Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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).
- // Each iteration memory increases 400 kBytes. Is this code correct to create an mp4 file? filename is a string "video.mp4".
- for (int m = 0; m < 20000; ++m)
- {
- const AVCodecContext* codec = this->context->streams[video_stream_index]->codec;
- AVFormatContext* format_context;
- AVOutputFormat* output_format = av_guess_format(NULL, filename.c_str(), NULL);
- avformat_alloc_output_context2(&format_context, output_format, NULL, filename.c_str());
- avio_open2(&format_context->pb, filename.c_str(), AVIO_FLAG_WRITE, NULL, NULL);
- AVStream* stream = avformat_new_stream(format_context, codec->codec);
- avcodec_copy_context(stream->codec, codec);
- stream->sample_aspect_ratio = codec->sample_aspect_ratio;
- avformat_write_header(format_context, NULL);
- // Write packets
- for (int k = syncData->kStart; k < syncData->kEnd; ++k)
- av_write_frame(format_context, &circular[k].packet);
- av_write_trailer(format_context);
- avio_close(format_context->pb);
- format_context->pb = NULL;
- avcodec_close(format_context->streams[video_stream_index]->codec);
- avformat_free_context(format_context);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement