1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00
Commit Graph

119908 Commits

Author SHA1 Message Date
778c0a48fa avcodec/mpegvideo_dec: Simplify check for unquantizing inter blocks
Just ensure that dct_unquantize_inter is set iff it is used
and check for the function pointer instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:53:32 +02:00
f2c04fd587 avcodec/mpegvideo_dec: Document which codecs take which codepath
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:52:57 +02:00
2e8a3e6645 avcodec/idctdsp: Only try to initialize xvid idct if it is used
This allows to remove checks from ff_xvid_idct_init()
(and also the AVCodecContext* parameter).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:50:34 +02:00
6349a3324d avcodec/xvididct: Remove always-true checks
ff_xvid_idct_init() is now only called from ff_idctdsp_init()
and only if idct_algo is FF_IDCT_XVID.
This also implies that it is unnecessary to initalize
the permutation on our own.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:50:23 +02:00
eb5d900f87 avcodec/mpeg4videodec: Remove unnecessary ff_xvid_idct_init()
It is unnecessary: If the dst context is not already initialized,
then it will be initialized by memcpy(dst, src, sizeof(*dst),
which already initializes the IDCT to the desired one, potentially
followed by ff_mpv_common_init(), which does not touch the IDCT.

(This call has been added in f89d76c10355242c39b08f253c1d1524f45ef778;
the aforementioned copying took place back then, too, but
ff_mpv_common_init() reinitialized the IDCT to a non-xvid one,
therefore the initialization here has been added to fix
multithreaded decoding.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:47:02 +02:00
6af1bcb180 avcodec/mpeg4videoenc: Use smaller scope for variable
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:46:56 +02:00
7267e4dab8 avcodec/mpeg4videoenc: Split writing blocks into intra and inter
These are sufficiently different to warrant their own functions;
in particular, the earlier code had two callsites for the actual
"write block" function, one for intra and one for inter, yet
the "write block" function nevertheless performed a check
(that the compiler can't optimize away) for whether the current
MB is intra or not.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:24:16 +02:00
f7bd2a5af8 avcodec/mpeg4videoenc: Remove no-output code
While it offers modest speedups compared to the ordinary code,
removing it completely offers even bigger speedups; and given
that these speedups also exist in the ordinary mode, they are
even more important. The no-output code has a 7.8% performance
improvement (based on benchmarking mpeg4_encode_mb()), yet
removing the no-output code resulted in a 9.4% improvement.

Furthermore, the no-output code was broken for the majority of
its existence (until 9207dc3b0d)
and no one complained, so it is likely not used at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:23:56 +02:00
2a59cb0c82 avcodec/mpeg4video: Nuke ff_mpeg4_init_rl_intra()
The MPEG-4 decoder can now initialize ff_mpeg4_rl_intra
directly given that the MPEG-4 encoder no longer wants
it performed, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:22:11 +02:00
d75a398d00 avcodec/mpeg4videoenc: Simplify creating LUT
There four cases for the LUT entry: An ordinary entry
or one of three escaping methods. Three of these methods
are only rarely possible --they correspond to the 102
codes of the underlying VLC and so only 102 of 16384 entries
are possible.

The earlier code would nevertheless try them all for every
LUT entry and use the best one; the new code meanwhile only
uses one method (the fallback one (i.e. the worst)) for them all
and only processes the 102 valid entries afterwards.

The implementation used also means that index_run, max_level
and max_run of the RLTable are no longer needed; the earlier
code would initialize said static tables although they are only
used for a short time to initialize something else.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:21:34 +02:00
295abb1fdc avcodec/mpegvideo_enc: Reduce stack usage
Multiple PutBitContexts are used when encoding partitioned
frames. When there are multiple candidates for macroblock types,
multiple states (namely the state before encoding the current MB,
the best state among the ones already tried and the current one)
need to be kept; duplicates of the PutBitContexts are among this
state. The temporary buffers for them are kept on the stack
in encode_thread() and their size is quite generous (MAX_MB_SIZE
- 3000 bytes). This commit uses tighter bounds, bringing the
size of the pb2 buffer down to 15 bytes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:02:58 +02:00
f887a2b006 avcodec/mpeg4videodec: Don't initialize unused parts of RLTables
The reversible VLC tables use a simpler escaping method
than the ordinary VLCs: It does not use max_run, max_level etc.
and therefore one does not need to initialize these at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:02:41 +02:00
a0a136e57b avcodec/h263dec: Move calculating gob_index to {intel,itu}h263dec.c
This avoids checks for whether it should be calculated at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:02:32 +02:00
9918741967 avcodec/mpegvideo_enc: Set gob_index once during init
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 04:00:08 +02:00
7ae20272b7 avcodec/pcm: Use av_unreachable() for unreachable code
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 03:38:37 +02:00
0d73ce4bc4 avcodec/h263dec: Use av_unreachable() for unreachable code
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 03:38:37 +02:00
ded08d0b1b avcodec/msmpeg4dec: Use av_unreachable() for unreachable code
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 03:38:37 +02:00
ef95a8d7b5 avcodec/mpegvideo_enc: Use av_unreachable() for unreachable code
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 03:38:37 +02:00
a5ff6ea32d avcodec/asvenc: Simplify writing extradata
It is confusing, because the AV_RL32("ASUS") already
returns an endian-independent value, so converting
it via av_le2ne32() makes no real sense: one would need
to transform the native value to le and write it as
a natie endian uint32_t for it to make sense (the current
code only works because le2ne32 and ne2le32 are the same
for both endianness that we care about). Or one can just
use AV_RL32 and create the number via MKTAG().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 03:37:09 +02:00
05a5e2b576 avcodec/asvenc: Combine writing bits
Removes implicit checks for "do I need to output the buffer now?".
Codesize with Clang 19 with -O3 decreased from 7136B to 6108B
(although asv2_put_level() is now inlined).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 03:37:09 +02:00
0401ca714a avcodec/asvenc: Don't waste bits encoding non-visible part
Up until now, the encoder replicated all the border pixels
for incomplete 16x16 macroblocks. In case the available width
or height is <= 8, some of the luma blocks of the MB
do not correspond to actual input, so that we should encode
them using the least amount of bits. Zeroing the block coefficients
(as this commit does) achieves this, replicating the pixels
and performing an FDCT does not.

This commit also removes the frame copying code for insufficiently
aligned dimensions.

The vsynth3-asv[12] FATE tests use a 34x34 input file and are
therefore affected by this. As the ref updates show, the size
and checksum of the encoded changes, yet the decoded output
stays the same.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-26 03:37:09 +02:00
ae0f71a387 lavc/h2645_parse: More descriptive NALU header error
Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-05-25 09:54:42 +08:00
0382291811 lavc/vvc: Fix divide-by-zero in LMCS param derivation
Add three missing requirements on bitstream conformance from 7.4.3.19 of
H.266 (V3).  Issue found using fuzzing.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-05-25 09:35:21 +08:00
670089304a lavc/vvc: Avoid UB in DB strength derivation for PLT CUs
When called for palette-predicted CUs, boundary_strength could cause
undefined behaviour due to accessing uninitialised motion information.
The spec doesn't include this, but in the reference software it seems
the deblock strength is always set to 0 for palette CUs due to some
implementation details: perhaps this is a spec issue?

Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-05-24 21:50:46 +08:00
a18b2c2696 lavc/vvc: Detect subpic overlaps at CTU level
In d5dbcc00d8, it was hoped that detection
of subpicture overlaps could be performed at the tile level, so as to
avoid introducing per-CTU checks. Unfortunately since that patch,
fuzzing has indicated there are some structures involving
pps_subpic_one_or_more_tiles_slice where tile-level checking is not
sufficient.  Performing the check at the CTU level should (touch wood)
be the be-all and and-all of this, as CTUs are the lowest common
denominator of the picture partitioning.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-05-24 10:57:20 +08:00
363a7a34f6 lavc/vvc/plt: validate run and signalled_entries
Fixes a crash triggered by a fuzzed clip:
https://github.com/ffvvc/tests/tree/main/fuzz/passed/000256.bit

Reproduce with:
ffmpeg -i 000256.bit -f null -
2025-05-24 10:36:19 +08:00
cbdb5e2477 ffv1enc_vulkan: fix array overflow 2025-05-24 02:28:13 +09:00
56b85b689d aacdec_ac: fix signed overflow in ff_aac_ac_update_context()
The issue is that state->cur[] is 8-bits, but a+b+1 can overflow
before being clipped to 0xF in the following line, causing an incorrect
state to be saved for the next symbol.

This solves numerous bitstream desyncs, particularly when coefficients
with magnitude greater than 127 are sent.
2025-05-24 02:19:18 +09:00
8c509ba491 tests/fate/ac3: Make ac3-fixed-encode-2 bitexact across arches
Don't use a 7.1 EAC3 input file for which our decoder is not
bitexact; instead just use the asynth-44100-8.wav file
which (as a 7.1 file) exhibits the same issue fixed by
1b3f4842c1.
(Either the encoder or the resampler are still not completely
bitexact, so we limit the number of frames output.)

Also switch to a framecrc test so that the output channel layout
is directly contained in the ref file.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-23 14:06:26 +02:00
559317cc13 avfilter/vf_libplacebo: add shader_cache option
Useful to speed up shader compilation. May significantly lower startup
times, in particular with large or complex shaders.

Sponsored-by: nxtedition
2025-05-23 14:05:16 +02:00
4f623b4c59 avfilter/vf_libplacebo: implement rotation option
Flipping can already be accomplished by setting the crop_w/h expressions to
their negative values, so together these options can implement any of the
common frame orientations.
2025-05-23 14:02:45 +02:00
a79720e10f avformat/matroskadec: Accept WebVTT subtitles with empty cues
Fixes: #11493
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-23 00:43:33 +02:00
9c6c653a46 avformat/imfdec: inherit opaque from parent AVFormatContext
io_open and io_close2 callbacks may use opaque pointer stored in the
context. They are already inherited, so opaque should also be passed
through.

Fixes IMF playback in mpv.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
Reviewed-by: Pierre-Anthony Lemieux <pal@sandflow.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-23 00:43:32 +02:00
622a72b5ea tests/fate/ac3: add a second ac3_fixed encoder test
Exercising the lavfi filtergraph codepath to choose the best output layout.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-22 19:38:26 -03:00
1b3f4842c1 avfilter/avfiltergraph: fix regression in picking channel layout
Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-22 19:38:11 -03:00
8eae65dc5c avcodec/lcevcdec: don't try to write to output frames directly
The buffer references may not be writable at this point, as the decoder
calls get_buffer2() with the AV_GET_BUFFER_FLAG_REF flag.

Fixes races as reported by tsan, producing correct output regardless of
threading choices.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-22 19:28:35 -03:00
d028cf03b8 swscale/swscale_unscaled: fix planarRgbToplanarRgbWrapper() for formats with bpc between 9-14 bits
Currently, planarRgbToplanarRgbWrapper() always sets the alpha value to 255,
without taking the bit depth into consideration.

This commit restricts the alpha value to the bit depth.
2025-05-23 00:07:56 +02:00
748e960e04 swscale/swscale_unscaled: fix packed16togbra16() for formats with bpc between 9-14 bits
Currently, packed16togbra16() always sets the alpha value to 0xFFFF,
without taking the bit depth into consideration.

This causes a bug on x86, which can be reproduced with:
./libswscale/tests/swscale -unscaled 1 -src xyz12le -dst gbrap12be

The problem arises in ff_hscale14to15_4_ssse3(), in the conversion
from gbrap12be to yuva444p, which comes after the conversion from
xyz12le to gbrap12be.

It has something to do with pmaddwd not working on unsigned values.
There is some code to deal with 0xFFFF if the input has a bit depth of
16, but not for bit depths < 16.
We could fix ff_hscale14to15_4_ssse3() to also work correctly with
0xFFFF on bit depths < 16, or we could just not write 0xFFFF there in
the first place, which is what this commit does.
2025-05-23 00:01:04 +02:00
0c1d87d1e6 swscale/swscale_unscaled: fix packed30togbra10() for formats with bpc between 9-14 bits
Currently, packed30togbra10() always sets the alpha value to 0xFFFF,
without taking the bit depth into consideration.

This commit restricts the alpha value to the bit depth.
2025-05-23 00:00:05 +02:00
a16c053a33 swscale/swscale_unscaled: fix planarCopyWrapper() for yuv444p => yuva444p
Currently, planarCopyWrapper() assumes that src[3] must be NULL when
the source format has no alpha plane.

This commit updates the condition for filling the alpha plane based on
the number of components available in the source format as well.
2025-05-22 23:59:39 +02:00
db5e0e2ef9 build: remove unused SLIBOBJS variable
The SLIBOBJS variable was introduced in 56572787ae but is no longer used.
Another variable, SHLIBOBJS, was introduced after SLIBOBJS, in 20b0d24c2f.
The functionality from SLIBOBJS was effectively migrated to SHLIBOBJS in b77fff47d0.

No code has used SLIBOBJS since.

This commit removes all remaining references to SLIBOBJS from the build system.
2025-05-22 23:59:03 +02:00
9b9a287872 doc/examples/qsv_decode: use av_err2str
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
2025-05-22 22:26:30 +02:00
e93a43b511 doc/examples/filter_audio: use av_err2str
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
2025-05-22 22:26:30 +02:00
977d1a24bc vulkan/ffv1: fix sync issue in cached bitstream reader/writer
The issue is that there is an explicit lack of synchronization as only the very
first invocation writes symbols and updates the state, which other invocations
then store.
2025-05-23 05:23:44 +09:00
b9b44e15b5 rtpdec: Set bitrate for pcm-mulaw audio
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
Co-authored-by: Marvin Scholz <epirat07@gmail.com>
2025-05-22 22:11:37 +02:00
f566392f66 libavformat/rtpdec_opus: add fmtp parsing of sprop-maxcapturerate
Co-authored-by: Marvin Scholz <epirat07@gmail.com>
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
2025-05-22 22:11:37 +02:00
2a180c7150 libavformat/rtpdec_opus: Set duration field on Opus AVPacket
This commit will properly set the duration field of Opus AVPackets.
Currently, duration is set to 0 on Opus packets from the RTP demuxer.

The Ogg muxer depends on the duration field to properly compute the page granule
value. Without a proper duration, the granule will be wrong, and result in
negative pts values in ogg files.

See oggenc.c:657 (ogg_write_packet_internal)

This commit calculates using the opus_duration function, which was copied
from oggparseopus.c

I moved this functionality and the existing opus extradata functionality
(added by me in 6c24f2b) into a new rtpdec_opus.c file.

Reviewed-by: Tristan Matthews <tmatth@videolan.org>
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
2025-05-22 22:10:46 +02:00
36ec9217e6 avformat/dhav: fix backward scanning for get_duration and optimize seeking
The backwards scanning done for incomplete final packets should not
assume a specific alignment at the end of the file. Truncated files
result in hundreds of thousands of seeks if the final packet does not
fall on a specific byte boundary, which can be extremely slow.
For example, with HTTP, each backwards seek results in a separate
HTTP request.

This changes the scanning to check for the end tag 1 byte at a time
and buffers the last 1 MiB to avoid additional seek operations.

Co-authored-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Justin Ruggles <justinr@vimeo.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2025-05-22 16:11:16 +01:00
c8b09fb0ac avutil/refstruct: Remove redundant check
We now require C11.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-22 15:12:54 +02:00
4099d53759 avfilter/vf_interlace_vulkan: fix FPS and PTS calculation
ol->frame_rate is 0/0, so we need to calcalute the correct value based on
the il->frame_rate instead. Also adjust the time base, PTS and frame_duration
values accordingly. (Logic taken from vf_tinterlace.c)
2025-05-21 16:10:55 +02:00