[FFmpeg-devel] [PATCH] ffmpeg: Update muxer extradata after flushing encoders
Paul B Mahol
onemda at gmail.com
Wed Aug 17 13:13:43 EEST 2016
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.
More information about the ffmpeg-devel
mailing list