Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 6/8] avcodec/dovi_rpuenc: disable metadata compression by default
Date: Tue, 18 Jun 2024 21:35:36 +0200
Message-ID: <20240618194221.26073-7-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240618194221.26073-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

Keyframes must reset the metadata compression state, so we cannot enable
metadata compression inside the encoders. Solve this by adding a new
flag, rather than removing it entirely, because I plan on adding
a bitstream filter for metadata compression.
---
 libavcodec/dovi_rpu.h    |  3 +++
 libavcodec/dovi_rpuenc.c | 27 +++++++++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 226a769bff..f0d9c24379 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -126,6 +126,9 @@ int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx);
 enum {
     FF_DOVI_WRAP_NAL        = 1 << 0, ///< wrap inside NAL RBSP
     FF_DOVI_WRAP_T35        = 1 << 1, ///< wrap inside T.35+EMDF
+
+    FF_DOVI_COMPRESS_VDR    = 1 << 2, ///< enable VDR RPU compression
+    FF_DOVI_COMPRESS_ALL    = FF_DOVI_COMPRESS_VDR,
 };
 
 /**
diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index 65c36ed0ae..631733c620 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -20,6 +20,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stdbool.h>
+
 #include "libavutil/avassert.h"
 #include "libavutil/crc.h"
 #include "libavutil/mem.h"
@@ -441,9 +443,10 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
     const AVDOVIRpuDataHeader *hdr;
     const AVDOVIDataMapping *mapping;
     const AVDOVIColorMetadata *color;
-    int vdr_dm_metadata_present, vdr_rpu_id, use_prev_vdr_rpu, profile,
+    int vdr_dm_metadata_present, vdr_rpu_id, profile,
         buffer_size, rpu_size, pad, zero_run;
     int num_ext_blocks_v1, num_ext_blocks_v2;
+    int use_prev_vdr_rpu = false;
     uint32_t crc;
     uint8_t *dst;
     if (!metadata) {
@@ -464,12 +467,21 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
     }
 
     vdr_rpu_id = mapping->vdr_rpu_id;
-    for (int i = 0; i <= DOVI_MAX_DM_ID; i++) {
-        if (s->vdr[i] && !memcmp(s->vdr[i], mapping, sizeof(*mapping))) {
-            vdr_rpu_id = i;
-            break;
-        } else if (s->vdr[vdr_rpu_id] && !s->vdr[i]) {
-            vdr_rpu_id = i;
+    if (flags & FF_DOVI_COMPRESS_VDR) {
+        for (int i = 0; i <= DOVI_MAX_DM_ID; i++) {
+            if (s->vdr[i] && !memcmp(s->vdr[i], mapping, sizeof(*mapping))) {
+                use_prev_vdr_rpu = true;
+                vdr_rpu_id = i;
+                break;
+            } else if (s->vdr[vdr_rpu_id] && !s->vdr[i]) {
+                vdr_rpu_id = i;
+            }
+        }
+    } else {
+        /* Flush VDRs to avoid leaking old state after keyframe */
+        for (int i = 0; i <= DOVI_MAX_DM_ID; i++) {
+            if (i != vdr_rpu_id)
+                ff_refstruct_unref(&s->vdr[i]);
         }
     }
 
@@ -513,7 +525,6 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
     }
 
     vdr_dm_metadata_present = memcmp(color, &ff_dovi_color_default, sizeof(*color));
-    use_prev_vdr_rpu = !memcmp(s->vdr[vdr_rpu_id], mapping, sizeof(*mapping));
     if (num_ext_blocks_v1 || num_ext_blocks_v2)
         vdr_dm_metadata_present = 1;
 
-- 
2.45.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:[~2024-06-18 19:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 19:35 [FFmpeg-devel] [PATCH 0/8] DoVi metadata compression Niklas Haas
2024-06-18 19:35 ` [FFmpeg-devel] [PATCH 1/8] avcodec/dovi_rpudec: clarify semantics Niklas Haas
2024-06-18 19:35 ` [FFmpeg-devel] [PATCH 2/8] avcodec/dovi_rpuenc: also copy ext blocks to dovi ctx Niklas Haas
2024-06-18 19:35 ` [FFmpeg-devel] [PATCH 3/8] avcodec/dovi_rpuenc: try to re-use existing vdr_rpu_id Niklas Haas
2024-06-18 19:50   ` Niklas Haas
2024-06-18 19:35 ` [FFmpeg-devel] [PATCH 4/8] avcodec/dovi_rpuenc: add `flags` to ff_dovi_rpu_generate() Niklas Haas
2024-06-18 19:35 ` [FFmpeg-devel] [PATCH 5/8] avcodec/dovi_rpuenc: make encapsulation optional Niklas Haas
2024-06-18 19:35 ` Niklas Haas [this message]
2024-06-18 19:35 ` [FFmpeg-devel] [PATCH 7/8] avcodec/dovi_rpu: add ff_dovi_get_metadata() Niklas Haas
2024-06-18 19:35 ` [FFmpeg-devel] [PATCH 8/8] avcodec/bsf/dovi_rpu: add new bitstream filter Niklas Haas

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=20240618194221.26073-7-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /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