41 [1] = {1280*720*24, 1280, 20, 50},
42 [2] = {1280*720*30, 1280, 20, 50},
43 [3] = {1920*1080*24, 1920, 20, 70},
44 [4] = {1920*1080*30, 2560, 20, 70},
45 [5] = {1920*1080*60, 3840, 20, 70},
46 [6] = {3840*2160*24, 3840, 25, 130},
47 [7] = {3840*2160*30, 3840, 25, 130},
48 [8] = {3840*2160*48, 3840, 40, 130},
49 [9] = {3840*2160*60, 3840, 40, 130},
50 [10] = {3840*2160*120, 3840, 60, 240},
51 [11] = {3840*2160*120, 7680, 60, 240},
52 [12] = {7680*4320*60, 7680, 120, 450},
53 [13] = {7680*4320*120u, 7680, 240, 800},
59 int strict_std_compliance,
67 int *nb_coded_side_data)
71 int dv_profile, dv_level, bl_compat_id = -1;
106 av_unreachable(
"ff_dovi_configure only used with AV1, H.264 and HEVC");
110 if (dv_profile == 9) {
119 switch (dv_profile) {
124 "layers is currently unsupported.");
156 if (!dv_profile || bl_compat_id < 0) {
159 "not determine profile and compatibility mode. Double-check "
160 "colorspace and format settings for compatibility?\n");
169 "is not permitted for profiles 7 and earlier. (dv_profile: %d, "
170 "compression: %d)\n", dv_profile, compression);
175 "compression is experimental and not supported by "
178 }
else if (dv_profile == 8) {
180 "for profile 8 is known to be unsupported by many devices, "
181 "use with caution.\n");
209 "exceed Dolby Vision limitations\n",
pps,
width);
213 "exceed Dolby Vision limitations. Ignoring, resulting file "
214 "may be non-conforming.\n",
pps,
width);
230 cfg->dv_version_major = 1;
231 cfg->dv_version_minor = 0;
232 cfg->dv_profile = dv_profile;
233 cfg->dv_level = dv_level;
234 cfg->rpu_present_flag = 1;
235 cfg->el_present_flag = 0;
236 cfg->bl_present_flag = 1;
237 cfg->dv_bl_signal_compatibility_id = bl_compat_id;
238 cfg->dv_md_compression = compression;
251 int strict_std_compliance)
315 if (!memcmp(&ext->
dm_static[j], dm,
sizeof(*dm))) {
337 union { uint32_t u32;
float f32; } fpart;
355 union { uint32_t u32;
float f32; } fpart;
372 return value <= 0xFFFE;
401 for (
int c = 0;
c < 3;
c++) {
426 for (
int k = 0; k < 7; k++)
439 for (
int c = 0;
c < 3;
c++) {
453 if (!q.
den || q.
den == den)
461 int ext_block_length, start_pos, pad_bits;
464 case 1: ext_block_length = 5;
break;
465 case 2: ext_block_length = 11;
break;
466 case 4: ext_block_length = 3;
break;
467 case 5: ext_block_length = 7;
break;
468 case 6: ext_block_length = 8;
break;
469 case 255: ext_block_length = 6;
break;
511 for (
int i = 0;
i < 4;
i++)
516 pad_bits = ext_block_length * 8 - (
put_bits_count(pb) - start_pos);
523 const int denom = 32767;
528#define ANY6(arr) (arr[0] || arr[1] || arr[2] || arr[3] || arr[4] || arr[5])
529#define ANY_XY(xy) (xy.x.num || xy.y.num)
530#define ANY_CSP(csp) (ANY_XY(csp.prim.r) || ANY_XY(csp.prim.g) || \
531 ANY_XY(csp.prim.b) || ANY_XY(csp.wp))
535 int ext_block_length, start_pos, pad_bits;
538 case 3: ext_block_length = 5;
break;
541 ext_block_length = 25;
543 ext_block_length = 19;
545 ext_block_length = 13;
547 ext_block_length = 12;
549 ext_block_length = 10;
554 ext_block_length = 17;
556 ext_block_length = 1;
561 ext_block_length = 21;
563 ext_block_length = 5;
566 case 11: ext_block_length = 4;
break;
567 case 254: ext_block_length = 2;
break;
589 if (ext_block_length < 12)
592 if (ext_block_length < 13)
595 if (ext_block_length < 19)
597 for (
int i = 0;
i < 6;
i++)
599 if (ext_block_length < 25)
601 for (
int i = 0;
i < 6;
i++)
606 if (ext_block_length < 17)
618 if (ext_block_length < 21)
639 pad_bits = ext_block_length * 8 - (
put_bits_count(pb) - start_pos);
651 int vdr_dm_metadata_present, vdr_rpu_id, use_prev_vdr_rpu,
profile,
652 buffer_size, rpu_size, pad, zero_run, dm_compression;
653 int num_ext_blocks_v1, num_ext_blocks_v2;
654 int dv_md_compression =
s->cfg.dv_md_compression;
692 use_prev_vdr_rpu = 0;
694 if (!
s->vdr[vdr_rpu_id]) {
696 if (!
s->vdr[vdr_rpu_id])
700 switch (dv_md_compression) {
707 if (
s->vdr[vdr_rpu_id])
708 use_prev_vdr_rpu = !memcmp(
s->vdr[vdr_rpu_id], mapping,
sizeof(*mapping));
723 if (
metadata->num_ext_blocks && !
s->ext_blocks) {
731 vdr_dm_metadata_present = 1;
733 if (vdr_dm_metadata_present && !
s->dm) {
745 num_ext_blocks_v1 = num_ext_blocks_v2 = 0;
746 for (
int i = 0;
i <
metadata->num_ext_blocks;
i++) {
775 buffer_size = 12 + 5 ;
776 buffer_size += num_ext_blocks_v1 * 13;
777 buffer_size += num_ext_blocks_v2 * 28;
778 if (!use_prev_vdr_rpu) {
780 for (
int c = 0;
c < 3;
c++) {
789 if (vdr_dm_metadata_present)
821 put_bits(pb, 1, vdr_dm_metadata_present);
824 s->mapping =
s->vdr[vdr_rpu_id];
828 if (!use_prev_vdr_rpu) {
831 for (
int c = 0;
c < 3;
c++) {
850 for (
int c = 0;
c < 3;
c++) {
866 for (
int j = 0; j < curve->
mmr_order[
i]; j++) {
867 for (
int k = 0; k < 7; k++)
877 for (
int c = 0;
c < 3;
c++) {
890 memcpy(
s->vdr[vdr_rpu_id], mapping,
sizeof(*mapping));
893 if (vdr_dm_metadata_present) {
895 const int denom =
profile == 4 ? (1 << 30) : (1 << 28);
899 if (!dm_compression) {
900 for (
int i = 0;
i < 9;
i++)
902 for (
int i = 0;
i < 3;
i++)
904 for (
int i = 0;
i < 9;
i++)
925 for (
int i = 0;
i <
metadata->num_ext_blocks;
i++) {
932 if (num_ext_blocks_v2) {
935 for (
int i = 0;
i <
metadata->num_ext_blocks;
i++) {
948 for (
int i = 0;
i <
metadata->num_ext_blocks;
i++) {
952 else if (!dm_compression)
978 if (rpu_size > 0xFF) {
980 put_bits(pb, 8, (rpu_size >> 8) - 1);
1002 for (
int i = 0;
i < rpu_size;
i++) {
1004 if (
s->rpu_buf[
i] == 0) {
1010 if ((
s->rpu_buf[
i] & ~3) == 0) {
1014 zero_run =
s->rpu_buf[
i] == 0;
1016 *
dst++ =
s->rpu_buf[
i];
1022 *out_rpu =
s->rpu_buf;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
Public header for CRC hash function implementation.
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
const AVDOVIColorMetadata ff_dovi_color_default
int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)
Internal helper function to guess the correct DV profile for HEVC.
#define FF_DOVI_AUTOMATIC
Enable tri-state.
@ FF_DOVI_WRAP_NAL
wrap inside NAL RBSP
@ FF_DOVI_WRAP_T35
wrap inside T.35+EMDF
@ FF_DOVI_COMPRESS_RPU
enable compression for this RPU
static int ff_dovi_rpu_extension_is_static(int level)
static void put_se_coef(PutBitContext *pb, const AVDOVIRpuDataHeader *hdr, uint64_t coef)
int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, int flags, uint8_t **out_rpu, int *out_size)
Synthesize a Dolby Vision RPU reflecting the current state.
static int validate_ue_coef(const AVDOVIRpuDataHeader *hdr, uint64_t coef)
static void generate_ext_v2(PutBitContext *pb, const AVDOVIDmData *dm)
static int av_q2den(AVRational q, int den)
static void put_ue_coef(PutBitContext *pb, const AVDOVIRpuDataHeader *hdr, uint64_t coef)
static int validate_se_coef(const AVDOVIRpuDataHeader *hdr, int64_t coef)
static av_cold int dovi_configure_ext(DOVIContext *s, enum AVCodecID codec_id, const AVDOVIMetadata *metadata, enum AVDOVICompression compression, int strict_std_compliance, int width, int height, AVRational framerate, enum AVPixelFormat pix_format, enum AVColorSpace color_space, enum AVColorPrimaries color_primaries, enum AVColorTransferCharacteristic color_trc, AVPacketSideData **coded_side_data, int *nb_coded_side_data)
static int validate_se_golomb_value(int64_t value)
static void generate_ext_v1(PutBitContext *pb, const AVDOVIDmData *dm)
av_cold int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx)
Variant of ff_dovi_configure_from_codedpar which infers the codec parameters from an AVCodecContext.
static const struct @236203243050001075351004153163043221076053071107 dv_levels[]
static int validate_mapping_for_generation(const AVDOVIRpuDataHeader *hdr, const AVDOVIDataMapping *mapping)
static int cmp_dm_level0(const AVDOVIColorMetadata *dm1, const AVDOVIColorMetadata *dm2)
av_cold int ff_dovi_configure_from_codedpar(DOVIContext *s, AVCodecParameters *par, const AVDOVIMetadata *metadata, enum AVDOVICompression compression, int strict_std_compliance)
Configure the encoder for Dolby Vision encoding.
static int try_reuse_ext(DOVIExt *ext, const AVDOVIMetadata *metadata)
static int validate_ue_golomb_value(uint64_t value)
static void put_cie_xy(PutBitContext *pb, AVCIExy xy)
static CheckasmConfig cfg
AVCodecID
Identify the syntax and semantics of the bitstream.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static AVRational av_make_q(int num, int den)
Create an AVRational.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
#define ITU_T_T35_PROVIDER_CODE_DOLBY
#define ITU_T_T35_COUNTRY_CODE_US
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Macro definitions for various function/variable attributes.
#define FFSWAP(type, a, b)
Memory handling functions.
#define AV_PIX_FMT_YUV420P10
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
AVColorPrimaries
Chromaticity coordinates of the source primaries.
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AVCOL_PRI_BT2020
ITU-R BT2020.
AVColorTransferCharacteristic
Color Transfer Characteristic.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
@ AVCOL_TRC_BT709
also ITU-R BT1361
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_IPT_C2
SMPTE ST 2128, IPT-C2.
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void put_bits63(PutBitContext *s, int n, uint64_t value)
Write up to 63 bits into a bitstream.
static int put_bytes_output(const PutBitContext *s)
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
exp golomb vlc writing stuff
static void set_ue_golomb(PutBitContext *pb, int i)
write unsigned exp golomb code.
static void set_se_golomb(PutBitContext *pb, int i)
write signed exp golomb code.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
#define FF_ARRAY_ELEMS(a)
Struct containing chromaticity x and y values for the standard CIE 1931 chromaticity definition.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
This struct describes the properties of an encoded stream.
enum AVColorSpace color_space
int height
The height of the video frame in pixels.
int nb_coded_side_data
Amount of entries in coded_side_data.
int width
The width of the video frame in pixels.
AVRational framerate
Number of frames per second, for streams with constant frame durations.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
enum AVColorPrimaries color_primaries
enum AVColorTransferCharacteristic color_trc
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
AVWhitepointCoefficients wp
AVPrimaryCoefficients prim
Dolby Vision RPU data mapping parameters.
uint32_t num_x_partitions
uint8_t mapping_color_space
uint8_t mapping_chroma_format_idc
AVDOVIReshapingCurve curves[3]
enum AVDOVINLQMethod nlq_method_idc
uint32_t num_y_partitions
Dolby Vision metadata extension block.
uint8_t target_primary_index
AVColorPrimariesDesc target_display_primaries
uint8_t target_display_index
uint8_t reference_mode_flag
uint16_t trim_chroma_weight
uint16_t trim_saturation_gain
uint8_t target_display_index
uint16_t target_mid_contrast
uint8_t saturation_vector_field[6]
uint8_t hue_vector_field[6]
uint16_t trim_saturation_gain
uint16_t trim_chroma_weight
AVColorPrimariesDesc source_display_primaries
uint8_t source_primary_index
Coefficients of the non-linear inverse quantization.
uint64_t linear_deadzone_slope
uint64_t linear_deadzone_threshold
uint8_t poly_order[AV_DOVI_MAX_PIECES]
enum AVDOVIMappingMethod mapping_idc[AV_DOVI_MAX_PIECES]
int64_t mmr_constant[AV_DOVI_MAX_PIECES]
int64_t mmr_coef[AV_DOVI_MAX_PIECES][3][7]
int64_t poly_coef[AV_DOVI_MAX_PIECES][3]
uint16_t pivots[AV_DOVI_MAX_PIECES+1]
uint8_t mmr_order[AV_DOVI_MAX_PIECES]
Structure to hold side data for an AVFrame.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Rational number (pair of numerator and denominator).
AVDOVIDmData dm_static[7]
static extension blocks
AVDOVIDmData dm_dynamic[25]
dynamic extension blocks