Ejemplo n.º 1
0
void ofxVideoRecorder::close()
{
    if(!bIsInitialized) return;

    //set pipes to non_blocking so we dont get stuck at the final writes
    setNonblocking(audioPipeFd);
    setNonblocking(videoPipeFd);
    
    while(frames.size() > 0 && audioFrames.size() > 0) {
        // if there are frames in the queue or the thread is writing, signal them until the work is done.
        videoThread.signal();
        audioThread.signal();
    }
    
    //at this point all data that ffmpeg wants should have been consumed
    // one of the threads may still be trying to write a frame,
    // but once close() gets called they will exit the non_blocking write loop
    // and hopefully close successfully

    bIsInitialized = false;

    if (bRecordVideo) {
        videoThread.close();
    }
    if (bRecordAudio) {
        audioThread.close();
    }

    retirePipeNumber(pipeNumber);

    ffmpegThread.waitForThread();
    // TODO: kill ffmpeg process if its taking too long to close for whatever reason.

}
//--------------------------------------------------------------
void ofxVideoRecorder::outputFileComplete()
{
    //at this point all data that ffmpeg wants should have been consumed
    // one of the threads may still be trying to write a frame,
    // but once close() gets called they will exit the non_blocking write loop
    // and hopefully close successfully
    
    bIsInitialized = false;
    
    if (bRecordVideo) {
        videoThread.close();
    }
    if (bRecordAudio) {
        audioThread.close();
    }
    
    retirePipeNumber(pipeNumber);
    
    ffmpegThread.waitForThread();
    // TODO: kill ffmpeg process if its taking too long to close for whatever reason.
    
    // Notify the listeners.
    ofxVideoRecorderOutputFileCompleteEventArgs args;
    args.fileName = fileName;
    ofNotifyEvent(outputFileCompleteEvent, args);
}
Ejemplo n.º 3
0
void ofxVideoRecorder::close()
{
	if (!bIsInitialized) return;

	bIsRecording = false;

#if defined( TARGET_OSX ) || defined( TARGET_LINUX )

	if (bRecordVideo && bRecordAudio) {
		//set pipes to non_blocking so we dont get stuck at the final writes
		audioThread.setPipeNonBlocking();
		videoThread.setPipeNonBlocking();

		while (frames.size() > 0 && audioFrames.size() > 0) {
			// if there are frames in the queue or the thread is writing, signal them until the work is done.
			videoThread.signal();
			audioThread.signal();
		}
	}
	else if (bRecordVideo) {
		//set pipes to non_blocking so we dont get stuck at the final writes
		videoThread.setPipeNonBlocking();

		while (frames.size() > 0) {
			// if there are frames in the queue or the thread is writing, signal them until the work is done.
			videoThread.signal();
		}
	}
	else if (bRecordAudio) {
		//set pipes to non_blocking so we dont get stuck at the final writes
		audioThread.setPipeNonBlocking();

		while (audioFrames.size() > 0) {
			// if there are frames in the queue or the thread is writing, signal them until the work is done.
			audioThread.signal();
		}
	}

	//at this point all data that ffmpeg wants should have been consumed
	// one of the threads may still be trying to write a frame,
	// but once close() gets called they will exit the non_blocking write loop
	// and hopefully close successfully

	bIsInitialized = false;

	if (bRecordVideo) {
		videoThread.close();
	}
	if (bRecordAudio) {
		audioThread.close();
	}

	retirePipeNumber(pipeNumber);

	ffmpegThread.waitForThread();
#endif
#ifdef TARGET_WIN32 
	if (bRecordVideo) {
		videoThread.close();
	}
	if (bRecordAudio) {
		audioThread.close();
	}

	//at this point all data that ffmpeg wants should have been consumed
	// one of the threads may still be trying to write a frame,
	// but once close() gets called they will exit the non_blocking write loop
	// and hopefully close successfully

	if (bRecordAudio && bRecordVideo) {
		ffmpegAudioThread.waitForThread();
		ffmpegVideoThread.waitForThread();

		//need to do one last script here to join the audio and video recordings

		stringstream finalCmd;

		/*finalCmd << ffmpegLocation << " -y " << " -i " << filePath << "_vtemp" << movFileExt << " -i " << filePath << "_atemp" << movFileExt << " \\ ";
		finalCmd << "-filter_complex \"[0:0] [1:0] concat=n=2:v=1:a=1 [v] [a]\" \\";
		finalCmd << "-map \"[v]\" -map \"[a]\" ";
		finalCmd << " -vcodec " << videoCodec << " -b:v " << videoBitrate << " -b:a " << audioBitrate << " ";
		finalCmd << filePath << movFileExt;*/

		finalCmd << ffmpegLocation << " -y " << " -i " << filePath << "_vtemp" << movFileExt << " -i " << filePath << "_atemp" << audioFileExt << " ";
		finalCmd << "-c:v copy -c:a copy -strict experimental ";
		finalCmd << filePath << movFileExt;

		ofLogNotice("FFMpeg Merge") << "\n==============================================\n Merge Command \n==============================================\n";
		ofLogNotice("FFMpeg Merge") << finalCmd.str();
		//ffmpegThread.setup(finalCmd.str());
		system(finalCmd.str().c_str());

		//delete the unmerged files
		stringstream removeCmd;
		ofStringReplace(filePath, "/", "\\");
		removeCmd << "DEL " << filePath << "_vtemp" << movFileExt << " " << filePath << "_atemp" << audioFileExt;
		system(removeCmd.str().c_str());

	}

	ffmpegThread.waitForThread();

#endif
	// TODO: kill ffmpeg process if its taking too long to close for whatever reason.
	ofLogNotice("ofxVideoRecorder") << "\n==============================================\n Closed ffmpeg \n==============================================\n";
	bIsInitialized = false;
	}