[FFmpeg-devel] [PATCH 4/5] fftools/ffmpeg: flush and recreate encoder instance if resolution changes

Anton Khirnov anton at khirnov.net
Wed Jun 10 11:31:12 EEST 2020


Quoting Linjie Fu (2020-06-09 10:48:46)
> Signed-off-by: Linjie Fu <linjie.fu at intel.com>
> ---
> Should be squashed with:
> https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=1434
> 
>  fftools/ffmpeg.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 5859781..8cdd532 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -130,6 +130,7 @@ static void do_video_stats(OutputStream *ost, int frame_size);
>  static BenchmarkTimeStamps get_benchmark_time_stamps(void);
>  static int64_t getmaxrss(void);
>  static int ifilter_has_all_input_formats(FilterGraph *fg);
> +static void flush_encoders(void);
>  
>  static int run_as_daemon  = 0;
>  static int nb_frames_dup = 0;
> @@ -1058,11 +1059,21 @@ static void do_video_out(OutputFile *of,
>  
>      if (next_picture && (enc->width != next_picture->width ||
>                           enc->height != next_picture->height)) {
> +        flush_encoders();
> +        avcodec_flush_buffers(enc);
>          if (!(enc->codec->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)) {
>              av_log(NULL, AV_LOG_ERROR, "Variable dimension encoding "
>                              "is not supported by %s.\n", enc->codec->name);
>              goto error;
>          }
> +
> +        enc->width  = next_picture->width;
> +        enc->height = next_picture->height;
> +
> +        if (enc->codec->close(enc) < 0)
> +            goto error;
> +        if (enc->codec->init(enc) < 0)
> +            goto error;

Absolutely not.
Those are private fields, they must not be accessed by libavcodec
callers.

What I meant was freeing the encoder and creating a completely new
encoder instance.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list