Video: Fix setting global extradata in FFmpeg

This commit is contained in:
Jeffrey Pfau 2014-11-04 00:15:54 -08:00
parent 67e31c9666
commit d3bb022bf1
1 changed files with 6 additions and 5 deletions

View File

@ -184,6 +184,9 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
encoder->audio->sample_fmt = encoder->sampleFormat; encoder->audio->sample_fmt = encoder->sampleFormat;
AVDictionary* opts = 0; AVDictionary* opts = 0;
av_dict_set(&opts, "strict", "-2", 0); av_dict_set(&opts, "strict", "-2", 0);
if (encoder->context->oformat->flags & AVFMT_GLOBALHEADER) {
encoder->audio->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
avcodec_open2(encoder->audio, acodec, &opts); avcodec_open2(encoder->audio, acodec, &opts);
av_dict_free(&opts); av_dict_free(&opts);
encoder->audioFrame = av_frame_alloc(); encoder->audioFrame = av_frame_alloc();
@ -221,6 +224,9 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
encoder->video->pix_fmt = encoder->pixFormat; encoder->video->pix_fmt = encoder->pixFormat;
encoder->video->gop_size = 15; encoder->video->gop_size = 15;
encoder->video->max_b_frames = 0; encoder->video->max_b_frames = 0;
if (encoder->context->oformat->flags & AVFMT_GLOBALHEADER) {
encoder->video->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
avcodec_open2(encoder->video, vcodec, 0); avcodec_open2(encoder->video, vcodec, 0);
encoder->videoFrame = av_frame_alloc(); encoder->videoFrame = av_frame_alloc();
encoder->videoFrame->format = encoder->video->pix_fmt; encoder->videoFrame->format = encoder->video->pix_fmt;
@ -232,11 +238,6 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
0, 0, 0, 0); 0, 0, 0, 0);
av_image_alloc(encoder->videoFrame->data, encoder->videoFrame->linesize, encoder->video->width, encoder->video->height, encoder->video->pix_fmt, 32); av_image_alloc(encoder->videoFrame->data, encoder->videoFrame->linesize, encoder->video->width, encoder->video->height, encoder->video->pix_fmt, 32);
if (encoder->context->oformat->flags & AVFMT_GLOBALHEADER) {
encoder->audio->flags |= CODEC_FLAG_GLOBAL_HEADER;
encoder->video->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
avio_open(&encoder->context->pb, outfile, AVIO_FLAG_WRITE); avio_open(&encoder->context->pb, outfile, AVIO_FLAG_WRITE);
avformat_write_header(encoder->context, 0); avformat_write_header(encoder->context, 0);