26#include "config_components.h"
45#define IS_H264(codec_id) (CONFIG_H264_SEI && (CONFIG_HEVC_SEI || CONFIG_VVC_SEI ) ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI)
46#define IS_HEVC(codec_id) (CONFIG_HEVC_SEI && (CONFIG_H264_SEI || CONFIG_VVC_SEI ) ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI)
47#define IS_VVC(codec_id) (CONFIG_VVC_SEI && (CONFIG_H264_SEI || CONFIG_HEVC_SEI) ? codec_id == AV_CODEC_ID_VVC : CONFIG_VVC_SEI )
59 "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d, provider_code = %d)\n",
91 h->buf_ref[
h->nb_buf_ref++] = buf_ref;
95 e = sscanf(
user_data + 16,
"x264 - core %d", &build);
96 if (e == 1 && build > 0)
97 h->x264_build = build;
98 if (e == 1 && build == 1 && !strncmp(
user_data+16,
"x264 - core 0000", 16))
114 h->anticlockwise_rotation =
get_bits(gb, 16);
129 h->present = !
h->arrangement_cancel_flag;
134 h->content_interpretation_type =
get_bits(gb, 6);
138 h->current_frame_is_frame0_flag =
get_bits1(gb);
142 if (!
h->quincunx_sampling_flag &&
h->arrangement_type != 5)
164 s->preferred_transfer_characteristics = bytestream2_get_byteu(gb);
172 static const uint16_t max_ambient_light_value = 50000;
177 s->ambient_illuminance = bytestream2_get_be32u(gb);
178 if (!
s->ambient_illuminance)
181 s->ambient_light_x = bytestream2_get_be16u(gb);
182 if (
s->ambient_light_x > max_ambient_light_value)
185 s->ambient_light_y = bytestream2_get_be16u(gb);
186 if (
s->ambient_light_y > max_ambient_light_value)
200 memset(
h, 0,
sizeof(*
h));
202 h->separate_colour_description_present_flag =
get_bits1(gb);
203 if (
h->separate_colour_description_present_flag) {
205 h->bit_depth_chroma =
get_bits(gb, 3) + 8;
208 h->transfer_characteristics =
get_bits(gb, 8);
213 for (
int c = 0;
c < 3;
c++)
215 for (
int c = 0;
c < 3;
c++) {
216 if (
h->comp_model_present_flag[
c]) {
217 h->num_intensity_intervals[
c] =
get_bits(gb, 8) + 1;
219 if (
h->num_model_values[
c] > 6)
221 for (
int i = 0;
i <
h->num_intensity_intervals[
c];
i++) {
222 h->intensity_interval_lower_bound[
c][
i] =
get_bits(gb, 8);
223 h->intensity_interval_upper_bound[
c][
i] =
get_bits(gb, 8);
224 for (
int j = 0; j <
h->num_model_values[
c]; j++)
249 for (
i = 0;
i < 3;
i++) {
250 s->display_primaries[
i][0] = bytestream2_get_be16u(gb);
251 s->display_primaries[
i][1] = bytestream2_get_be16u(gb);
254 s->white_point[0] = bytestream2_get_be16u(gb);
255 s->white_point[1] = bytestream2_get_be16u(gb);
258 s->max_luminance = bytestream2_get_be32u(gb);
259 s->min_luminance = bytestream2_get_be32u(gb);
276 s->max_content_light_level = bytestream2_get_be16u(gb);
277 s->max_pic_average_light_level = bytestream2_get_be16u(gb);
300 if (!
h->film_grain_characteristics)
323 src->itut_t35.a53_cc);
327 for (
unsigned i = 0;
i <
dst->unregistered.nb_buf_ref;
i++)
329 dst->unregistered.nb_buf_ref = 0;
335 if (
src->unregistered.nb_buf_ref) {
337 src->unregistered.nb_buf_ref,
338 sizeof(*
dst->unregistered.buf_ref));
342 for (
unsigned i = 0;
i <
src->unregistered.nb_buf_ref;
i++) {
344 if (!
dst->unregistered.buf_ref[
i])
346 dst->unregistered.nb_buf_ref++;
352 src->itut_t35.aom_film_grain.sets[
i]);
356 dst->itut_t35.aom_film_grain.enable =
src->itut_t35.aom_film_grain.enable;
358 dst->ambient_viewing_environment =
src->ambient_viewing_environment;
359 dst->mastering_display =
src->mastering_display;
360 dst->content_light =
src->content_light;
363 src->film_grain_characteristics);
383 for (
unsigned i = 0;
i <
sei->unregistered.nb_buf_ref;
i++) {
394 sei->unregistered.nb_buf_ref = 0;
396 if (
sei->ambient_viewing_environment.present) {
423 if (
sei->mastering_display.present) {
425 const int mapping[3] = {2, 0, 1};
426 const int chroma_den = 50000;
427 const int luma_den = 10000;
439 for (
i = 0;
i < 3;
i++) {
440 const int j = mapping[
i];
441 metadata->display_primaries[
i][0].num =
sei->mastering_display.display_primaries[j][0];
442 metadata->display_primaries[
i][0].den = chroma_den;
443 metadata->has_primaries &=
sei->mastering_display.display_primaries[j][0] >= 5 &&
444 sei->mastering_display.display_primaries[j][0] <= 37000;
446 metadata->display_primaries[
i][1].num =
sei->mastering_display.display_primaries[j][1];
447 metadata->display_primaries[
i][1].den = chroma_den;
448 metadata->has_primaries &=
sei->mastering_display.display_primaries[j][1] >= 5 &&
449 sei->mastering_display.display_primaries[j][1] <= 42000;
451 metadata->white_point[0].num =
sei->mastering_display.white_point[0];
452 metadata->white_point[0].den = chroma_den;
453 metadata->has_primaries &=
sei->mastering_display.white_point[0] >= 5 &&
454 sei->mastering_display.white_point[0] <= 37000;
456 metadata->white_point[1].num =
sei->mastering_display.white_point[1];
457 metadata->white_point[1].den = chroma_den;
458 metadata->has_primaries &=
sei->mastering_display.white_point[1] >= 5 &&
459 sei->mastering_display.white_point[1] <= 42000;
461 metadata->max_luminance.num =
sei->mastering_display.max_luminance;
462 metadata->max_luminance.den = luma_den;
463 metadata->has_luminance &=
sei->mastering_display.max_luminance >= 50000 &&
464 sei->mastering_display.max_luminance <= 100000000;
466 metadata->min_luminance.num =
sei->mastering_display.min_luminance;
467 metadata->min_luminance.den = luma_den;
468 metadata->has_luminance &=
sei->mastering_display.min_luminance <= 50000 &&
469 sei->mastering_display.min_luminance <
470 sei->mastering_display.max_luminance;
475 metadata->has_luminance &=
sei->mastering_display.min_luminance >= 1;
481 "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
492 "min_luminance=%f, max_luminance=%f\n",
498 if (
sei->content_light.present) {
506 metadata->MaxCLL =
sei->content_light.max_content_light_level;
507 metadata->MaxFALL =
sei->content_light.max_pic_average_light_level;
521 unsigned bit_depth_luma,
unsigned bit_depth_chroma,
579 if (
sei->display_orientation.present &&
580 (
sei->display_orientation.anticlockwise_rotation ||
581 sei->display_orientation.hflip ||
582 sei->display_orientation.vflip)) {
599 angle = -angle * (1 - 2 * !!o->
hflip) * (1 - 2 * !!o->
vflip);
622 if (itut_t35->
lcevc) {
629 if (
sei->film_grain_characteristics &&
sei->film_grain_characteristics->present) {
705 for (
unsigned i = 0;
i <
s->unregistered.nb_buf_ref;
i++)
707 s->unregistered.nb_buf_ref = 0;
710 s->ambient_viewing_environment.present = 0;
711 s->mastering_display.present = 0;
712 s->content_light.present = 0;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
AVAmbientViewingEnvironment * av_ambient_viewing_environment_alloc(size_t *size)
Allocate an AVAmbientViewingEnvironment structure.
int ff_aom_attach_film_grain_sets(const AVFilmGrainAFGS1Params *s, AVFrame *frame)
Libavcodec external API header.
refcounted data buffer API
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf)
Same as ff_frame_new_side_data_from_buf, but taking a AVFrameSideData array directly instead of an AV...
int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, struct AVMasteringDisplayMetadata **mdm)
Same as ff_decode_mastering_display_new, but taking a AVFrameSideData array directly instead of an AV...
int ff_decode_content_light_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, AVContentLightMetadata **clm)
Same as ff_decode_content_light_new, but taking a AVFrameSideData array directly instead of an AVFram...
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
@ AV_FILM_GRAIN_PARAMS_H274
The union is valid when interpreted as AVFilmGrainH274Params (codec.h274)
bitstream reader API header.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int get_se_golomb_long(GetBitContext *gb)
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
AVCodecID
Identify the syntax and semantics of the bitstream.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFrameSideData * av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf, unsigned int flags)
Add a new side data entry to an array from an existing AVBufferRef.
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
@ AV_FRAME_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
@ AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
Ambient viewing environment metadata, as defined by H.274.
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
static AVRational av_make_q(int num, int den)
Create an AVRational.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
@ AV_STEREO3D_COLUMNS
Views are packed per column.
@ AV_STEREO3D_LINES
Views are packed per line, as if interlaced.
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
@ AV_STEREO3D_CHECKERBOARD
Views are packed in a checkerboard-like structure per pixel.
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
@ AV_STEREO3D_SIDEBYSIDE_QUINCUNX
Views are next to each other, but when upscaling apply a checkerboard pattern.
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
@ AV_STEREO3D_VIEW_RIGHT
Frame contains only the right view.
@ AV_STEREO3D_VIEW_LEFT
Frame contains only the left view.
static int decode_unregistered_user_data(H2645SEIUnregistered *h, GetByteContext *gb, enum AVCodecID codec_id)
void ff_h2645_sei_reset(H2645SEI *s)
static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics *h, enum AVCodecID codec_id, GetBitContext *gb)
static int decode_frame_packing_arrangement(H2645SEIFramePacking *h, GetBitContext *gb, enum AVCodecID codec_id)
static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, AVFrameSideData ***sd, int *nb_sd)
static int decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s, GetByteContext *gb)
int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, enum AVCodecID codec_id, AVCodecContext *avctx, const H2645VUI *vui, unsigned bit_depth_luma, unsigned bit_depth_chroma, int seed)
int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, enum AVCodecID codec_id, void *logctx)
int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, enum AVCodecID codec_id, GetBitContext *gb, GetByteContext *gbyte, void *logctx)
Decode a single SEI message.
static int decode_nal_sei_mastering_display_info(H2645SEIMasteringDisplay *s, GetByteContext *gb)
int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei)
#define IS_H264(codec_id)
static int decode_alternative_transfer(H2645SEIAlternativeTransfer *s, GetByteContext *gb)
static int decode_nal_sei_content_light_info(H2645SEIContentLight *s, GetByteContext *gb)
static int decode_display_orientation(H2645SEIDisplayOrientation *h, GetBitContext *gb)
static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id)
@ FF_H2645_SEI_MESSAGE_UNHANDLED
int ff_itut_t35_parse_payload_to_struct(FFITUTT35 *const itut_t35, FFITUTT35Aux *const aux, FFITUTT35Meta *metadata, int err_recognition)
Parse a pre-processed ITU-T T35 payload to fill the metadata struct.
int ff_itut_t35_parse_buffer(FFITUTT35 *const itut_t35, const uint8_t *buf, size_t buf_size, int flags)
Parse a raw ITU-T T35 buffer to get the country code, provider code, and set them plus the pointer an...
void ff_itut_t35_unref(FFITUTT35Meta *metadata)
Unref all references in metadata.
Memory handling functions.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
SEIFpaType
frame_packing_arrangement types.
@ SEI_FPA_TYPE_TOP_BOTTOM
@ SEI_FPA_H264_TYPE_CHECKERBOARD
@ SEI_FPA_TYPE_INTERLEAVE_TEMPORAL
@ SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN
@ SEI_FPA_H264_TYPE_INTERLEAVE_ROW
@ SEI_FPA_TYPE_SIDE_BY_SIDE
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
@ SEI_TYPE_DISPLAY_ORIENTATION
@ SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
@ SEI_TYPE_FRAME_PACKING_ARRANGEMENT
@ SEI_TYPE_USER_DATA_UNREGISTERED
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
@ SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
#define FF_ARRAY_ELEMS(a)
Ambient viewing environment metadata as defined by H.274.
AVRational ambient_illuminance
Environmental illuminance of the ambient viewing environment in lux.
AVRational ambient_light_x
Normalized x chromaticity coordinate of the environmental ambient light in the nominal viewing enviro...
AVRational ambient_light_y
Normalized y chromaticity coordinate of the environmental ambient light in the nominal viewing enviro...
A reference to a data buffer.
uint8_t * data
The data buffer.
size_t size
Size of data in bytes.
main external API structure.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
This structure describes how to handle film grain synthesis for codecs using the ITU-T H....
uint8_t intensity_interval_upper_bound[3][256]
Specifies the upper bound of each intensity interval for which the set of model values applies for th...
int blending_mode_id
Specifies the blending mode used to blend the simulated film grain with the decoded images.
uint8_t intensity_interval_lower_bound[3][256]
Specifies the lower ounds of each intensity interval for whichthe set of model values applies for the...
int log2_scale_factor
Specifies a scale factor used in the film grain characterization equations.
int16_t comp_model_value[3][256][6]
Specifies the model values for the component for each intensity interval.
int model_id
Specifies the film grain simulation mode.
int component_model_present[3]
Indicates if the modelling of film grain for a given component is present.
uint16_t num_intensity_intervals[3]
Specifies the number of intensity intervals for which a specific set of model values has been estimat...
uint8_t num_model_values[3]
Specifies the number of model values present for each intensity interval in which the film grain has ...
This structure describes how to handle film grain synthesis in video for specific codecs.
enum AVColorPrimaries color_primaries
AVFilmGrainH274Params h274
enum AVColorRange color_range
Intended video signal characteristics.
int subsampling_x
Intended subsampling ratio, or 0 for luma-only streams.
int bit_depth_luma
Intended bit depth, or 0 for unknown/unspecified.
union AVFilmGrainParams::@177057277273004265167152242113040056044005264354 codec
Additional fields may be added both here and in any structure included.
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
int width
Intended display resolution.
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
enum AVColorTransferCharacteristic color_trc
enum AVColorSpace color_space
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
enum AVStereo3DType type
How views are packed within the video.
int flags
Additional information about the frame packing.
enum AVStereo3DView view
Determines which views are packed.
uint32_t ambient_illuminance
int anticlockwise_rotation
int16_t comp_model_value[3][256][6]
uint8_t num_model_values[3]
int transfer_characteristics
uint16_t num_intensity_intervals[3]
int comp_model_present_flag[3]
uint8_t intensity_interval_lower_bound[3][256]
int separate_colour_description_present_flag
uint8_t intensity_interval_upper_bound[3][256]
int current_frame_is_frame0_flag
int content_interpretation_type
SEIFpaType arrangement_type
int quincunx_sampling_flag
enum AVColorPrimaries colour_primaries
int video_signal_type_present_flag
enum AVColorTransferCharacteristic transfer_characteristics
int video_full_range_flag
enum AVColorSpace matrix_coeffs
int colour_description_present_flag