summaryrefslogtreecommitdiff
path: root/libavcodec/hevc_sei.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2021-07-23 14:10:00 -0300
committerJames Almer <jamrial@gmail.com>2021-08-06 09:56:44 -0300
commit82be9f277781afa7f90a2d93bfda818c1dc84551 (patch)
tree38bae1fd26c12189285d6570f0770185bb4707b7 /libavcodec/hevc_sei.c
parent794e15fd54db9cef85a02f21354090d718f81d22 (diff)
avcodec/hevc_sei: parse and export Film Grain Characteristics SEI messages
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/hevc_sei.c')
-rw-r--r--libavcodec/hevc_sei.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index e6ae777852..2c326bf1f7 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -395,6 +395,48 @@ static int decode_nal_sei_timecode(HEVCSEITimeCode *s, GetBitContext *gb)
return 0;
}
+static int decode_film_grain_characteristics(HEVCSEIFilmGrainCharacteristics *h,
+ GetBitContext *gb)
+{
+ h->present = !get_bits1(gb); // film_grain_characteristics_cancel_flag
+
+ if (h->present) {
+ memset(h, 0, sizeof(*h));
+ h->model_id = get_bits(gb, 2);
+ h->separate_colour_description_present_flag = get_bits1(gb);
+ if (h->separate_colour_description_present_flag) {
+ h->bit_depth_luma = get_bits(gb, 3) + 8;
+ h->bit_depth_chroma = get_bits(gb, 3) + 8;
+ h->full_range = get_bits1(gb);
+ h->color_primaries = get_bits(gb, 8);
+ h->transfer_characteristics = get_bits(gb, 8);
+ h->matrix_coeffs = get_bits(gb, 8);
+ }
+ h->blending_mode_id = get_bits(gb, 2);
+ h->log2_scale_factor = get_bits(gb, 4);
+ for (int c = 0; c < 3; c++)
+ h->comp_model_present_flag[c] = get_bits1(gb);
+ for (int c = 0; c < 3; c++) {
+ if (h->comp_model_present_flag[c]) {
+ h->num_intensity_intervals[c] = get_bits(gb, 8) + 1;
+ h->num_model_values[c] = get_bits(gb, 3) + 1;
+ if (h->num_model_values[c] > 6)
+ return AVERROR_INVALIDDATA;
+ for (int i = 0; i < h->num_intensity_intervals[c]; i++) {
+ h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8);
+ h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8);
+ for (int j = 0; j < h->num_model_values[c]; j++)
+ h->comp_model_value[c][i][j] = get_se_golomb_long(gb);
+ }
+ }
+ }
+ h->persistence_flag = get_bits1(gb);
+
+ h->present = 1;
+ }
+
+ return 0;
+}
static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s,
const HEVCParamSets *ps, int type, int size)
@@ -422,6 +464,8 @@ static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s,
return decode_nal_sei_alternative_transfer(&s->alternative_transfer, gb);
case SEI_TYPE_TIME_CODE:
return decode_nal_sei_timecode(&s->timecode, gb);
+ case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
+ return decode_film_grain_characteristics(&s->film_grain_characteristics, gb);
default:
av_log(logctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
skip_bits_long(gb, 8 * size);