[FFmpeg-cvslog] lavc/mpegvideo_enc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
Anton Khirnov
git at videolan.org
Sun Jan 29 10:40:25 EET 2023
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Jan 4 17:27:07 2023 +0100| [c44a3dba9eaebc200c2cf9e4cb30c20c2ebd4562] | committer: Anton Khirnov
lavc/mpegvideo_enc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
For delay-capable encoders, i.e. mpeg12 and mpeg4video. Generic code in
encode.c already handles this for all other mpegvideo encoders.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c44a3dba9eaebc200c2cf9e4cb30c20c2ebd4562
---
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 a6663a158b..b5951e4307 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 27df9ba098..c3e9ebea45 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 bb101612e5..0e6a4c4ec5 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)
More information about the ffmpeg-cvslog
mailing list