Commit graph

26920 commits

Author SHA1 Message Date
Nicolas Gaullier
af6a1dd0b2 avformat/demux: duplicate side_data in parse_packet()
If an input packet results in several output packets, the side data will be
exported only by the first output packet, and be missing from the rest.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Signed-off-by: James Almer <jamrial@gmail.com>
2026-01-07 20:25:18 -03:00
James Almer
0cca125a94 avformat/demux: prevent the loss of packet side data when using an parser
Many parsers will request data until they find what will be the start of the
next assembled packet in order to decide where to cut the current one. If this
happens, the loop in demux.c will, in case the demuxer exports already fully
assembled packets as is sometimes the case for MPEG-TS, discard the already
handled first input packet before it tries to move its side data to the output.

The affected FATE tests reflect this change by no longer dropping the side data
from the first input packet, nor exporting every other side data in the wrong
output packet.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-01-07 20:25:18 -03:00
James Almer
70d84bdd84 avformat/demux: use a stream specific temporary packet for the parser
This will be useful for the next commit.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-01-07 20:25:17 -03:00
Gyan Doshi
03541f0026 avformat/hls: show stream IDs
The subdemuxer may be MPEG-TS which sets stream id, and users may
want to see it for stream selection.
2026-01-06 04:05:47 +00:00
wangwenchao10
2892815c45 avformat/pcmdec: Mark raw PCM stream as having no timestamps
Signed-off-by: wangwenchao10 <wangwenchao10@xiaomi.com>
2026-01-05 01:23:17 +00:00
Marton Balint
8579037b6c avformat/file: respect pkt_size even in streaming mode
Also clarify the documentation a bit.

Signed-off-by: Marton Balint <cus@passwd.hu>
2026-01-01 18:20:58 +00:00
Timo Rothenpieler
f6a95c7eb7 avformat/img2dec: reject input images too big to fit into a single packet
Not entirely sure if it should instead use some entirely different
approach here, given that images exceeding 2GB don't seem that crazy
to me, but so far processing such images results in a heap overflow,
since the size addition overflows and a much too small packet is
allocated and its size never checked again when writing into it.

Fixes #YWH-PGM40646-32
2025-12-31 14:37:58 +00:00
caifan3
82144fea48 libavformat/file: apply pkt_size option to read mode
Previously, the pkt_size option only affected write buffering in the file
protocol. This change extends its effect to read mode as well.

On embedded systems with limited RAM, users can now reduce I/O buffer
memory by setting a smaller pkt_size.

Signed-off-by: caifan3 <caifan3@xiaomi.com>
2025-12-30 00:49:13 +00:00
James Almer
129744ac72 avformat/iamf_writer: reindent after the previous change
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-29 12:02:10 -03:00
James Almer
8cd4d4cb0b avformat/iamf_writer: add support for Projection mode ambisonic Audio elements
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-29 12:02:02 -03:00
James Almer
a0fc454871 avformat/iamf_writer: check that stream count is consistent for ambisonic Audio Elements
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-29 12:00:01 -03:00
James Almer
21ff60d2cf avformat/iamf_writer: fix writting some ambisonics fields in Audio Elements
The fields are defined as 8 bit long unsigned ints. Fortunately, writing most sane values
as leb is equivalent, which is why no tests are affected.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-29 12:00:01 -03:00
James Almer
e3498c8051 avformat/iamf_parse: set AVIAMFLayer.nb_demixing_matrix
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-29 12:00:01 -03:00
James Almer
03a981445e avformat/iamf_parse: fix setting denominator in AVIAMFLayer.demixing_matrix
The format of demixing_matrix is Q15 fixed point values.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-29 12:00:01 -03:00
Martin Storsjö
78bfcf003b libavformat: Fix the docs for av_mime_codec_str and ff_make_codec_str
The doxygen comments were missed as these functions were updated
during review; they don't take separate pointer/length parameters
but use an AVBPrint struct now instead.

Also clarify that ff_make_codec_str doesn't log if the logctx
parameter is NULL.
2025-12-29 12:05:14 +00:00
James Almer
f8e6f8f0a2 avformat/iamf_parse: check layer channel count and stream count for consistency
A layer could define a loudspeaker_layout that corresponds to a certain channel layout,
but then report an amount of substream_count and coupled_substream_count that might not
match the expected channel count.

Fixes: Invalid write of size 4
Fixes: clusterfuzz-testcase-minimized-ffmpeg_dem_IAMF_fuzzer-6687125346254848

Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-27 15:16:49 +00:00
Michael Niedermayer
9e974b2c45
avformat/hls: fix double space
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-12-24 14:14:45 +01:00
Michael Niedermayer
548b28d5b1 avformat/hls: Fix arguments of handle_rendition_args()
Fixes: call to function handle_rendition_args through pointer to incorrect function type 'void (*)(void *, const char *, int, char **, int *)'
Fixes: 464965411/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-4790164406992896

Found-by:  continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-12-24 12:04:07 +00:00
Michael Niedermayer
d1985442e1 avformat/hls: Check seg size and offset for overflow
Fixes: integer overflow
Fixes: signed integer overflow: 9223372036854775807 + 2039324394 cannot be represented in type 'int64_t' (aka 'long')

Found-by:  continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-12-24 12:04:07 +00:00
Zhao Zhili
260f5a47a5 avformat/rawvideodec: add stride option to skip line padding
Some tools like v4l2-ctl dump data without skip padding. If the
padding size is not an integer multiple of the number of pixel
bytes, we cannot handle it by using a larger width, e.g.,, for
RGB24 image with 32 bytes padding in each line.
2025-12-23 03:20:34 +00:00
Zhao Zhili
49a15e70be avformat/rawvideodec: use AV_OPT_TYPE_PIXEL_FMT instead of parse from string manually 2025-12-23 03:20:34 +00:00
Romain Beauxis
b43645b2ef libavformat/id3v2.c: return valid string in decode_str for empty strings
with no bom. Fixes: #YWH-PGM40646-12
2025-12-22 13:44:42 +00:00
Andreas Rheinhardt
b934dd1d4b avformat/whip: Fix leak of dtls_fingerprint
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Reviewed-by: Jack Lau <jacklau1222gm@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-19 21:45:24 +01:00
Andreas Rheinhardt
34bc95ddfc avformat/whip: Check number of audio/video streams generically
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Reviewed-by: Jack Lau <jacklau1222gm@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-19 21:45:21 +01:00
Andreas Rheinhardt
e252bc0c3d avformat/whip: Remove dead code
This is checked generically after
6070ea29de.
Also set AVOutputFormat.subtitle_codec explicitly in order
not to rely on AV_CODEC_ID_NONE to be zero.

Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Reviewed-by: Jack Lau <jacklau1222gm@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-19 21:42:27 +01:00
Andreas Rheinhardt
1c35a1b79b avformat/flvdec: Fix leak of channel layout map
Fixes: memleak
Fixes: 418396714/clusterfuzz-testcase-minimized-ffmpeg_dem_KUX_fuzzer-4595253332213760

Found-by:  continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-19 08:02:52 +01:00
Andreas Rheinhardt
4aed9db83c avformat/flac_picture: Correct check
Since af97c9865f,
the return value of avio_read() has been compared against
an uint32_t, so that the int is promoted to uint32_t for
the comparison (on common systems with 32bit ints). The upshot was
that errors returned from avio_read() were ignored, so that
the buffer could be uninitialized on success.

Fix this by using ffio_read_size() instead.

Fixes: MemorySanitizer: use-of-uninitialized-value
Fixes: 443923343/clusterfuzz-testcase-minimized-ffmpeg_dem_FLAC_fuzzer-5458132865449984

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-19 07:32:01 +01:00
Gyan Doshi
6070ea29de lavf/whip: add flag for default codecs only
The muxer does not accept any other codecs.
2025-12-19 04:13:34 +00:00
Gyan Doshi
fdce17953c lavf/supenc: add flag for default codecs only
The muxer does not accept any other codecs.
2025-12-19 04:13:34 +00:00
Gyan Doshi
20b671f651 lavf/dvenc: add flag for default codecs only
The muxer does not accept any other codecs.
2025-12-19 04:13:34 +00:00
Timo Rothenpieler
4bb9b46486 avcodec/demux: validate avctx state in has_decode_delay_been_guessed 2025-12-16 22:45:17 -03:00
James Almer
c9c95f6f32 avformat/demux: ensure avformat_find_stream_info updates internal stream contexts
read_frame_internal() may result in a stream being modified without also
returning a packet from it. Given said function only bothered to update the
internal stream context for the returned packet, the result would be a desync
between the stream's AVCodecParameters and the internal AVCodecContext.

This change makes sure all streams are updated within the
avformat_find_stream_info() loop.

Fixes #YWH-PGM40646-20

Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-16 22:45:17 -03:00
Ruikai Peng
16f89d342e avformat/mpegts: bounds-check JPEG-XS header_size before padding
Regression since: 536475ea05.

The JPEG-XS PES path trusted header_size from the payload and advanced
pkt->data/pkt->size without validation, so the trailing memset could
write out of bounds when header_size > pkt->size. Reject such packets,
marking them corrupt and returning an error to avoid the OOB write.

Repro (ASan):
ASAN_OPTIONS=halt_on_error=1:detect_leaks=0   ./ffmpeg -v debug -nostdin -i poc-jpegxs.ts -copy_unknown -map 0   -c copy -f null /dev/null

Crash in new_pes_packet memset on crafted TS with stream_id 0xbd,
stream_type 0x32, header_size 0xFFFFFF00, payload starting with jxes.

Found-by: Pwno
2025-12-14 17:42:59 +00:00
Marton Balint
131a33c808 avformat/xmv: do not set audio pts values
The format does not contain audio timestamps and the calculated audio pts
values were only correct for compressed audio. It is better to remove PTS
calculation entirely and let the generic code handle it.

Fixes ticket #8595.
Fixes #20983.

Fate test changes are because of the different audio time base which is now
always 1/sample_rate.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-12-14 17:08:37 +00:00
Andreas Rheinhardt
b802eeabff avformat/Makefile: Add jpegxs->img2dec.o dependency
Forgotten in 3b1214a897.

Reported-by: Jamaika1 <lukaszcz18@wp.pl>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-14 14:27:46 +01:00
jess
536475ea05 avformat/mpegts: add support for JPEG-XS streams
Co-Authored-by: James Almer <jamrial@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-13 19:03:43 -03:00
James Almer
3b1214a897 avformat: add a raw JPEG-XS muxer and demuxer
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-13 19:03:36 -03:00
Jack Lau
ec0173ab59 avformat/amr: add P bits check to avoid mis-detects
Fix #21056

Refer to RFC 3267 Section 4.4.2:

A ToC entry takes the following format in octet-aligned mode:

 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
|F|  FT   |Q|P|P|
+-+-+-+-+-+-+-+-+

P bits: padding bits, MUST be set to zero.

Signed-off-by: Jack Lau <jacklau1222gm@gmail.com>
2025-12-12 20:17:00 +00:00
Martin Storsjö
c9b5e145b7 avformat: Add av_mime_codec_str public API
Add a public API for producing RFC 4281/6381 codecs trings for
MIME types.

This can be required for providing alternative video files to
a web browser, letting the browser pick the best file it supports.
Such strings also allow querying a browser whether it supports
a certain codec combination.

Finally, if implementing a DASH/HLS segmenter outside of libavformat,
one also has to generate such strings.

Generating such strings for H264/AAC is very simple, but for
more modern codecs, it can require a lot of nontrivial codec
specific parsing of extradata.

As libavformat already implements this, expose it for users as well.

The old, internal function ff_make_codec_str is kept and used by
the HLS and DASH muxers; the old function takes a logging context
which can be used for logging auxillary info about how the string
generation worked out.
2025-12-12 18:40:00 +02:00
Martin Storsjö
360fda56cd avformat: Skip logging in ff_make_codec_str if logctx == NULL
This is in preparation for reusing the same codepaths for a public
API, where we don't want it to print various diagnostic logging.
2025-12-12 18:39:34 +02:00
Ruikai Peng
bb424927db avformat/sierravmd: fix header read error check
The header read check stored the comparison result into ret, so read
failures became ret=1 and were treated as success, leaving the VMD header
uninitialized and letting parsing continue with bogus state.

Regression since: ee623a43e3.
Found-by: Pwno
2025-12-11 16:26:17 +00:00
James Almer
16050a1cef avformat/iamf_writer: ensure expanded_loudspeaker_layout is only written when using a single scalable layout layer
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-09 17:54:11 -03:00
James Almer
5cdc1cad77 avformat/iamf_parse: add a few extra sanity checks
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-09 17:54:11 -03:00
James Almer
2d5abf27e5 avformat/iamf_parse: fix parsing of Scalable layouts with Mono and Stereo layers
An ASAN heap-buffer-overflow in scalable_channel_layout_config was caused by an
unchecked assumption that the channel layout of a scalable audio layer is a
superset of the previous layer's channel layout.

scalable_channel_layout_config constructs a channel layout map by copying
channels from the previous layer and adding new ones. The memory allocation is
based on the target loudspeaker_layout. However, if the target layout doesn't
encompass all previous channels (e.g., Mono to Stereo), copying previous
channels followed by adding current ones could exceed the allocated size,
causing a heap buffer overflow.

This commit adds an exception for the know case of Mono -> Stereo, and a check
to ensure the previous layer's channel layout is a subset of the current
layer's layout by comparing their masks. If the condition isn't met,
an error is returned.

Fixes: https://issues.oss-fuzz.com/issues/464965414

Co-authored-by: Oliver Chang <ochang@google.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-09 17:54:11 -03:00
James Almer
ac9552bebf avformat/cbs: add missing license headers
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-08 20:07:45 -03:00
caifan3
40d7f7774a avformat/unix: add pkt_size option
Add a "pkt_size" AVOption to the Unix domain socket protocol. This option
allows the user to specify the maximum packet size for packet-oriented
sockets (SOCK_DGRAM and SOCK_SEQPACKET).

Signed-off-by: caifan3 <caifan3@xiaomi.com>
2025-12-07 19:36:03 +00:00
Andreas Rheinhardt
e0845ec2cf avformat/movenc: Fix leak of IAMFContext on error
Forgotten in 5b87869c09.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-04 16:15:09 +00:00
Michael Niedermayer
12e7d095b1 Revert "avformat/rawdec: set framerate in codec parameters"
Fixes single image videos
this works and creates our single image video
./ffmpeg -i lena.pnm /tmp/file.m2v

this fails after 3d96d83a0a:
./ffmpeg -i /tmp/file.m2v /tmp/file.jpg -y

This reverts commit 3d96d83a0a.
2025-12-04 01:59:04 +00:00
wutno
f4312ea138 avformat/xmv: Handle zero sized packet at end of file
Some XMVs introduce a blank packet at the end of the stream. Previously, we
didn't account for this and returned AVERROR_INVALIDDATA, indicating an issue
with the file. Instead, let's check for this and close out with AVERROR_EOF.
2025-12-03 22:09:20 +00:00
Andreas Rheinhardt
5d9270df7f libavutil/internal: Remove {SIZE,PTRDIFF}_SPECIFIER
Possible since 222127418b.

Reviewed-by: Kacper Michajłow <kasper93@gmail.com>
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-03 11:52:54 +01:00