Advertisement
Guest User

Untitled

a guest
Apr 8th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. // NOTE: this->context->streams[video_stream_index]->codec refers to the capturing codec context which I am using to capture from a network camera (RTSP H.264).
  2.  
  3. // Each iteration memory increases 400 kBytes. Is this code correct to create an mp4 file? filename is a string "video.mp4".
  4. for (int m = 0; m < 20000; ++m)
  5. {
  6.     const AVCodecContext* codec = this->context->streams[video_stream_index]->codec;
  7.     AVFormatContext* format_context;
  8.     AVOutputFormat* output_format = av_guess_format(NULL, filename.c_str(), NULL);
  9.     avformat_alloc_output_context2(&format_context, output_format, NULL, filename.c_str());
  10.     avio_open2(&format_context->pb, filename.c_str(), AVIO_FLAG_WRITE, NULL, NULL);
  11.     AVStream* stream = avformat_new_stream(format_context, codec->codec);
  12.     avcodec_copy_context(stream->codec, codec);
  13.     stream->sample_aspect_ratio = codec->sample_aspect_ratio;
  14.     avformat_write_header(format_context, NULL);
  15.                    
  16.         // Write packets
  17.         for (int k = syncData->kStart; k < syncData->kEnd; ++k)
  18.             av_write_frame(format_context, &circular[k].packet);
  19.  
  20.     av_write_trailer(format_context);
  21.     avio_close(format_context->pb);
  22.     format_context->pb = NULL;
  23.     avcodec_close(format_context->streams[video_stream_index]->codec);
  24.     avformat_free_context(format_context);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement