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] [RFC PATCH 1/7] lavc/mpegvideo_enc: support AV_CODEC_CAP_ENCODER_RECON_FRAME
Date: Fri, 24 Mar 2023 10:14:45 +0100
Message-ID: <20230324091451.20895-1-anton@khirnov.net> (raw)

---
Last time I tested this, the frames did not actually match when using
B-frames. As I'm not particularly interested in these encoders, I don't
want to spend time debugging the issue, so I don't intend to push this
patch with the rest. Volunteers welcome.
---
 libavcodec/flvenc.c        | 1 +
 libavcodec/h261enc.c       | 1 +
 libavcodec/ituh263enc.c    | 7 +++++--
 libavcodec/mjpegenc.c      | 6 ++++--
 libavcodec/mpeg12enc.c     | 6 ++++--
 libavcodec/mpeg4videoenc.c | 3 ++-
 libavcodec/mpegvideo_enc.c | 8 ++++++++
 libavcodec/msmpeg4enc.c    | 9 ++++++---
 libavcodec/rv10enc.c       | 1 +
 libavcodec/rv20enc.c       | 1 +
 libavcodec/speedhqenc.c    | 1 +
 libavcodec/wmv2enc.c       | 1 +
 12 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 6a96cb0f2f..53878722af 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -103,6 +103,7 @@ const FFCodec ff_flv_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = ff_mpv_encode_end,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                      AV_PIX_FMT_NONE},
     .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 438ebb63d9..04dc34d08c 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -411,6 +411,7 @@ const FFCodec ff_h261_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = ff_mpv_encode_end,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                      AV_PIX_FMT_NONE },
     .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index c30ecad438..78c041b2cf 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -903,7 +903,8 @@ const FFCodec ff_h263_encoder = {
     .p.id           = AV_CODEC_ID_H263,
     .p.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE},
     .p.priv_class   = &h263_class,
-    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .priv_data_size = sizeof(MpegEncContext),
     .init           = ff_mpv_encode_init,
@@ -934,7 +935,9 @@ const FFCodec ff_h263p_encoder = {
     .p.id           = AV_CODEC_ID_H263P,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
     .p.priv_class   = &h263p_class,
-    .p.capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+    .p.capabilities = AV_CODEC_CAP_SLICE_THREADS |
+                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .priv_data_size = sizeof(MpegEncContext),
     .init           = ff_mpv_encode_init,
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 508772987f..47b3ca3141 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -652,7 +652,8 @@ const FFCodec ff_mjpeg_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = mjpeg_encode_close,
     .p.capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS |
-                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_ICC_PROFILES,
     .p.pix_fmts     = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
@@ -686,6 +687,7 @@ const FFCodec ff_amv_encoder = {
         AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_NONE
     },
     .p.priv_class   = &amv_class,
-    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
 };
 #endif
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index a932b59678..b120174efb 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -1246,7 +1246,8 @@ const FFCodec ff_mpeg1video_encoder = {
     .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 |
-                            AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+                            AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                            AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal        = FF_CODEC_CAP_INIT_CLEANUP,
     .p.priv_class         = &mpeg1_class,
 };
@@ -1265,7 +1266,8 @@ const FFCodec ff_mpeg2video_encoder = {
                                                            AV_PIX_FMT_YUV422P,
                                                            AV_PIX_FMT_NONE },
     .p.capabilities       = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
-                            AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+                            AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE           |
+                            AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal        = FF_CODEC_CAP_INIT_CLEANUP,
     .p.priv_class         = &mpeg2_class,
 };
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index c3e9ebea45..93b92867a8 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1404,7 +1404,8 @@ const FFCodec ff_mpeg4_encoder = {
     .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 |
-                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE           |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .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 7d3c8875f2..ca3495fc8f 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1865,6 +1865,14 @@ vbv_retry:
                                        (avctx->flags&AV_CODEC_FLAG_PSNR) ? MPEGVIDEO_MAX_PLANES : 0,
                                        s->pict_type);
 
+        if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {
+            AVCodecInternal *avci = avctx->internal;
+            av_frame_unref(avci->recon_frame);
+            ret = av_frame_ref(avci->recon_frame, s->current_picture.f);
+            if (ret < 0)
+                return ret;
+        }
+
         if (avctx->flags & AV_CODEC_FLAG_PASS1)
             assert(put_bits_count(&s->pb) == s->header_bits + s->mv_bits +
                                              s->misc_bits + s->i_tex_bits +
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 54121438a0..85b76c889f 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -684,7 +684,8 @@ const FFCodec ff_msmpeg4v2_encoder = {
     .p.id           = AV_CODEC_ID_MSMPEG4V2,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
     .p.priv_class   = &ff_mpv_enc_class,
-    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .priv_data_size = sizeof(MSMPEG4EncContext),
     .init           = ff_mpv_encode_init,
@@ -699,7 +700,8 @@ const FFCodec ff_msmpeg4v3_encoder = {
     .p.id           = AV_CODEC_ID_MSMPEG4V3,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
     .p.priv_class   = &ff_mpv_enc_class,
-    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .priv_data_size = sizeof(MSMPEG4EncContext),
     .init           = ff_mpv_encode_init,
@@ -714,7 +716,8 @@ const FFCodec ff_wmv1_encoder = {
     .p.id           = AV_CODEC_ID_WMV1,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
     .p.priv_class   = &ff_mpv_enc_class,
-    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .priv_data_size = sizeof(MSMPEG4EncContext),
     .init           = ff_mpv_encode_init,
diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c
index 8a405b8686..90ba4c0a0b 100644
--- a/libavcodec/rv10enc.c
+++ b/libavcodec/rv10enc.c
@@ -77,5 +77,6 @@ const FFCodec ff_rv10_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = ff_mpv_encode_end,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
 };
diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c
index dc26877d5e..aeea557e89 100644
--- a/libavcodec/rv20enc.c
+++ b/libavcodec/rv20enc.c
@@ -74,5 +74,6 @@ const FFCodec ff_rv20_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = ff_mpv_encode_end,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
 };
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 5b4ff4c139..162bb77508 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -294,6 +294,7 @@ const FFCodec ff_speedhq_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = ff_mpv_encode_end,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.pix_fmts     = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
         AV_PIX_FMT_NONE
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index 8eb56444a3..1a1df73ec2 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -248,6 +248,7 @@ const FFCodec ff_wmv2_encoder = {
     FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
     .close          = ff_mpv_encode_end,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .p.capabilities = AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                      AV_PIX_FMT_NONE },
 };
-- 
2.39.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".

             reply	other threads:[~2023-03-24  9:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24  9:14 Anton Khirnov [this message]
2023-03-24  9:14 ` [FFmpeg-devel] [PATCH 2/7] tools/decode_simple: always call process_frame(NULL) at the end Anton Khirnov
2023-03-24  9:14 ` [FFmpeg-devel] [PATCH 3/7] tools/decode_simple: initialize decoder parameters with container info Anton Khirnov
2023-03-24  9:14 ` [FFmpeg-devel] [PATCH 4/7] tools: add an AV_CODEC_CAP_ENCODER_RECON_FRAME test tool Anton Khirnov
2023-03-24  9:14 ` [FFmpeg-devel] [PATCH 5/7] lavc/avcodec: fix documentation typo Anton Khirnov
2023-03-24  9:14 ` [FFmpeg-devel] [PATCH 6/7] lavc: expand doxy for AV_CODEC_FLAG_RECON_FRAME Anton Khirnov
2023-03-24  9:14 ` [FFmpeg-devel] [PATCH 7/7] lavc: turn mentions of AV_CODEC_FLAG_RECON_FRAME in doxy into links 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=20230324091451.20895-1-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