1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-02-04 06:08:26 +02:00

12 Commits

Author SHA1 Message Date
Cosmin Stejerean
0c0e7ec81e avcodec/dovi_rpu: correctly read el_bit_depth_minus8 and ext_mapping_idc
These two fields are coded together into a single 16 bit integer with upper 8
bits for ext_mapping_idc and lower 8 bits for el_bit_depth_minus8.

Furthermore ext_mapping_idc has two components, upper 3 bits and lower 5 bits.

Co-authored-by: Niklas Haas <git@haasn.dev>
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-06-22 15:48:25 +02:00
Niklas Haas
d9f902d3a4 avcodec/dovi_rpu: guard ext blocks by dm_metadata_present
In the spec, dm_metadata_present also toggles all extension blocks, so
we need to move them inside the branch.
2024-06-18 21:18:30 +02:00
Niklas Haas
7bf08a5b2d avcodec/dovi_rpu: simplify vdr type
Storing the color metadata alongside the data mapping is no longer
needed, so we can simplify this array's type.
2024-06-18 21:18:30 +02:00
Niklas Haas
7ee64631f6 avcodec/dovi_rpu: fix dm_metadata_id handling
Despite the suggestive size limits, this metadata ID has nothing to do
with the VDR metadata ID used for the data mappings. Actually, the
specification leaves them wholly unexplained, other than acknowleding
their existence. Must be some secret dolby sauce. They're not even
involved in DM metadata compression, which is handled using an entirely
separate ID.

That leaves us with a lack of anything sensible to do with these IDs.
Since we unfortunately only expose one `dm_metadata_id` field to the
user, just ensure that they match; which appears to always be the case
in practice. If somebody ever hits this error, I would really much
rather like to see the triggering file.
2024-06-18 21:18:30 +02:00
Niklas Haas
68a22ac936 avcodec/dovi_rpu: properly handle vdr_dm_metadata_present
When this is 0, the metadata is explicitly inferred to stated default
values from the spec, rather than inferred from the previous frame's
values.

Likewise, when encoding, instead of checking if the value changed since
the last frame, we need to check if it differs from the default.
2024-06-18 21:18:30 +02:00
Niklas Haas
6225ad5c19 avcodec/dovi_rpu{enc,dec}: fix ms_weight handling
The code as written was wrong. In the spec, these fields are treated
merely as plain integers in the range 0 to 4095. The only difference
between L2 and L8 is that L2.ms_weight also accepts an additional value
of -1, hence the extra sign bit. While it's likely that these are still
shifted integers in disguise, since all real-world samples seem to use
a value of 2048 here, the offset used in the code was wrong.

In addition, because the l8.ms_weight struct member is unsigned, these
wrong shifting semantics ended up overflowing the field, leading to
undefined behavior when transcoding. Fortunately, the damage was
relatively contained in practice, because it just corrupts the coding of
this field, which is ignored in practice in all implementations I have
seen.
2024-06-14 13:43:55 +02:00
Michael Niedermayer
73d6d9f129
avcodec/dovi_rpuenc: fix compaatibility
Fixes: a frequency
Found while reviewing: CID1596607

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-13 03:40:18 +02:00
Michael Niedermayer
46ad68084e
avcodec/dovi_rpuenc: initialize profile
Code is taken from dovi_rpudec

Fixes: CID1596604 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-13 03:40:18 +02:00
Michael Niedermayer
c7075cdb67
avcodec/dovi_rpuenc: Initialize bl_compat_id
Fixes: CID1596607 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-06 03:00:40 +02:00
Niklas Haas
1d89de03d6 avcodec/dovi_rpuenc: avoid division by zero
Fixes: https://trac.ffmpeg.org/ticket/10985
2024-04-30 21:35:42 +02:00
Niklas Haas
3306766608 avcodec/dovi_rpuenc: add ff_dovi_rpu_generate()
This function takes a decoded AVDOVIMetadata struct and turns it back
into a binary RPU. Verified using existing tools, and matches the
bitstream in official reference files.

I decided to just roll the EMDF and NAL encapsulation into this function
because the end user will need to do it otherwise anyways.
2024-04-22 12:17:56 +02:00
Niklas Haas
f140935005 avcodec/dovi_rpuenc: add ff_dovi_configure()
We need to set up the configuration struct appropriately based on the
codec type, colorspace metadata, and presence/absence of an EL (though,
we currently don't support an EL).

When present, we use the signalled RPU data header to help infer (and
validate) the right values.

Behavior can be controlled by a new DOVIContext.enable flag.
2024-04-22 12:17:51 +02:00