95 Commits
Author SHA1 Message Date
Michael Niedermayer 0747459f0c avcodec/bsf/lcevc_metadata: write the VUI into the NAL unit holding the global config
Fixes: u1TxsBfg36kp/testcase/two_b.mp4 / gen_au.py gen_mp4.py
Fixes: u1TxsBfg36kp
Fixes: AISLE-2026-0150-00084
Fixes: assertion failure
Assertion failure Replicated through UnModified FFmpeg

Found-by: Joshua Rogers (AISLE)

The report suggested returning the NAL unit together with the found
block and inserting into its list, and replacing the assertion by a
runtime check.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-11-06 04:40:30 +00:00
Michael Niedermayer c90bbc2036 avcodec/bsf/av1_frame_merge: limit the number of OBUs buffered per temporal unit
Fixes: bdTY8jUuDHwF
Fixes: AISLE-2026-0150-00241
Fixes: OOM
OOM Replicated through UnModified FFmpeg with /usr/bin/time (peak RSS)

Found-by: Joshua Rogers <joshua.rogers@aisle.com>
2026-11-03 16:12:58 +00:00
Michael Niedermayer d8013c0617 avcodec/bsf/dts2pts: reject packets with more than two H.264 pictures
Fixes: iYUViL6T5SOa
Fixes: AISLE-2026-0150-00073
Fixes: Timeout
Timeout Replicated through UnModified FFmpeg with /usr/bin/time

Found-by: Joshua Rogers <joshua.rogers@aisle.com>
2026-11-03 16:12:58 +00:00
Michael Niedermayer 3b1cbb5e0f avcodec/bsf/aac_adtstoasc: check the bit reader initialization before the PCE
Fixes: RG0je5bJzuAD
Fixes: AISLE-2026-0150-00525
Fixes: NULL pointer dereference
NULL pointer dereference Replicated through UnModified FFmpeg with ASAN and UBSAN

Found-by: Joshua Rogers <joshua.rogers@aisle.com>
2026-11-03 16:12:58 +00:00
Michael Niedermayer 11052ca4b0 avcodec/bsf/pcm_rechunk: reject channel counts that overflow the sample size
Fixes: Zc8wjsgxLWvu
Fixes: AISLE-2026-0150-00562
Fixes: signed integer overflow, division by zero
Division by zero Replicated through UnModified FFmpeg with ASAN and UBSAN

Found-by: Joshua Rogers <joshua.rogers@aisle.com>
2026-11-03 16:12:58 +00:00
Michael Niedermayer 8828574c98 avcodec/bsf/dovi_split: reject NAL units that do not fit the output length field
Truncated length field Replicated through UnModified FFmpeg

Found by a grok bot based audit of the code.
2026-10-31 13:49:30 +00:00
Romain Beauxis 368aee9d25 avcodec/bsf: add the side_data bitstream filter
Add a filter that removes side data of the given types from packets and from
the stream, or keeps only the packets carrying side data of any of the given
types, as the select mode of the sidedata frame filter does for frames, but
with a list of types. The types are named by their handle, as option
constants joined with '+'.
2026-10-23 14:04:24 +00:00
James Almer 94cba3150c avcodec/bsf/jpegapp: use an AVOption of binary type for the sidecar
Opening a file for this is hacky and the tests added for it are broken on Windows.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-10-17 15:49:47 -03:00
Reinhard NißlandCursor 955276412d avcodec/bsf: add jpegapp to inject JPEG APP segments
Inject APP0..APP15 segments from a length-prefixed sidecar into each
MJPEG packet after SOI. A zero-length record passes the packet through.
An APP1-only payload retains the existing APP0; a payload starting with
APP0 replaces an APP0 located immediately after SOI.

Consume records in packet arrival order, with a 16 MiB record limit.
Missing or invalid records return an error. Remember sidecar read and
validation errors so later packets cannot consume a rejected record's
payload as metadata. Flushing neither rewinds the sidecar nor clears
this error; closing the context does not read ahead.

Count every consumed input packet in diagnostics, distinguish I/O errors
from truncated records, include the open error text for a sidecar that
cannot be opened, and document the sidecar and lifecycle contract.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Reinhard Nißl <rnissl@gmx.de>
Assisted-by: Fairy
2026-10-14 20:43:13 +00:00
Mark Thompson ebfc9497f7 apv_metadata: Add delete_filler option
Deletes all filler bytes in the stream:
- Filler PBUs.
- Filler at end of frame PBUs.
- Dummy bytes trailing in tile data.
- Filler at end of AU info PBUs.
- Filler at end of metadata PBUs.
- Filler metadata payloads.
2026-10-13 21:16:28 +01:00
Jun Zhao 6931e21b7e avcodec/hevc_mp4toannexb: avoid duplicating parameter sets when present in-band
When an input packet already contains in-band VPS/SPS/PPS parameter sets,
hevc_mp4toannexb still prepended extradata parameter sets before IRAP NALUs,
causing duplicate parameter sets at keyframes.

Avoid duplication by indexing extradata parameter sets in a hash table and
checking in-band parameter sets against it, suppressing any extradata
parameter set whose payload is already present in-band. Declarative SEIs
from extradata are always preserved. Packet-side matching attempts are
bounded to prevent CPU amplification, and redundant linear scans are
pruned with an emitted_types mask. Topological ordering dependencies
(e.g. PPS after SPS, and Prefix SEI barrier before pending parameter sets)
are strictly preserved.

Extradata is parsed in two passes with a single allocation, capping the
total number of NAL units to prevent memory amplification from malformed inputs.

Update the fate-hevc-bsf-mp4toannexb test reference accordingly.

Fixes: ticket #24637
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2026-10-04 08:09:26 +08:00
Romain Beauxis 3a165c77dc bsf: add trim filter.
Drop packets outside a range given as a pts, dts, packet index, millisecond or
duration bound, trimming a packet that straddles a boundary through skip
samples side data for audio and shifted timestamps otherwise.

Set preroll to export the packets a decoder needs to start on a cut made inside
a group of pictures, flagged for discard so the frames it produces still begin
at the bound.
2026-09-10 18:23:50 +00:00
James Almer 7dc71230a9 avcodec/bsf/dca_core: clear profile value on init()
The output stream no longer has extension sub-streams, so the
declared input profile, if it was set, is no longer valid.

Fixes issue #24388.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-09-06 18:17:13 -03:00
Kenan Alghythee 534f16d866 avcodec/bsf/dovi_rpu: handle update_rpu() returning no RPU
Fixes: out of array access
Fixes: SUcVEyk7r3Gc
Found-by: Kenan Alghythee <kalghy2@uic.edu>
2026-07-31 04:00:56 +00:00
James Almer 86940d45af avcodec/bsf/truehd_core: clear profile value on init()
The output stream no longer has Atmos metadata, so the
AV_PROFILE_TRUEHD_ATMOS profile, if it was set, is no longer valid.

Fixes issue #23195.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-07-30 13:19:39 +00:00
James Almer c77c0e580a avcodec/bsf/eac3_core: clear profile value on init()
The output stream no longer has Atmos metadata, so the
AV_PROFILE_EAC3_DDP_ATMOS profile, if it was set, is no longer valid.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-07-30 13:19:39 +00:00
Michael NiedermayerandFable-5 dd941af8ac avcodec/bsf/dts2pts: evict unconsumable nodes from the poc tree
Each pending packet consumes up to poc_diff tree nodes when it is
output, so the packets in the FIFO can consume at most nb_pending nodes
in total. Frames whose tree lookup misses on output leave their nodes
behind, and damaged or crafted streams can make that happen
indefinitely, growing the tree without limit.

Track the node count and insertion order, keep the leftovers of up to
MAX_DAMAGED_FRAMES frames and beyond that evict the nodes unconsumed
the longest. Timestamps of valid frames are unaffected unless more
frames than that are damaged. No eviction is done at EOF, where nodes
are deliberately kept to regenerate timestamps from.

Of all h264/hevc conformance samples only MR3_TANDBERG_B.264 triggers
evictions, and no sample changes output.

Fixes: unbounded memory growth with damaged streams

Co-Authored-By: Fable-5
2026-07-11 21:53:00 +00:00
Michael NiedermayerandFable-5 4133db39b2 avcodec/bsf/dts2pts: fix removal of 2nd field nodes
alloc_and_insert_node() inserts the nodes for 2nd fields with
duration / poc_diff added to the timestamp, but the removal loop
compared all nodes of a frame against the unadjusted first timestamp,
so 2nd field nodes never matched and stayed in the tree until close.
Advance the compared timestamp the same way the insertion does.

Fixes: tree nodes leaking on every field coded frame

Co-Authored-By: Fable-5
2026-07-11 21:53:00 +00:00
Michael NiedermayerandFable-5 501d8eb62d avcodec/bsf/dts2pts: chain same-gop nodes instead of collecting into a fixed array
hevc_queue_frame() collected all tree nodes of the current gop into a
fixed nodes[HEVC_MAX_DPB_SIZE * 2] array and asserted the count stayed
within it. For a crafted HEVC stream the tree can hold slightly more
same-gop nodes than that estimate (observed 34 vs 32), tripping the
av_assert0 and aborting. Link the matching nodes into a list through a
next pointer in the node instead; this has no size limit and needs
neither extra passes nor allocation.

Fixes: assertion failure
Fixes: 519466146/clusterfuzz-testcase-minimized-ffmpeg_BSF_DTS2PTS_fuzzer-5238235193475072
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg

Co-Authored-By: Fable-5
2026-07-11 21:53:00 +00:00
Zhao Zhili 1d5550613b avcodec/bsf/source: fix packet leak on av_packet_ref failure
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-07-07 19:04:42 +00:00
James Almer f2b3888754 avcodec/bsf: add an LCEVC stream merging bsf
Signed-off-by: James Almer <jamrial@gmail.com>
2026-07-06 13:27:25 -03:00
James Almer 32a256f619 avcodec: add a graph based bitstream filtering API
Tagged experimental for now, as it may see modifications depending on
requirements.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-07-06 13:26:02 -03:00
jiangjie 98c766ec19 avcodec/hevc_mp4toannexb: handle packet-side hvcC extradata
Do not overwrite the output codecpar extradata after init(). Keep the currently active HEVC parameter sets in HEVCBSFContext instead.

When AV_PKT_DATA_NEW_EXTRADATA on an input packet carries hvcC extradata, convert it to Annex B, update the runtime extradata state, and remove the packet side data.

Also add a FATE test covering extradata reloads with hevc_mp4toannexb,hevc_metadata.
2026-06-29 14:06:29 +00:00
James Almer 3d2c02f1dd avcodec/bsf/h264_mp4toannexb: don't overwrite output codecpar extradata after init()
It's against the documented behavior of bitstream filters.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-06-13 21:32:07 -03:00
Andrew Kelley b29bdd3715 bsf: qualify libavcodec include paths
Removes the special -I flag specified in the avcodec/bsf/ subdirectory.

This makes code copy-pastable to other parts of the ffmpeg codebase, as
well as simplifying the build script.

It also reduces ambiguity, since there are many instances of same-named
header files existing in both libavformat/ and libavcodec/
subdirectories.

Reverts: 0e4dfa4709
Reapplies: 41b73ae883
2026-06-10 18:52:32 -07:00
Kacper Michajłow 6026988b75 avcodec/bsf: add dovi_split BSF
Allows splitting interleaved BL+EL HEVC bitstream into separate streams.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-05-31 16:58:23 +02:00
Michael Niedermayer 054dffd133 avcodec/bsf/dts2pts: fix binary tree invariant violation on selective dec_poc
Modifying the keys of a sorted structure, be that a tree or other
can lead to changes in the ordering and undefined behavior.
It can also lead to collisions with existing keys.

All these cases need to be handled unless there is a bug elsewhere
that would prevent them.

Fixes: out of array access
Fixes: 504281984/clusterfuzz-testcase-minimized-ffmpeg_BSF_DTS2PTS_fuzzer-6032368162111488

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-31 13:41:57 +00:00
Michael Niedermayer 0834dbed1c avcodec/bsf/smpte436m_to_eia608: properly frees stuff on errors in ff_smpte436m_to_eia608_filter()
Fixes: memleaks
Fixes: 501913473/clusterfuzz-testcase-minimized-ffmpeg_BSF_SMPTE436M_TO_EIA608_fuzzer-5607133705207808

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-28 22:24:58 +00:00
Andreas Rheinhardt ff0ad0278d avcodec/cbs: Move ff_cbs_all_codec_ids to cbs_bsf
Only used as AVBitStreamFilter.codec_ids. This avoids duplicating
it into lavf.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-05-08 09:35:38 +02:00
Marvin Scholz 938fa8b14c avcodec: replace fall-through comments 2026-04-28 12:29:37 +00:00
Zhao Zhili 44ad73031d avcodec/bsf/lcevc_metadata: fix copy-paste typo in chroma loc setup
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-03-25 12:19:46 +00:00
James Almer d61d724905 avcodec/bsf/lcevc_metadata: write Aditional Info blocks after the Global Config block
Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-24 11:14:17 -03:00
Andreas Rheinhardt 9d97771bc6 avcodec/bsf/extract_extradata: Remove pointless checks
It doesn't hurt to keep track of filtered_size:
The end result will be ignored if extradata is not removed
from the bitstream.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-21 15:05:17 +00:00
Andreas Rheinhardt 1dd853010a avcodec/bsf/extract_extradata: Redo extracting LCEVC extradata
Changes compared to the current version include:
1. We no longer use a dummy PutByteContext on the first pass
for checking whether there is extradata in the NALU. Instead
the first pass no longer writes anything to any PutByteContext
at all; the size information is passed via additional int*
parameters. (This no longer discards const when initializing
the dummy PutByteContext, fixing a compiler warning.)
2. We actually error out on invalid data in the first pass,
ensuring that the second pass never fails.
3. The first pass is used to get the exact sizes of both
the extradata and the filtered data. This obviates the need
for reallocating the buffers lateron. (It also means
that the extradata side data will have been allocated with
av_malloc (ensuring proper alignment) instead of av_realloc().)
4. The second pass now writes both extradata and (if written)
the filtered data instead of parsing the NALUs twice.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-21 15:05:17 +00:00
Andreas Rheinhardt 548b9f5ca7 avcodec/bsf/extract_extradata: Inline constants
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-21 15:05:17 +00:00
James Almer 2556db6173 avcodec/bsf/extract_extradata: don't use a NULL pointer to initialize an empty PutByteContext
Fixes UB in the form or adding a 0 offset to a NULL pointer, and substracting a
NULL pointer from another.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:27:07 -03:00
James Almer 5ebd50415f avcodec/bsf/extract_extradata: reallocate buffers with the final used size
The buffers are allocated using the worst case scenario of the entire NALU
being written, when this is in many times not the case.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:27:01 -03:00
James Almer 1434d99b19 avcodec/bsf/extract_extradata: write correct length start codes for LCEVC
The specification for LCEVC states that start codes may be three or four bytes
long except for the first NALU in an AU, which must be four bytes long.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:20:06 -03:00
James Almer d1431d3f50 avcodec/bsf/extract_extradata: write correct length start codes for h26x
The specification for H.26{4,5,6} states that start codes may be three or four
bytes long long except for the first NALU in an AU, and for NALUs of parameter
set types, which must be four bytes long.
This is checked by ff_cbs_h2645_unit_requires_zero_byte(), which is made
available outside of CBS for this change.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:20:06 -03:00
Michael Niedermayer f84c859ec5 avcodec/bsf/extract_extradata: Replace incorrect size accounting
Fixes: out of array writes
Fixes: 492054712/clusterfuzz-testcase-minimized-ffmpeg_BSF_EXTRACT_EXTRADATA_fuzzer-5705993148497920

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-13 02:03:59 +00:00
James Almer 125bb2e045 avcodec/lcevc_parser: Check that block_size is not negative
Based on 248b481c33

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-09 18:39:33 -03:00
Michael Niedermayer 248b481c33 avcodec/bsf/extract_extradata: Check that block_size is not negative
Fixes: out of array access
Fixes: 490576036/clusterfuzz-testcase-minimized-ffmpeg_BSF_EXTRACT_EXTRADATA_fuzzer-4605696279904256

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-08 23:34:14 +00:00
James Almer 863c748144 avcodec/bsf/extract_extradata: remove extradata blocks from supported LCEVC NALUs
Given we rewrite these NALUs to remove the encoded data blocks to export as extradata,
we need to do the inverse to remove SC, GC and AI blocks to export as filtered data in
packes.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-03 09:05:45 -03:00
James Almer 3607a10dc3 avcodec/bsf/extract_extradata: simplify a switch statement
And use named defines. Will come in handy the following commit.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-03 09:05:45 -03:00
James Almer c893117048 avcodec/bsf/extract_extradata: fix writing filtered LCEVC NALUs when removing extradata
write_lcevc_nalu() is meant only for IDR and NON_IDR NALUs. For everything else, just
copy it unchanged.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-03 09:05:45 -03:00
James Almer e869426a8c avcodec/bsf/extract_extradata: remove dead code
Applied accidentally in 3dba9eb806.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-02-28 19:42:06 -03:00
James Almer e245f4d5cf avcodec/bsf: add a LCEVC metadata bitstream filter
Signed-off-by: James Almer <jamrial@gmail.com>
2026-02-28 16:14:40 -03:00
James Almer 3dba9eb806 avcodec/bsf/extract_extradata: add support for LCEVC
Signed-off-by: James Almer <jamrial@gmail.com>
2026-02-28 16:12:33 -03:00
Zhao Zhili 86d2fae59f avcodec: use int instead of enum for AVOption fields
AVOption with AV_OPT_TYPE_INT assumes the field is int (4 bytes),
but enum size is implementation-defined and may be smaller.
This can cause memory corruption when AVOption writes 4 bytes
to a field that is only 1-2 bytes, potentially overwriting
adjacent struct members.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-02-26 11:40:09 +08:00
Kacper Michajłow fa36645f7e avcodec/bsf/dovi_rpu: fix typo
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-02-12 00:56:21 +00:00