Advertisement
Guest User

Untitled

a guest
Apr 17th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. void FFMpegFrameSink::do_cueForRecording(ARGBFrame* frame)
  2. {
  3. // If we're already in a recording mode, we wan to
  4. // remove the current file and start it again
  5. if (isRecording())
  6. {
  7. WX_SEVERE("Cannot cue for recording when recording is currently in process");
  8. return;
  9. }
  10.  
  11. // Cleanup any pointer's we've got open
  12. _cleanUp();
  13.  
  14. // Get the Properties to use
  15. _configuration[MFSA::WIDTH] = QString::number(frame->getWidth());
  16. _configuration[MFSA::HEIGHT] = QString::number(frame->getHeight());
  17. _configuration[MFSA::FRAME_RATE] = QString::number(frame->getFPS());
  18.  
  19. // Flag our Recording state and create the path for the Output file
  20. setRecordingState(Cueing);
  21. createPath("C:\\Temp");
  22.  
  23. // Get our Filename
  24. QDir baseDir("C:\\Temp");
  25. _fileName = baseDir.absFilePath(transformFileName(getOutputFileNameBase(), frame) + "." + STREAM_CONTAINER);
  26.  
  27. // Try to guess the Output Format
  28. _format = av_guess_format(NULL, _fileName.data(), NULL);
  29. if (!_format)
  30. {
  31. WX_WARNING("Failed to determine output format: using " + QString(STREAM_CONTAINER));
  32. _format = av_guess_format(STREAM_CONTAINER, NULL, NULL);
  33. }
  34. if (!_format)
  35. {
  36. WX_SEVERE("Could not find a suitable codec");
  37. return;
  38. }
  39.  
  40. // Allocate our Format (Output) Context
  41. _formatContext = avformat_alloc_context();
  42. if (!_formatContext)
  43. {
  44. WX_SEVERE("Memory error when allocating the format context");
  45. return;
  46. }
  47.  
  48. _fileName = _fileName.replace("/", "\\\\");
  49. WX_FINE(QString("Saving To File: %1").arg(_fileName).data());
  50.  
  51. _formatContext->oformat = _format;
  52. _snprintf(_formatContext->filename, sizeof(_formatContext->filename), "%s", _fileName);
  53.  
  54. // Add our Video and Audio Streams
  55. _format->video_codec = _videoCodec;
  56. _format->audio_codec = _audioCodec;
  57.  
  58. _videoStream = _addVideoStream(_format->video_codec);
  59. _audioStream = _addAudioStream(_format->audio_codec);
  60.  
  61. if (_videoStream == NULL || _audioStream == NULL)
  62. {
  63. WX_SEVERE("Cannot continue, one of the streams did not get allocated correctly");
  64. return;
  65. }
  66.  
  67. // Set our Output Parameters
  68. if (av_set_parameters(_formatContext, NULL) < 0)
  69. {
  70. WX_SEVERE("Invalid output format parameters");
  71. return;
  72. }
  73.  
  74. // Open the Audio and Video codecs for encoding
  75. if (!_openVideo(_videoStream))
  76. {
  77. WX_SEVERE("Failed to open stream, cannot continue with video output");
  78. _cleanUp();
  79. return;
  80. }
  81.  
  82. // Open the File
  83. int errorCode = url_fopen(&_formatContext->pb, _fileName.data(), URL_WRONLY);
  84. if (errorCode < 0)
  85. {
  86. WX_SEVERE("Failed to open the output file for writing. Error Code: " + QString::number(errorCode));
  87. _cleanUp();
  88. return;
  89. }
  90.  
  91. // Write the header
  92. av_write_header(_formatContext);
  93.  
  94. // Set up Some parameters we're going to need later
  95. _argbLength = frame->getHeight() * frame->getWidth();
  96.  
  97. // Flag our Recording States
  98. setRecordingState(Cued);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement