Commit ebf3b9e8 authored by Vittorio Giovara's avatar Vittorio Giovara

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: 's avatarVittorio Giovara <vittorio.giovara@gmail.com>
parent 19388a72
...@@ -346,6 +346,14 @@ static int decode_display_orientation(H264SEIDisplayOrientation *h, ...@@ -346,6 +346,14 @@ static int decode_display_orientation(H264SEIDisplayOrientation *h,
return 0; return 0;
} }
static int decode_alternative_transfer(H264SEIAlternativeTransfer *h,
GetBitContext *gb)
{
h->present = 1;
h->preferred_transfer_characteristics = get_bits(gb, 8);
return 0;
}
int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb, int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
const H264ParamSets *ps, void *logctx) const H264ParamSets *ps, void *logctx)
{ {
...@@ -396,6 +404,9 @@ int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb, ...@@ -396,6 +404,9 @@ int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
case H264_SEI_TYPE_DISPLAY_ORIENTATION: case H264_SEI_TYPE_DISPLAY_ORIENTATION:
ret = decode_display_orientation(&h->display_orientation, gb); ret = decode_display_orientation(&h->display_orientation, gb);
break; break;
case H264_SEI_TYPE_ALTERNATIVE_TRANSFER:
ret = decode_alternative_transfer(&h->alternative_transfer, gb);
break;
default: default:
av_log(logctx, AV_LOG_DEBUG, "unknown SEI type %d\n", type); av_log(logctx, AV_LOG_DEBUG, "unknown SEI type %d\n", type);
skip_bits(gb, 8 * size); skip_bits(gb, 8 * size);
......
...@@ -33,6 +33,7 @@ typedef enum { ...@@ -33,6 +33,7 @@ typedef enum {
H264_SEI_TYPE_RECOVERY_POINT = 6, ///< recovery point (frame # to decoder sync) H264_SEI_TYPE_RECOVERY_POINT = 6, ///< recovery point (frame # to decoder sync)
H264_SEI_TYPE_FRAME_PACKING = 45, ///< frame packing arrangement H264_SEI_TYPE_FRAME_PACKING = 45, ///< frame packing arrangement
H264_SEI_TYPE_DISPLAY_ORIENTATION = 47, ///< display orientation H264_SEI_TYPE_DISPLAY_ORIENTATION = 47, ///< display orientation
H264_SEI_TYPE_ALTERNATIVE_TRANSFER = 147, ///< alternative transfer
} H264_SEI_Type; } H264_SEI_Type;
/** /**
...@@ -115,6 +116,11 @@ typedef struct H264SEIDisplayOrientation { ...@@ -115,6 +116,11 @@ typedef struct H264SEIDisplayOrientation {
int hflip, vflip; int hflip, vflip;
} H264SEIDisplayOrientation; } H264SEIDisplayOrientation;
typedef struct H264SEIAlternativeTransfer {
int present;
int preferred_transfer_characteristics;
} H264SEIAlternativeTransfer;
typedef struct H264SEIContext { typedef struct H264SEIContext {
H264SEIPictureTiming picture_timing; H264SEIPictureTiming picture_timing;
H264SEIAFD afd; H264SEIAFD afd;
...@@ -124,6 +130,7 @@ typedef struct H264SEIContext { ...@@ -124,6 +130,7 @@ typedef struct H264SEIContext {
H264SEIBufferingPeriod buffering_period; H264SEIBufferingPeriod buffering_period;
H264SEIFramePacking frame_packing; H264SEIFramePacking frame_packing;
H264SEIDisplayOrientation display_orientation; H264SEIDisplayOrientation display_orientation;
H264SEIAlternativeTransfer alternative_transfer;
} H264SEIContext; } H264SEIContext;
struct H264ParamSets; struct H264ParamSets;
......
...@@ -1154,6 +1154,12 @@ static int h264_export_frame_props(H264Context *h) ...@@ -1154,6 +1154,12 @@ static int h264_export_frame_props(H264Context *h)
a53->a53_caption_size = 0; a53->a53_caption_size = 0;
} }
if (h->sei.alternative_transfer.present &&
av_color_transfer_name(h->sei.alternative_transfer.preferred_transfer_characteristics) &&
h->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
h->avctx->color_trc = cur->f->color_trc = h->sei.alternative_transfer.preferred_transfer_characteristics;
}
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment