[FFmpeg-devel] [PATCH] nvenc: implement flush to help allow an encoder to be re-used

Josh Allmann joshua.allmann at gmail.com
Sat Dec 21 02:07:18 EET 2019


On Fri, 20 Dec 2019 at 15:34, Philip Langdale <philipl at overt.org> wrote:
>
> It can be useful to re-use an encoder instance when doing segmented
> encodings, and this requires flushing the encoder at the start of
> each segment.
> ---
>  libavcodec/nvenc.c      | 5 +++++
>  libavcodec/nvenc.h      | 2 ++
>  libavcodec/nvenc_h264.c | 1 +
>  libavcodec/nvenc_hevc.c | 1 +
>  4 files changed, 9 insertions(+)
>
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index 310e30805d..9a96bf2bba 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -2262,3 +2262,8 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>
>      return 0;
>  }
> +
> +av_cold void ff_nvenc_encode_flush(AVCodecContext *avctx)
> +{
> +    ff_nvenc_send_frame(avctx, NULL);

One concern I had was about the long-term stability of this behavior.
Right now, it works, but perhaps only coincidentally? Being flushable
and resumable like this isn't explicitly part of the "contract" for
nvenc, as far as I can see. Could future changes inadvertently
introduce state that isn't reset in between flushes, breaking the
resumable behavior? If so, is there a way to safeguard against that?

Josh


More information about the ffmpeg-devel mailing list