ffmpeg: Copy extradata if it has been initialized later from the encoder
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 6 Sep 2014 02:42:48 +0000 (04:42 +0200)
committerCarl Eugen Hoyos <cehoyos@ag.or.at>
Sat, 1 Nov 2014 14:53:19 +0000 (15:53 +0100)
Fixes Ticket3909

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit ab84effdeda931a74d8503891488ed538619a5d3)

ffmpeg.c

index 3015ca8..af171d2 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -578,6 +578,14 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
     AVCodecContext          *avctx = ost->st->codec;
     int ret;
 
+    if (!ost->st->codec->extradata_size && ost->enc_ctx->extradata_size) {
+        ost->st->codec->extradata = av_mallocz(ost->enc_ctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+        if (ost->st->codec->extradata) {
+            memcpy(ost->st->codec->extradata, ost->enc_ctx->extradata, ost->enc_ctx->extradata_size);
+            ost->st->codec->extradata_size = ost->enc_ctx->extradata_size;
+        }
+    }
+
     if ((avctx->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) ||
         (avctx->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))
         pkt->pts = pkt->dts = AV_NOPTS_VALUE;