diff mbox series

[FFmpeg-devel,23/30] lavc/ffv1enc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE

Message ID 20221127170351.11477-23-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/30] lavc/libx264: factor out setting up the input frame | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Nov. 27, 2022, 5:03 p.m. UTC
---
 libavcodec/ffv1enc.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Andreas Rheinhardt Jan. 4, 2023, 5:27 p.m. UTC | #1
Anton Khirnov:
> ---
>  libavcodec/ffv1enc.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
> index 0237ac48eb..553abb558f 100644
> --- a/libavcodec/ffv1enc.c
> +++ b/libavcodec/ffv1enc.c
> @@ -1233,7 +1233,20 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>      pkt->size   = buf_p - pkt->data;
>      pkt->pts    =
>      pkt->dts    = pict->pts;
> +    pkt->duration = pict->duration;
>      pkt->flags |= AV_PKT_FLAG_KEY * f->key_frame;
> +
> +    if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
> +        pkt->opaque = pict->opaque;
> +        if (pict->opaque_ref) {
> +            pkt->opaque_ref = av_buffer_ref(pict->opaque_ref);
> +            if (!pkt->opaque_ref)
> +                return AVERROR(ENOMEM);
> +        }
> +    }
> +
> +    avctx->reordered_opaque = pict->reordered_opaque;
> +
>      *got_packet = 1;
>  
>      return 0;
> @@ -1272,7 +1285,8 @@ const FFCodec ff_ffv1_encoder = {
>      .p.type         = AVMEDIA_TYPE_VIDEO,
>      .p.id           = AV_CODEC_ID_FFV1,
>      .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
> -                      AV_CODEC_CAP_SLICE_THREADS,
> +                      AV_CODEC_CAP_SLICE_THREADS            |
> +                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
>      .priv_data_size = sizeof(FFV1Context),
>      .init           = encode_init,
>      FF_CODEC_ENCODE_CB(encode_frame),

FFV1's does not have frame reordering (no AV_CODEC_PROP_REORDER for the
codec descriptor); the encoder just has the AV_CODEC_CAP_DELAY set to
write stats in case this was the first pass of a two-pass encoding (this
could actually be moved . Otherwise the encoder is a simple
one-in-one-out encoder with no delay at all. Something similar is true
for the FLAC encoder (it has the DELAY cap so that it can output a
side-data only packet with updated extradata when flushing) and adxenc.
Maybe we should have an internal capability to allow to set these
properties generically for these codecs, too?

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 0237ac48eb..553abb558f 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1233,7 +1233,20 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     pkt->size   = buf_p - pkt->data;
     pkt->pts    =
     pkt->dts    = pict->pts;
+    pkt->duration = pict->duration;
     pkt->flags |= AV_PKT_FLAG_KEY * f->key_frame;
+
+    if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
+        pkt->opaque = pict->opaque;
+        if (pict->opaque_ref) {
+            pkt->opaque_ref = av_buffer_ref(pict->opaque_ref);
+            if (!pkt->opaque_ref)
+                return AVERROR(ENOMEM);
+        }
+    }
+
+    avctx->reordered_opaque = pict->reordered_opaque;
+
     *got_packet = 1;
 
     return 0;
@@ -1272,7 +1285,8 @@  const FFCodec ff_ffv1_encoder = {
     .p.type         = AVMEDIA_TYPE_VIDEO,
     .p.id           = AV_CODEC_ID_FFV1,
     .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
-                      AV_CODEC_CAP_SLICE_THREADS,
+                      AV_CODEC_CAP_SLICE_THREADS            |
+                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .priv_data_size = sizeof(FFV1Context),
     .init           = encode_init,
     FF_CODEC_ENCODE_CB(encode_frame),