Browse code

h264: Add support for alternative transfer characterics SEI

The use of this SEI is for backward compatibility in HLG HDR systems:
older devices that cannot interpret the "arib-std-b67" transfer will
get the compatible transfer (usually bt709 or bt2020) from the VUI,
while newer devices that can interpret HDR will read the SEI and use
its value instead.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>

Vittorio Giovara authored on 2017/06/10 06:27:22
Showing 3 changed files
... ...
@@ -382,6 +382,14 @@ static int decode_green_metadata(H264SEIGreenMetaData *h, GetBitContext *gb)
382 382
     return 0;
383 383
 }
384 384
 
385
+static int decode_alternative_transfer(H264SEIAlternativeTransfer *h,
386
+                                       GetBitContext *gb)
387
+{
388
+    h->present = 1;
389
+    h->preferred_transfer_characteristics = get_bits(gb, 8);
390
+    return 0;
391
+}
392
+
385 393
 int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
386 394
                        const H264ParamSets *ps, void *logctx)
387 395
 {
... ...
@@ -437,6 +445,9 @@ int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
437 437
         case SEI_TYPE_GREEN_METADATA:
438 438
             ret = decode_green_metadata(&h->green_metadata, gb);
439 439
             break;
440
+        case SEI_TYPE_ALTERNATIVE_TRANSFER:
441
+            ret = decode_alternative_transfer(&h->alternative_transfer, gb);
442
+            break;
440 443
         default:
441 444
             av_log(logctx, AV_LOG_DEBUG, "unknown SEI type %d\n", type);
442 445
         }
... ...
@@ -32,7 +32,8 @@ typedef enum {
32 32
     SEI_TYPE_RECOVERY_POINT         = 6,   ///< recovery point (frame # to decoder sync)
33 33
     SEI_TYPE_FRAME_PACKING          = 45,  ///< frame packing arrangement
34 34
     SEI_TYPE_DISPLAY_ORIENTATION    = 47,  ///< display orientation
35
-    SEI_TYPE_GREEN_METADATA         = 56   ///< GreenMPEG information
35
+    SEI_TYPE_GREEN_METADATA         = 56,  ///< GreenMPEG information
36
+    SEI_TYPE_ALTERNATIVE_TRANSFER   = 147, ///< alternative transfer
36 37
 } SEI_Type;
37 38
 
38 39
 /**
... ...
@@ -144,6 +145,11 @@ typedef struct H264SEIGreenMetaData {
144 144
     uint16_t xsd_metric_value;
145 145
 } H264SEIGreenMetaData;
146 146
 
147
+typedef struct H264SEIAlternativeTransfer {
148
+    int present;
149
+    int preferred_transfer_characteristics;
150
+} H264SEIAlternativeTransfer;
151
+
147 152
 typedef struct H264SEIContext {
148 153
     H264SEIPictureTiming picture_timing;
149 154
     H264SEIAFD afd;
... ...
@@ -154,6 +160,7 @@ typedef struct H264SEIContext {
154 154
     H264SEIFramePacking frame_packing;
155 155
     H264SEIDisplayOrientation display_orientation;
156 156
     H264SEIGreenMetaData green_metadata;
157
+    H264SEIAlternativeTransfer alternative_transfer;
157 158
 } H264SEIContext;
158 159
 
159 160
 struct H264ParamSets;
... ...
@@ -1287,6 +1287,12 @@ static int h264_export_frame_props(H264Context *h)
1287 1287
         h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
1288 1288
     }
1289 1289
 
1290
+    if (h->sei.alternative_transfer.present &&
1291
+        av_color_transfer_name(h->sei.alternative_transfer.preferred_transfer_characteristics) &&
1292
+        h->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
1293
+        h->avctx->color_trc = cur->f->color_trc = h->sei.alternative_transfer.preferred_transfer_characteristics;
1294
+    }
1295
+
1290 1296
     return 0;
1291 1297
 }
1292 1298