Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 13/19] lavc/mpegvideo_enc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
Date: Wed, 25 Jan 2023 17:55:31 +0100
Message-ID: <20230125165537.5371-13-anton@khirnov.net> (raw)
In-Reply-To: <20230125165537.5371-1-anton@khirnov.net>

For delay-capable encoders, i.e. mpeg12 and mpeg4video. Generic code in
encode.c already handles this for all other mpegvideo encoders.
---
 libavcodec/mpeg12enc.c     | 6 ++++--
 libavcodec/mpeg4videoenc.c | 3 ++-
 libavcodec/mpegvideo_enc.c | 9 +++++++++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 3ad1cd84a1..ff3d737e2a 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -1246,7 +1246,8 @@ const FFCodec ff_mpeg1video_encoder = {
     .p.supported_framerates = ff_mpeg12_frame_rate_tab + 1,
     .p.pix_fmts           = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                            AV_PIX_FMT_NONE },
-    .p.capabilities       = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
+    .p.capabilities       = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
+                            AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .caps_internal        = FF_CODEC_CAP_INIT_CLEANUP,
     .p.priv_class         = &mpeg1_class,
 };
@@ -1264,7 +1265,8 @@ const FFCodec ff_mpeg2video_encoder = {
     .p.pix_fmts           = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                            AV_PIX_FMT_YUV422P,
                                                            AV_PIX_FMT_NONE },
-    .p.capabilities       = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
+    .p.capabilities       = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
+                            AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .caps_internal        = FF_CODEC_CAP_INIT_CLEANUP,
     .p.priv_class         = &mpeg2_class,
 };
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index a2a14afbd0..f7d48490f9 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1403,7 +1403,8 @@ const FFCodec ff_mpeg4_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = ff_mpv_encode_end,
     .p.pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
-    .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
+    .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
+                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .p.priv_class   = &mpeg4enc_class,
 };
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 9b11c5c05a..e77d5bcd57 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1952,6 +1952,7 @@ vbv_retry:
         s->total_bits     += s->frame_bits;
 
         pkt->pts = s->current_picture.f->pts;
+        pkt->duration = s->current_picture.f->duration;
         if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) {
             if (!s->current_picture.f->coded_picture_number)
                 pkt->dts = pkt->pts - s->dts_delta;
@@ -1960,6 +1961,14 @@ vbv_retry:
             s->reordered_pts = pkt->pts;
         } else
             pkt->dts = pkt->pts;
+
+        // the no-delay case is handled in generic code
+        if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY) {
+            ret = ff_encode_reordered_opaque(avctx, pkt, s->current_picture.f);
+            if (ret < 0)
+                return ret;
+        }
+
         if (s->current_picture.f->key_frame)
             pkt->flags |= AV_PKT_FLAG_KEY;
         if (s->mb_info)
-- 
2.35.1

_______________________________________________
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-01-25 16:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 16:55 [FFmpeg-devel] [PATCH 01/19] lavc/avcodec: improve enc/dec API doxy Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 02/19] lavc/avcodec: improve AV_CODEC_FLAG_RECON_FRAME doxy Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 03/19] lavc: add a private cap for fake-delay encoders Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 04/19] lavc: add a codec flag for propagating opaque from frames to packets Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 05/19] lavc: support AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE in all no-delay encoders Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 06/19] lavc/encode: pass through frame durations to encoded packets Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 07/19] lavc/librav1e: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 08/19] lavc/nvenc: " Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 09/19] lavc/pngenc: " Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 10/19] lavc/pngenc: stop setting dts unnecessarily for APNG Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 11/19] lavc/libtheoraenc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 12/19] lavc/libtheoraenc: stop setting dts unnecessarily Anton Khirnov
2023-01-25 16:55 ` Anton Khirnov [this message]
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 14/19] lavc/vaapi_encode*: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 15/19] lavc/libwebpenc_animencoder: stop setting dts unnecessarily Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 16/19] lavc/libwebpenc_animencoder: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE Anton Khirnov
2023-01-25 20:51   ` Michael Niedermayer
2023-01-26  9:45     ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 17/19] lavc/libx264: pass through frame durations to encoded packets Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 18/19] lavc/libx265: " Anton Khirnov
2023-01-25 16:55 ` [FFmpeg-devel] [PATCH 19/19] lavc/libaomenc: " Anton Khirnov
2023-01-28 11:11 ` [FFmpeg-devel] [PATCH 01/19] lavc/avcodec: improve enc/dec API doxy Anton Khirnov
2023-01-28 11:37 ` Marvin Scholz
2023-01-28 13:23   ` Anton Khirnov
2023-01-28 14:47     ` Marvin Scholz
2023-01-28 13:45   ` [FFmpeg-devel] [PATCH] " Anton Khirnov

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=20230125165537.5371-13-anton@khirnov.net \
    --to=anton@khirnov.net \
    --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