Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void FFMpegFrameSink::do_cueForRecording(ARGBFrame* frame)
- {
- // If we're already in a recording mode, we wan to
- // remove the current file and start it again
- if (isRecording())
- {
- WX_SEVERE("Cannot cue for recording when recording is currently in process");
- return;
- }
- // Cleanup any pointer's we've got open
- _cleanUp();
- // Get the Properties to use
- _configuration[MFSA::WIDTH] = QString::number(frame->getWidth());
- _configuration[MFSA::HEIGHT] = QString::number(frame->getHeight());
- _configuration[MFSA::FRAME_RATE] = QString::number(frame->getFPS());
- // Flag our Recording state and create the path for the Output file
- setRecordingState(Cueing);
- createPath("C:\\Temp");
- // Get our Filename
- QDir baseDir("C:\\Temp");
- _fileName = baseDir.absFilePath(transformFileName(getOutputFileNameBase(), frame) + "." + STREAM_CONTAINER);
- // Try to guess the Output Format
- _format = av_guess_format(NULL, _fileName.data(), NULL);
- if (!_format)
- {
- WX_WARNING("Failed to determine output format: using " + QString(STREAM_CONTAINER));
- _format = av_guess_format(STREAM_CONTAINER, NULL, NULL);
- }
- if (!_format)
- {
- WX_SEVERE("Could not find a suitable codec");
- return;
- }
- // Allocate our Format (Output) Context
- _formatContext = avformat_alloc_context();
- if (!_formatContext)
- {
- WX_SEVERE("Memory error when allocating the format context");
- return;
- }
- _fileName = _fileName.replace("/", "\\\\");
- WX_FINE(QString("Saving To File: %1").arg(_fileName).data());
- _formatContext->oformat = _format;
- _snprintf(_formatContext->filename, sizeof(_formatContext->filename), "%s", _fileName);
- // Add our Video and Audio Streams
- _format->video_codec = _videoCodec;
- _format->audio_codec = _audioCodec;
- _videoStream = _addVideoStream(_format->video_codec);
- _audioStream = _addAudioStream(_format->audio_codec);
- if (_videoStream == NULL || _audioStream == NULL)
- {
- WX_SEVERE("Cannot continue, one of the streams did not get allocated correctly");
- return;
- }
- // Set our Output Parameters
- if (av_set_parameters(_formatContext, NULL) < 0)
- {
- WX_SEVERE("Invalid output format parameters");
- return;
- }
- // Open the Audio and Video codecs for encoding
- if (!_openVideo(_videoStream))
- {
- WX_SEVERE("Failed to open stream, cannot continue with video output");
- _cleanUp();
- return;
- }
- // Open the File
- int errorCode = url_fopen(&_formatContext->pb, _fileName.data(), URL_WRONLY);
- if (errorCode < 0)
- {
- WX_SEVERE("Failed to open the output file for writing. Error Code: " + QString::number(errorCode));
- _cleanUp();
- return;
- }
- // Write the header
- av_write_header(_formatContext);
- // Set up Some parameters we're going to need later
- _argbLength = frame->getHeight() * frame->getWidth();
- // Flag our Recording States
- setRecordingState(Cued);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement