Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: add a flush callback
Date: Mon, 27 Mar 2023 22:33:37 +0200
Message-ID: <GV1P250MB07379142B047D5608661213B8F8B9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20230327200956.2138-1-jamrial@gmail.com>

James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/libx264.c | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 92828fabc3..72c3b6cedc 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -178,8 +178,8 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt,
>          memcpy(p, x4->sei, x4->sei_size);
>          p += x4->sei_size;
>          size -= x4->sei_size;
> -        x4->sei_size = 0;
> -        av_freep(&x4->sei);
> +        /* Keep the value around in case of flush */
> +        x4->sei_size = -x4->sei_size;
>      }
>  
>      /* x264 guarantees the payloads of the NALs
> @@ -648,6 +648,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      return 0;
>  }
>  
> +static void X264_flush(AVCodecContext *avctx)
> +{
> +    X264Context *x4 = avctx->priv_data;
> +    x264_nal_t *nal;
> +    int nnal, ret;
> +    x264_picture_t pic_out = {0};
> +
> +    do {
> +        ret = x264_encoder_encode(x4->enc, &nal, &nnal, NULL, &pic_out);
> +    } while (ret > 0 && x264_encoder_delayed_frames(x4->enc));
> +
> +    for (int i = 0; i < x4->nb_reordered_opaque; i++)
> +        opaque_uninit(&x4->reordered_opaque[i]);
> +
> +    if (x4->sei_size < 0)
> +        x4->sei_size = -x4->sei_size;
> +}
> +
>  static av_cold int X264_close(AVCodecContext *avctx)
>  {
>      X264Context *x4 = avctx->priv_data;
> @@ -1335,12 +1353,14 @@ FFCodec ff_libx264_encoder = {
>      .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>                          AV_CODEC_CAP_OTHER_THREADS |
>                          AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
> +                        AV_CODEC_CAP_ENCODER_FLUSH |
>                          AV_CODEC_CAP_ENCODER_RECON_FRAME,
>      .p.priv_class     = &x264_class,
>      .p.wrapper_name   = "libx264",
>      .priv_data_size   = sizeof(X264Context),
>      .init             = X264_init,
>      FF_CODEC_ENCODE_CB(X264_frame),
> +    .flush            = X264_flush,
>      .close            = X264_close,
>      .defaults         = x264_defaults,
>  #if X264_BUILD < 153

Wasn't AV_CODEC_CAP_ENCODER_FLUSH supposed to be only implemented for
hardware encoders where closing and reopening an encoder is costly?

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2023-03-27 20:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-27 20:09 James Almer
2023-03-27 20:09 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libfdk-aaceenc: " James Almer
2023-03-27 20:33 ` Andreas Rheinhardt [this message]
2023-03-27 20:40   ` [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: " James Almer
2023-03-28 21:12 ` Michael Niedermayer
2023-03-28 21:25   ` [FFmpeg-devel] [PATCH v2 " James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GV1P250MB07379142B047D5608661213B8F8B9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git