[FFmpeg-devel] [PATCH v2 3/4] avcodec/h2645_sei: decode AFGS1 T.35 SEI

Niklas Haas ffmpeg at haasn.xyz
Fri Mar 8 15:21:08 EET 2024


From: Niklas Haas <git at haasn.dev>

Changes from v1:
- fixed field size of provider_oriented_code (8 instead of 16 bits)

---
I restricted this SEI to HEVC for now, until I see a H.264 sample.
---
 libavcodec/Makefile    |  2 +-
 libavcodec/h2645_sei.c | 38 ++++++++++++++++++++++++++++++++++++++
 libavcodec/h2645_sei.h |  3 +++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5d99120aa91..68e5394d84e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -105,7 +105,7 @@ OBJS-$(CONFIG_H264_SEI)                += h264_sei.o h2645_sei.o
 OBJS-$(CONFIG_HEVCPARSE)               += hevc_parse.o hevc_ps.o hevc_data.o \
                                           h2645data.o h2645_parse.o h2645_vui.o
 OBJS-$(CONFIG_HEVC_SEI)                += hevc_sei.o h2645_sei.o \
-                                          dynamic_hdr_vivid.o
+                                          dynamic_hdr_vivid.o aom_film_grain.o
 OBJS-$(CONFIG_HPELDSP)                 += hpeldsp.o
 OBJS-$(CONFIG_HUFFMAN)                 += huffman.o
 OBJS-$(CONFIG_HUFFYUVDSP)              += huffyuvdsp.o
diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index e60606f43f9..d6452e8fbfa 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -209,6 +209,24 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb,
         }
         break;
     }
+    case 0x5890: { // aom_provider_code
+        const uint16_t aom_grain_provider_oriented_code = 0x0001;
+        uint16_t provider_oriented_code;
+
+        if (!IS_HEVC(codec_id))
+            goto unsupported_provider_code;
+
+        if (bytestream2_get_bytes_left(gb) < 2)
+            return AVERROR_INVALIDDATA;
+
+        provider_oriented_code = bytestream2_get_byteu(gb);
+        if (provider_oriented_code == aom_grain_provider_oriented_code) {
+            return ff_aom_parse_film_grain_sets(&h->aom_film_grain,
+                                                gb->buffer,
+                                                bytestream2_get_bytes_left(gb));
+        }
+        break;
+    }
     unsupported_provider_code:
 #endif
     default:
@@ -692,6 +710,25 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
             avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
     }
 
+#if CONFIG_HEVC_SEI
+    if (sei->aom_film_grain.enable) {
+        const AVFilmGrainAOMParamSet *fgps;
+        fgps = ff_aom_select_film_grain_set(&sei->aom_film_grain, frame);
+        if (fgps && fgps->apply_grain) {
+            AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame);
+            if (!fgp)
+                return AVERROR(ENOMEM);
+
+            fgp->type = AV_FILM_GRAIN_PARAMS_AV1;
+            fgp->seed = fgps->grain_seed;
+            fgp->codec.aom = fgps->params;
+
+            if (avctx)
+                avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
+        }
+    }
+#endif
+
     if (sei->ambient_viewing_environment.present) {
         H2645SEIAmbientViewingEnvironment *env =
             &sei->ambient_viewing_environment;
@@ -788,4 +825,5 @@ void ff_h2645_sei_reset(H2645SEI *s)
     s->ambient_viewing_environment.present = 0;
     s->mastering_display.present = 0;
     s->content_light.present = 0;
+    s->aom_film_grain.enable = 0;
 }
diff --git a/libavcodec/h2645_sei.h b/libavcodec/h2645_sei.h
index 0ebf48011af..e5fcfd4e0c2 100644
--- a/libavcodec/h2645_sei.h
+++ b/libavcodec/h2645_sei.h
@@ -23,7 +23,9 @@
 
 #include "libavutil/buffer.h"
 #include "libavutil/frame.h"
+#include "libavutil/film_grain_params.h"
 
+#include "aom_film_grain.h"
 #include "avcodec.h"
 #include "bytestream.h"
 #include "codec_id.h"
@@ -132,6 +134,7 @@ typedef struct H2645SEI {
     H2645SEIAmbientViewingEnvironment ambient_viewing_environment;
     H2645SEIMasteringDisplay mastering_display;
     H2645SEIContentLight content_light;
+    AVFilmGrainAOMParamSets aom_film_grain;
 } H2645SEI;
 
 enum {
-- 
2.44.0



More information about the ffmpeg-devel mailing list