Commit Graph

52676 Commits

Author SHA1 Message Date
Niklas Haas
65580592c9 avcodec/jpegxl: parse and signal correct alpha mode
This header bit ("alpha_associated") was incorrectly ignored.
2025-09-02 17:06:25 +02:00
Niklas Haas
51572ff08a avcodec/libjxlenc: also attach extra channel info
Works around a bug where older versions of libjxl don't correctly forward
the alpha channel information to the extra channel info.
2025-09-02 17:06:25 +02:00
Niklas Haas
a88cc0a53e avcodec/libjxl: set correct alpha mode
JPEG XL supports both premultiplied and straight alpha, and the basic info
struct contains signalling for this. Forward the correct tagging on decode
and encode.
2025-09-02 17:06:25 +02:00
Niklas Haas
702a5ac29b avcodec/exr: set correct alpha mode
OpenEXR always uses premultiplied alpha, as per the spec.

cf. https://openexr.com/en/latest/TechnicalIntroduction.html

> By convention, all color channels are premultiplied by alpha, so that
> `foreground + (1-alpha) x background` performs a correct “over” operation.
> (See Premultiplied vs. Un-Premultiplied Color Channels)
>
> In the visual effects industry premultiplied color channels are the norm,
> and application software packages typically use internal image
> representations that are also premultiplied.
2025-09-02 17:06:25 +02:00
Niklas Haas
d6ce720765 avcodec/png: set correct alpha mode
PNG always uses straight alpha.

cf. https://www.w3.org/TR/PNG-Rationale.html

> Although each form of alpha storage has its advantages, we did not want to
> require all PNG viewers to handle both forms. We standardized on non-
> premultiplied alpha as being the lossless and more general case.
2025-09-02 17:06:25 +02:00
Niklas Haas
02d531ca05 avcodec/encode: enforce alpha mode compatibility at encode time
Error out if trying to encode frames with an incompatible alpha mode.
2025-09-02 17:06:25 +02:00
Niklas Haas
ecebf9c693 avcodec/avcodec: add AVCodecContext.alpha_mode
Following in the footsteps of the previous commit, this commit adds the
new fields to AVCodecContext so we can start properly setting it on codecs,
as well as limiting the list of supported options to detect a format mismatch
during encode.

This commit also sets up the necessary infrastructure to start using the
newly added field in all codecs.
2025-09-02 17:06:24 +02:00
Nicolas Gaullier
f24474dcfc avcodec/aac_ac3_parser: do not override the profile set by the decoder
Parsing the ADTS header is not enough to detect HE-AAC v1/v2.

Regression since 64bb91fd3b.

Fixes #11600

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-09-02 16:05:46 +02:00
Nicolas Gaullier
593b426902 avcodec/aac_ac3_parser: simplify
Use ff_adts_header_parse_buf() wrapper to simplify as GetBitContext is
no longer needed (it was introduced for USAC).

Partially reverts 64bb91fd3b.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-09-02 16:05:46 +02:00
Nicolas Gaullier
9bd10fa32c avcodec/aac_ac3_parser: remove unused USAC/ADTS code
ff_adts_header_parse() parse the object_type from a 2 bits field.
See also 696ea1c223.

Partially reverts 64bb91fd3b.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-09-02 16:05:46 +02:00
Maryla Ustarroz-Calonge
a282500087 avcodec/libaom: Add HDR10+ metadata support
Signed-off-by: Maryla Ustarroz-Calonge <maryla@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-09-02 15:56:56 +02:00
James Almer
9dc79241d9 avcodec/decode: always extract display matrix from Exif in frames
Should help ensure no conflicting values are propagated.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 12:08:04 -03:00
James Almer
6a15183e6a avcodec/decode: parse Exif packet side data before passing it to frames
Extract Orientation and export it as a display matrix if present, and set the
frame's metadata with the remaining Exif entries.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 12:07:59 -03:00
James Almer
fa1938c574 avcodec/decode: use ff_frame_new_side_data() to export Exif side data
Otherwise, the user requested priority of packet side data will be ignored.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 12:07:41 -03:00
James Almer
75bd5056a4 avcodec/decode: use av_exif_get_tag_id() where useful
Removes dependency on exif_internal.h

Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 12:07:41 -03:00
James Almer
4ffd621523 avcodec/packet: add an Exif side data type
Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 12:07:07 -03:00
James Almer
45dcfb2d60 avcodec/version_major: remove unnecessary define for an internal function
It being avpriv and not public, it can be removed in the next bump regardless of when it
happens.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 11:00:44 -03:00
Henrik Gramner
a66a260ae9 vp9: Add 8bpc intra prediction AVX2 asm 2025-09-01 13:54:52 +00:00
Cameron Gutman
126671e730 avcodec/mfenc: add AVLowLatencyMode support
Set CODECAPI_AVLowLatencyMode when AV_CODEC_FLAG_LOW_DELAY is enabled on
the AVCodecContext. AVLowLatencyMode can acheive lower latency encoding
that may not be accessible using eAVScenarioInfo options alone.

Signed-off-by: Cameron Gutman <aicommander@gmail.com>
2025-09-01 12:40:36 +00:00
Martin Storsjö
3ea6c2fe25 aacencdsp: Improve consistency with assembly, for x87 math
Currently, the aacencdsp checkasm tests fails for many seeds,
if the C code has been built with x87 math. This happens because
the excess precision of x87 math can make it end up rounding
to a different integer, and the checkasm tests checks that the
output integers match exactly between C and assembly.

One such failing case is "tests/checkasm/checkasm --test=aacencdsp
41" when compiled with GCC. When compiled with Clang, the test
seed 21 produces a failure.

To avoid the issue, we need to limit the precision of intermediates
to their nominal float range, matching the assembly implementations.

This can be achieved when compiling with GCC, by just adding a single
cast.

To observe the effect of this cast, compile the following
snippet,

    int cast(float a, float b) {
        return (int)
    #ifdef CAST
            (float)
    #endif
            (a + b);
    }

with "gcc -m32 -std=c17 -O2", with/without -DCAST. For x86_64
cases (without the "-m32"), the cast doesn't make any difference
on the generated code.

This cast would seem to not have any effect, as a binary expression
with float inputs also would have the type float.

However, if compiling with GCC with -fexcess-precision=standard,
the cast forces limiting the precision according to the language
standard here - according to the GCC docs [1]:

> When compiling C or C++, if -fexcess-precision=standard is
> specified then excess precision follows the rules specified in
> ISO C99 or C++; in particular, both casts and assignments cause
> values to be rounded to their semantic types (whereas -ffloat-store
> only affects assignments). This option is enabled by default for
> C or C++ if a strict conformance option such as -std=c99 or
> -std=c++17 is used.

Ffmpeg's configure scripts enables -std=c17 by default.

This only helps with GCC though - the cast doesn't make any
difference for Clang. (Although, upstream Clang seems to default
to SSE math, while Ubuntu provided Clang defaults to x87 math.)
Limiting the precision with Clang would require casting to volatile
float for both intermediates here - and that does have a code
generation effect on all architectures.

[1] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
2025-09-01 09:22:39 +00:00
Cameron Gutman
b2910ec92e avcodec/mfenc: fix memory leak with D3D11 input surfaces
Fixes: d56522c6eb ("avcodec/mfenc: add support for D3D11 input surfaces")
Signed-off-by: Cameron Gutman <aicommander@gmail.com>
2025-08-31 14:36:20 -05:00
YiboFang
ae448e00af avcodec/pcm: use compile-time guards for PCM table init
Change the PCM table init to use compile-time #if instead of a runtime
`if (CONFIG_...)`. This makes sure code for disabled encoders never gets
built, without depending on compiler dead-code elimination.

Signed-off-by: YiboFang <fangyibo@xiaomi.com>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-08-31 21:40:29 +08:00
Gyan Doshi
f317b6c052 lavc/codec_desc: add lossless flags for hevc and av1
Both codecs support a lossless mode akin to H.264/AVC
2025-08-31 16:48:03 +05:30
Tong Wu
9893d66add avcodec/d3d12va_encode: add max_frame_size option
Add the max_frame_size option to support setting max frame size in
bytes. Max frame size is the maximum cap in the bitrate algorithm per
each encoded frame.

Signed-off-by: Tong Wu <wutong1208@outlook.com>
2025-08-31 10:46:11 +00:00
Peter Ross
16d32a1c1d libavcodec/dpxenc: map AVCodecContext color transfer and color primaries fields 2025-08-31 07:05:36 +00:00
Peter Ross
6d7daaab0a avcodec/dpx: move enum DPX_TRC and DPX_COL_SPEC to dpx.h 2025-08-31 07:05:36 +00:00
James Almer
2fffa01ddb avcodec/x86/vp9dsp_init: remove preprocessor checks for some prototypes
Fixes compilation with --disable-avx512icl

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-29 14:02:49 -03:00
Nicolas Gaullier
7252f6c0bf avcodec/version: update the codec_ids
The counters should be incremented for each new codec.
Catch-up to be in sync with codec_id.h again.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
2025-08-29 17:32:52 +02:00
Daniil Cherednik
0828a3b636 avcodec/atrac3: fix inconsistent band num calculation
'decode_spectrum' reads 5 bits from bitstream to get
number of encoded subbands – so 31 means all 32
subbands are encoded. This value also is used to
determinate the number of used band in the hybrid
filterbank.

'subband_tab' array contains 33 values of MDCT spec
line positions started from 0 line and used to map
subband number in to the range of mdct lines.

Since the subband_num returned by decode_spectrum
actually is number – 1 and subband_tab started from 0
we need to add 1 to make num_bands calculation correct.
2025-08-29 12:29:52 +00:00
Henrik Gramner
10a061ba99 vp9: Add AVX-512ICL asm for 8bpc subpel mc 2025-08-28 12:45:52 +00:00
Michael Niedermayer
76645e096f avcodec/exif: also copy zero termination for AV_TIFF_STRING
Fixes: out of array read
Fixes: 441131173/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_DEC_fuzzer-6700429212975104

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-08-27 15:46:35 +00:00
Leo Izen
041651841a avcodec/libjxlenc: fix leaked EXIF ifd
We're missing a call to av_exif_free here. We leak the internal heap-
allocated objects when &ifd goes out of scope.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-27 05:28:31 -04:00
Leo Izen
a8d6b87a44 avcodec/libjxldec: fix leaked EXIF ifd
We're missing a call to av_exif_free here. We leak the internal heap-
allocated objects when &ifd goes out of scope.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-27 05:26:03 -04:00
Raphaël Zumer
ae14930176 avcodec/webp: simplify special-case handling when building Huffman reader
Signed-off-by: Raphaël Zumer <rzumer@tebako.net>
2025-08-26 14:42:47 +00:00
Raphaël Zumer
d1a7a20cb1 avcodec/webp: fix incorrectly returning AVERROR_INVALIDDATA when building Huffman reader
This corrects an error in commit c33f16d.

Signed-off-by: Raphaël Zumer <rzumer@tebako.net>
2025-08-26 14:42:47 +00:00
James Almer
fa23202cc7 configure: bump LCEVCdec minimum required version to 4.0.0
The project introduced API breaking changes to some of their public functions,
and given the library is relatively new, just bump the minimum supported
version instead of adding ifdeffery to the source files.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-25 10:43:23 -03:00
Leo Izen
ef9fe0fe0b avcodec/exif: avoid allocation failure on empty EXIF metadata
An EXIF IFD with 0 entries is legal, but does not contain metadata. We
should not attempt to allocate a struct with size zero in this case, as
this causes an allocation failure. Instead, we just leave the struct
empty.

Fixes: #20305.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-24 20:20:10 +00:00
Leo Izen
2398fddf6e avcodec/exif: avoid writing native-endian EXIF buffers
Currently there's platform-dependent behavior where if no endianness
is requested, it writes the buffers in native-endian. This breaks FATE
tests on big-endian architecture. This commit changes the default to
little-endian buffers upon writing.

Fixes: #20291.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-24 20:20:10 +00:00
James Almer
368b5e0ffc avcodec/exif: make the get and remove helpers take a flags argument as input
This makes the functions extensible, as future behavior change flags can be
introduced.

This is strictly speaking not an API break. Only if a user was setting
recursive to anything other than 1 it would now behave differently, but given
these functions have been in the tree for only a few days, the chances for that
are practically zero.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-24 12:34:15 +00:00
Frank Plowman
673f28b6cb lavc/Makefile: Make exif.o compulsory
av_exif_* functions are part of libavcodec's public API since
ad77345a5d, so the EXIF objects can't
be disabled.

Fixes compilation with --disable-everything.
2025-08-22 22:44:07 +00:00
James Almer
5ed1d72792 avcodec/decode: remove Exif Orientation tag after adding it as display matrix
Don't replace it with a conflicting value.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-21 22:48:16 +00:00
James Almer
5a9e5d8031 avcodec/exif: use ff_frame_new_side_data() to export display matrix
Otherwise, the user requested priority of packet side data will be ignored.
For this, move the relevant functions to decode.c, as they need access to an
AVCodecContext.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-21 22:48:16 +00:00
Manuel Lauss
d311382c38 avcodec/sanm: fix issues with FTCH offset hack
Just add an extra x/y offset parameter pair to process_frame_obj(),
and store the size of the data to FTCH in a separate context member.
The only valid sizes for FTCH are 6 and 12, reject any other.
Finally, if a FOBJ uses codecs37 and above, enforce it to be subversion 2,
to use the simpler STOR/FTCH method.

Fixes BIGSLEEP-440183164/process_ftch.anim

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-08-21 21:02:40 +00:00
Michael Niedermayer
c41a70b6bb avcodec/sanm: Eliminate reference into reallocated frame
AFAIK the original decoder uses the frame buffers in very strange ways
our implementation seems to mimic that and that results in the
bitstream input to point into a frame buffer while code then
parses that and potentially reallocates the frame buffer
leaving pointers hanging into dealllocated space

This simply uses a temporary buffer

Fixes: Writing into freed buffers
Fixes: BIGSLEEP-440183164/old_codec21.anim
Fixes: BIGSLEEP-440183164/old_codec4.anim

Found-by: Google Big Sleep

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-08-21 21:02:40 +00:00
Michael Niedermayer
d4e28917af avcodec/sanm: Replace impossible bitstream check by assert
the space left and size have already been cross checked by the caller

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-08-21 21:02:40 +00:00
Leo Izen
7caa2a65d9 avcodec/exif: fix some coverity errors
This commit fixes some memory and security issues due to improper
sanitizing and checks.

Fixes:
 - CID 1665100..1665107

Signed-off-by: Leo Izen <leo.izen@gmail.com>
Reportedy-by: James Almer <jamrial@gmail.com>
2025-08-21 15:40:45 -04:00
Manuel Lauss
d4eb01f281 avcodec/sanm: handle xpal cmd 0
It's like cmd 2. Fixes the Rebel Assault 1 Intro Video "C1BLOCK.ANM"
crossfade from planet view to space view and subsequent wrong colors.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-08-21 16:24:26 +00:00
James Almer
d151d3aecb avcodec/exif: don't expose a private function in an installed header
And it doesn't need an entry in APIChanges, given it's not public API.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-20 10:44:12 -03:00
Zhao Zhili
b8856c5fc5 avcodec/hevc: Fix invalid null pointer check
c5287178b4 added a null pointer check, but checked the wrong
variable. &s->cur_frame->f->data[c_idx] cannot be null.
2025-08-20 11:52:32 +00:00
Manuel Lauss
990edfee5b libavcodec/vima: reindent
Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-08-20 11:20:14 +02:00