[FFmpeg-devel] [PATCH 3/4] avcodec/avcodec: Don't reset decoder-fields for encoders when flushing

Anton Khirnov anton at khirnov.net
Wed Apr 13 18:48:24 EEST 2022


Quoting Andreas Rheinhardt (2022-04-13 16:49:51)
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
> Needs to be applied before
> https://ffmpeg.org/pipermail/ffmpeg-devel/2022-March/294507.html
> or flushing an encoder will segfault.
> Btw: All this stuff is unused by subtitle decoders,
> so one could condition the else on that and avoid the allocations.
> 
>  libavcodec/avcodec.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index ded6b5b307..0d971a61d4 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -422,6 +422,17 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>          }
>          if (avci->in_frame)
>              av_frame_unref(avci->in_frame);
> +    } else {
> +        av_packet_unref(avci->last_pkt_props);
> +        while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0)
> +            av_packet_unref(avci->last_pkt_props);
> +
> +        av_packet_unref(avci->in_pkt);
> +
> +        avctx->pts_correction_last_pts =
> +        avctx->pts_correction_last_dts = INT64_MIN;
> +
> +        av_bsf_flush(avci->bsf);
>      }
>  
>      avci->draining      = 0;
> @@ -430,22 +441,10 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>      av_frame_unref(avci->buffer_frame);
>      av_packet_unref(avci->buffer_pkt);
>  
> -    av_packet_unref(avci->last_pkt_props);
> -    while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0)
> -        av_packet_unref(avci->last_pkt_props);
> -
> -    av_packet_unref(avci->in_pkt);
> -
>      if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
>          ff_thread_flush(avctx);
>      else if (ffcodec(avctx->codec)->flush)
>          ffcodec(avctx->codec)->flush(avctx);
> -
> -    avctx->pts_correction_last_pts =
> -    avctx->pts_correction_last_dts = INT64_MIN;
> -
> -    if (avci->bsf)

did you drop this check on purpose?

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list