summaryrefslogtreecommitdiff
path: root/libavcodec/h264_slice.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2021-07-23 11:06:45 -0300
committerJames Almer <jamrial@gmail.com>2021-07-23 11:06:45 -0300
commit4ff73add5dbe6c319d693355be44df2e17a0b8bf (patch)
tree8e85d3357aca65d9fab4e26c8ae26552ba2c4465 /libavcodec/h264_slice.c
parente3b5ff17c2e54d557d2c897aa7e491ea4d3df708 (diff)
avcodec/h264_sei: parse and export Film Grain Characteristics SEI messages
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/h264_slice.c')
-rw-r--r--libavcodec/h264_slice.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 20055e6f7a..41338fbcb6 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -28,6 +28,7 @@
#include "libavutil/avassert.h"
#include "libavutil/display.h"
#include "libavutil/imgutils.h"
+#include "libavutil/film_grain_params.h"
#include "libavutil/stereo3d.h"
#include "libavutil/timecode.h"
#include "internal.h"
@@ -1330,6 +1331,59 @@ static int h264_export_frame_props(H264Context *h)
}
h->sei.unregistered.nb_buf_ref = 0;
+ if (h->sei.film_grain_characteristics.present &&
+ (h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) {
+ H264SEIFilmGrainCharacteristics *fgc = &h->sei.film_grain_characteristics;
+ AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(out);
+ if (!fgp)
+ return AVERROR(ENOMEM);
+
+ fgp->type = AV_FILM_GRAIN_PARAMS_H274;
+
+ fgp->codec.h274.model_id = fgc->model_id;
+ if (fgc->separate_colour_description_present_flag) {
+ fgp->codec.h274.bit_depth_luma = fgc->bit_depth_luma;
+ fgp->codec.h274.bit_depth_chroma = fgc->bit_depth_chroma;
+ fgp->codec.h274.color_range = fgc->full_range + 1;
+ fgp->codec.h274.color_primaries = fgc->color_primaries;
+ fgp->codec.h274.color_trc = fgc->transfer_characteristics;
+ fgp->codec.h274.color_space = fgc->matrix_coeffs;
+ } else {
+ fgp->codec.h274.bit_depth_luma = sps->bit_depth_luma;
+ fgp->codec.h274.bit_depth_chroma = sps->bit_depth_chroma;
+ if (sps->video_signal_type_present_flag)
+ fgp->codec.h274.color_range = sps->full_range + 1;
+ else
+ fgp->codec.h274.color_range = AVCOL_RANGE_UNSPECIFIED;
+ if (sps->colour_description_present_flag) {
+ fgp->codec.h274.color_primaries = sps->color_primaries;
+ fgp->codec.h274.color_trc = sps->color_trc;
+ fgp->codec.h274.color_space = sps->colorspace;
+ } else {
+ fgp->codec.h274.color_primaries = AVCOL_PRI_UNSPECIFIED;
+ fgp->codec.h274.color_trc = AVCOL_TRC_UNSPECIFIED;
+ fgp->codec.h274.color_space = AVCOL_SPC_UNSPECIFIED;
+ }
+ }
+ fgp->codec.h274.blending_mode_id = fgc->blending_mode_id;
+ fgp->codec.h274.log2_scale_factor = fgc->log2_scale_factor;
+
+ memcpy(&fgp->codec.h274.component_model_present, &fgc->comp_model_present_flag,
+ sizeof(fgp->codec.h274.component_model_present));
+ memcpy(&fgp->codec.h274.num_intensity_intervals, &fgc->num_intensity_intervals,
+ sizeof(fgp->codec.h274.num_intensity_intervals));
+ memcpy(&fgp->codec.h274.num_model_values, &fgc->num_model_values,
+ sizeof(fgp->codec.h274.num_model_values));
+ memcpy(&fgp->codec.h274.intensity_interval_lower_bound, &fgc->intensity_interval_lower_bound,
+ sizeof(fgp->codec.h274.intensity_interval_lower_bound));
+ memcpy(&fgp->codec.h274.intensity_interval_upper_bound, &fgc->intensity_interval_upper_bound,
+ sizeof(fgp->codec.h274.intensity_interval_upper_bound));
+ memcpy(&fgp->codec.h274.comp_model_value, &fgc->comp_model_value,
+ sizeof(fgp->codec.h274.comp_model_value));
+
+ fgc->present = !!fgc->repetition_period;
+ }
+
if (h->sei.picture_timing.timecode_cnt > 0) {
uint32_t *tc_sd;
char tcbuf[AV_TIMECODE_STR_SIZE];