diff mbox

[FFmpeg-devel] ffmpeg: copy the extradata from encoder to muxer

Message ID e930920d-ebe7-12cb-80f0-1538c2e89966@googlemail.com
State Superseded
Headers show

Commit Message

Andreas Cadhalpun Oct. 27, 2016, 7:19 p.m. UTC
This fixes creating apng files.

This partly reverts commit 5ef19590802f000299e418143fc2301e3f43affe.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
---
 ffmpeg.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

James Almer Oct. 27, 2016, 7:37 p.m. UTC | #1
On 10/27/2016 4:19 PM, Andreas Cadhalpun wrote:
> This fixes creating apng files.
> 
> This partly reverts commit 5ef19590802f000299e418143fc2301e3f43affe.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> ---
>  ffmpeg.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/ffmpeg.c b/ffmpeg.c
> index 3b91710..9971148 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -646,6 +646,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
>  {
>      AVFormatContext *s = of->ctx;
>      AVStream *st = ost->st;
> +    AVCodecContext *avctx = ost->encoding_needed ? ost->enc_ctx : ost->st->codec;

No, AVStream->codec usage was removed. It can't be re added.

>      int ret;
>  
>      if (!of->header_written) {
> @@ -709,6 +710,16 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
>          }
>      }
>  
> +    if (!st->codecpar->extradata_size && avctx->extradata_size) {
> +        st->codecpar->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
> +        if (!st->codecpar->extradata) {
> +            av_log(NULL, AV_LOG_ERROR, "Could not allocate extradata buffer to copy parser data.\n");
> +            exit_program(1);
> +        }
> +        st->codecpar->extradata_size = avctx->extradata_size;
> +        memcpy(st->codecpar->extradata, avctx->extradata, avctx->extradata_size);
> +    }

If apng encoder needs to add new extradata in a packet, it should do it
with av_packet_new_side_data() instead.

> +
>      if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
>          if (pkt->dts != AV_NOPTS_VALUE &&
>              pkt->pts != AV_NOPTS_VALUE &&
>
diff mbox

Patch

diff --git a/ffmpeg.c b/ffmpeg.c
index 3b91710..9971148 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -646,6 +646,7 @@  static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
 {
     AVFormatContext *s = of->ctx;
     AVStream *st = ost->st;
+    AVCodecContext *avctx = ost->encoding_needed ? ost->enc_ctx : ost->st->codec;
     int ret;
 
     if (!of->header_written) {
@@ -709,6 +710,16 @@  static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
         }
     }
 
+    if (!st->codecpar->extradata_size && avctx->extradata_size) {
+        st->codecpar->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
+        if (!st->codecpar->extradata) {
+            av_log(NULL, AV_LOG_ERROR, "Could not allocate extradata buffer to copy parser data.\n");
+            exit_program(1);
+        }
+        st->codecpar->extradata_size = avctx->extradata_size;
+        memcpy(st->codecpar->extradata, avctx->extradata, avctx->extradata_size);
+    }
+
     if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
         if (pkt->dts != AV_NOPTS_VALUE &&
             pkt->pts != AV_NOPTS_VALUE &&