[FFmpeg-devel] [PATCH] ffmpeg: Update muxer extradata after flushing encoders

Umair Khan omerjerk at gmail.com
Wed Aug 17 22:01:19 EEST 2016


Hi,

On Wed, Aug 17, 2016 at 10:44 PM, Umair Khan <omerjerk at gmail.com> wrote:
> Hi,
>
> On Wed, Aug 17, 2016 at 3:43 PM, Paul B Mahol <onemda at gmail.com> wrote:
>> On 8/17/16, Michael Niedermayer <michael at niedermayer.cc> wrote:
>>> This is needed for encoders which store a final sample count or checksum in
>>> extradata
>>>
>>> alternatively every encoder as well as muxer can implement
>>> AV_PKT_DATA_NEW_EXTRADATA support
>>> to update the extradata at the end.
>>>
>>> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
>>> ---
>>>  ffmpeg.c | 17 +++++++++++++++++
>>>  1 file changed, 17 insertions(+)
>>>
>>> diff --git a/ffmpeg.c b/ffmpeg.c
>>> index bae515d..9d972d0 100644
>>> --- a/ffmpeg.c
>>> +++ b/ffmpeg.c
>>> @@ -1772,6 +1772,23 @@ static void flush_encoders(void)
>>>              if (stop_encoding)
>>>                  break;
>>>          }
>>> +        if (ost->enc_ctx->extradata_size) {
>>> +            void *ptr  = av_mallocz(ost->enc_ctx->extradata_size +
>>> AV_INPUT_BUFFER_PADDING_SIZE);
>>> +            void *ptr2 = av_mallocz(ost->enc_ctx->extradata_size +
>>> AV_INPUT_BUFFER_PADDING_SIZE);
>>> +            if (ptr && ptr2) {
>>> +                av_free(ost->st->codec->extradata);
>>> +                av_free(ost->st->codecpar->extradata);
>>> +                ost->st->codec->extradata    = ptr;
>>> +                ost->st->codecpar->extradata = ptr2;
>>> +                memcpy(ost->st->codec->extradata   ,
>>> ost->enc_ctx->extradata, ost->enc_ctx->extradata_size);
>>> +                memcpy(ost->st->codecpar->extradata,
>>> ost->enc_ctx->extradata, ost->enc_ctx->extradata_size);
>>> +                ost->st->codec   ->extradata_size =
>>> ost->enc_ctx->extradata_size;
>>> +                ost->st->codecpar->extradata_size =
>>> ost->enc_ctx->extradata_size;
>>> +            } else {
>>> +                av_free(ptr);
>>> +                av_free(ptr2);
>>> +            }
>>> +        }
>>>      }
>>>  }
>>
>> I'm against this patch. Use API already available, don't add hacks on
>> top of hacks.
>
> I had a look at the mp4 muxer code. And it itself doesn't implement
> the AV_PKT_DATA_NEW_EXTRADATA api.
> I'll try to implement that in the mp4 muxer now.

I've sent the patch to the mailing list. Please review it.

Meanwhile, I'll finalise my alsenc patch. :)

- Umair


More information about the ffmpeg-devel mailing list