1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-29 05:57:37 +02:00
Commit Graph

26509 Commits

Author SHA1 Message Date
Zhao Zhili
920071355d avformat/movenc: Fix editlist with hybrid_fragmented
The segment_duration must not be set to zero when writing the moov
atom for the second time. This is related to edit lists in standard
MP4 files.

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-06-16 10:55:04 +08:00
Lidong Yan
b65fece0aa avformat/rtmpproto: fix rmtp packet leak in gen_connect()
In libavformat/rtmpproto.c:gen_connect(), if check on string length
or check on codec fourcc failed, ff_rtmp_packet_create() allocated
data in pkt would leak. Add ff_rtmp_packet_destory before return error
code.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Reviewed-by: Zhao Zhili <quinkblack@foxmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-16 01:31:45 +02:00
Jack Lau
8fc91ea936 avformat/hls: fix typo in Range header comment (chore)
Signed-off-by: Marth64 <marth64@proxyid.net>
2025-06-15 12:23:37 -05:00
Marth64
f8c8e1f39d avformat/dvdvideodec: fix seeking on multi-angle discs
When seeking on multi-angle titles, libdvdnav does not lock on
to the correct sectors initially as it seeks to find the right NAV packet.

This manifests itself as two bugs:
(1) When seeking on the first angle in a multi-angle segment,
frames from another angle will appear (for example in intro
or credits scenes). This issue is present in VLC also.

(2) When seeking during a segment on angle n+1, the demuxer
cannot deduce the right position from dvdnav and does not allow
seeking within the segment (due to it maintaining a strict state).

Correct the issue by switching to angle 1 before doing the seek
operation, and skipping 3 VOBUs (NAV packet led segments) ahead
where dvdnav will have positioned itself correctly.

Reported-by: Kacper Michajlow <kasper93@gmail.com>
Signed-off-by: Marth64 <marth64@proxyid.net>
2025-06-15 12:22:23 -05:00
Marth64
693703bcdb avformat/dvdvideodec: remove unused has_cc field
Signed-off-by: Marth64 <marth64@proxyid.net>
2025-06-15 12:22:17 -05:00
Marth64
f66ae1ba24 avformat/dump: lowercase 'Start' prefix for start offset
Just applying some UX polish.
This is to match the lowercase trend of attributes in
the dump string (and similar to chapters).

Signed-off-by: Marth64 <marth64@proxyid.net>
2025-06-15 12:22:10 -05:00
Clément Péron
90424a4475 various: fix typos
usefull -> useful
seperately -> separately
reciever -> receiver

Signed-off-by: Clément Péron <peron.clem@gmail.com>
2025-06-15 21:00:38 +05:30
Clément Péron
52441bd4cd avformat/rtpdec: explicit timestamp wraparound handling
Change delta_timestamp to int32_t and add explicit cast to handle
RTP timestamp wraparound correctly. This fixes implementation-defined
behavior when computing negative timestamp differences due to 32-bit
wraparound.

Signed-off-by: Clément Péron <peron.clem@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-14 23:41:38 +02:00
Kacper Michajłow
26807592e1 avformat/internal: add missing __clang__ check
Clang x86_64-pc-windows-msvc doesn't define __GNUC__.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2025-06-12 14:17:38 +03:00
Marvin Scholz
93255f1c48 avformat/sdp: add framerate entry
This also updates fate-lavf-mov_rtphint as there the SDP
is included in the muxed file.
2025-06-11 19:19:50 +02:00
Erik Linge
e8199f95d6 avformat/rtpdec_jpeg: Set width and heigh codec parameters
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
2025-06-11 19:19:50 +02:00
Erik Linge
c917f28c49 avformat/rtsp: parse framerate in sdp
Co-authored-by: Marvin Scholz <epirat07@gmail.com>
Signed-off-by: Marvin Scholz <epirat07@gmail.com>
2025-06-11 19:19:50 +02:00
Marvin Scholz
2dcd9c5aac doc: use av_dict_iterate in documentation example 2025-06-11 19:19:50 +02:00
nyanmisaka
ebcf2dcb2c avformat/movenc: handle EAC-3 extension bits for Atmos
Based on a patch by nyanmisaka.
Fixes commit #9996.

Reviewed-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-06-08 18:39:35 -03:00
James Almer
117343c0ba avcodec/ac3_parser: handle more header bits in ff_ac3_parse_header()
Based on a patch by nyanmisaka.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-06-08 18:39:17 -03:00
Derek Buitenhuis
be46370941 avformat/dhav: Add missed free for end_buffer
Accidentally left out of 36ec9217e6.

Found-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2025-06-08 12:58:22 +01:00
Clément Péron
8a9cbf99a5 libavformat/rtpdec: Fix RTP timestamp wraparound in Producer Reference Time
The rtp_set_prft() function incorrectly calculates the timestamp delta
when RTP timestamps wrap around the 32-bit boundary. The current code:

    delta_timestamp = (int64_t)timestamp - (int64_t)s->last_rtcp_timestamp;

treats both timestamps as large positive values, causing wraparound to
produce a large negative delta instead of the correct small positive delta.

For example, with a 90kHz video clock:
- last_rtcp_timestamp = 0xFFFFFF00 (near wraparound)
- timestamp = 0x00000100 (after wraparound)
- Current result: delta ≈ -4.3 billion ticks ≈ -47,721 seconds
- Expected result: delta ≈ +512 ticks ≈ +0.006 seconds

This causes prft->wallclock to jump backward by approximately:
- 90kHz video: ~47,721 seconds (~13.25 hours)
- 48kHz audio: ~89,478 seconds (~24.9 hours)
- 8kHz audio: ~536,871 seconds (~6.2 days)

Fix by casting the subtraction result to int32_t, which correctly
handles wraparound through modular arithmetic:

    delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp);

This ensures the delta is always in the range [-2^31, 2^31-1], making
wraparound produce the correct small positive values.

Fixes timing jumps in applications that rely on Producer Reference Time
for media synchronization.

Signed-off-by: Clément Péron <peron.clem@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-08 02:07:23 +02:00
Michael Niedermayer
869e288b3a avformat/framecrcenc: List types and checksums for for side data
This allows detecting changes and regressions in side data related code, same as what
framecrc does for before already for packet data itself.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-07 20:00:12 +02:00
Michael Niedermayer
21fd1b5ba5 avformat/dhav: Do not evaluate avio_size() multiple times
Code like FFMIN(MAX_DURATION_BUFFER_SIZE, avio_size(s->pb)) is not safe
as FFMIN() is a macro and avio_size() is thus evaluated multiple
times

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-07 19:36:49 +02:00
Jack Lau
4611ed5cc3 avformat/tls_openssl: fix build error when openssl version < 3
add the missing data structure pkey in the tls_context
properly set this pkey and free it

Signed-off-by: Jack Lau <jacklau1222@qq.com>
Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-06-07 14:36:58 +02:00
Zhao Zhili
a5dc56fcd6 avformat/format: make experimental flag works for muxer
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-06-07 15:59:06 +08:00
Zhao Zhili
153cdf3142 avformat/whip: Constify arguments in is_rtp_rtcp/is_rtcp
Fix warning of -Wincompatible-pointer-types-discards-qualifiers.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-06-07 15:58:21 +08:00
Zhao Zhili
1af6881ba1 avformat/tls: Fix integer overflow with option mtu
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-06-07 15:58:21 +08:00
James Almer
17729aa80c avformat/movenc: fix writing reserved bits in EC3SpecificBox
As described in section F.6.1 from ETSI TS 102 366.

Found-by: nyanmisaka
Reviewed-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-06-05 21:49:11 -03:00
Jack Lau
167e343bbe avformat/whip: Add WHIP muxer support for subsecond latency streaming
0. WHIP Version 3.
1. The WHIP muxer has been renamed and refined,
    with improved logging context and error messages for SSL, DTLS, and RTC.
2. Magic numbers have been replaced with macros and extracted to functions,
    and log levels have been altered for better clarity.
3. DTLS curve list has been updated,
    and SRTP profile names have been refined for FFmpeg and OpenSSL.
4. ICE STUN magic number has been refined,
    and RTP payload types have been updated based on Chrome's definition.
5. Fixed frame size has been refined to rtc->audio_par->frame_size,
    and h264_mp4toannexb is now used to convert MP4/ISOM to annexb.
6. OPUS timestamp issue has been addressed,
    and marker setting has been corrected after utilizing BSF.
7. DTLS handshake and ICE handling have been optimized for improved performance,
    with a single handshake timeout and server role to prevent ARQ.
8. Consolidated ICE request/response handling and DTLS handshake into a single function,
    and fixed OpenSSL build errors to work with Pion.
9. Merge TLS & DTLS implementation, shared BIO callbacks, read, write,
    print_ssl_error, openssl_init_ca_key_cert,
    init_bio_method function and shared same data structure
10. Modify configure that whip is enabled only dtls is
    enabled(just support openssl for now) to fix build error

Co-authored-by: winlin <winlinvip@gmail.com>
Co-authored-by: yangrtc <yangrtc@aliyun.com>
Co-authored-by: cloudwebrtc <duanweiwei1982@gmail.com>
Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: Steven Liu <lq@chinaffmpeg.org>
Co-authored-by: Jun Zhao <barryjzhao@tencent.com>
Signed-off-by: Jack Lau <jacklau1222@qq.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2025-06-04 11:17:07 +08:00
Zhao Zhili
8ea2b993fd avformat/movenc: Reduce loop iterations in mov_flush_fragment
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-06-01 16:37:00 +08:00
Zhao Zhili
56cf1c084d avformat/movenc: Fix flush fragment
The follow cmd output corrupted file before the patch:

ffmpeg -f lavfi -i color=blue,trim=duration=0.04 \
	-f lavfi -i anullsrc,atrim=duration=2 \
	-movflags +empty_moov+hybrid_fragmented \
	-frag_duration 1000000 \
	-frag_interleave 1 \
	output.mp4

1. first_track is the first track with track->entry != 0. As in the
command above, video track (track index 0) has a single frame. When
flush the second fragment, first_track is 1, the audio track.

2. write_moof = i == first_track, so write_moof is false for i = 0.

3. When mov->frag_interleave != 0, mov->mdat_buf != NULL, because
it contains audio data. So avio_write is called before write_moof,
that is, the data write before moof, and mov_finish_fragment
executed with wrong mdat_start.

4. With normal fmp4 output, the error isn't obvious. With
hybrid_fragmented, ffplay output.mp4 shows a lot of error messages.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-06-01 16:36:54 +08:00
Gabriel Hege
6c291232cf avformat/movenc: fix VVC encoding with leading pictures
The default behavior for VVenC (since v1.10.0) is to create an IDR with
leading pictures for the first picture in decoding order (POC 32). This
leads to FFmpeg generating an edit list with an empty entry, skipping
the leading pictures.

This patch fixes the calculation for the start_pts, while the DTS is
negative (as produced by vvenc).

Signed-off-by: Gabriel Hege <g+ffmpeg@hege.cc>
2025-05-31 09:47:50 +08:00
Michael Niedermayer
848ceb1329 Revert "ogg/vorbis: implement header packet skip in chained ogg bitstreams."
non flat extradata is problematic and was missed by reviewers

Found-by: Andreas Rheinhardt
This reverts commit 574f634e49.
2025-05-31 03:18:26 +02:00
Kacper Michajłow
1a7e802c8f avformat/demux: use io_close2 when closing avfromat
It's not valid to call avio_close() on context that has not been open
with avio_open().

This fixes use of custom IO. (io_open / io_close2 callbacks)

Note that by default io_close2 is set to io_close2_default() which calls
avio_close(), so default case will work the same as before.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-31 00:08:25 +02:00
Romain Beauxis
5030564376 libavformat/oggdec.h: Change paket function documentation to return 1 on header packets only.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-30 22:07:11 +02:00
Romain Beauxis
574f634e49 ogg/vorbis: implement header packet skip in chained ogg bitstreams.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-30 22:07:10 +02:00
Romain Beauxis
c9cc61d620 ogg/vorbis: factor out header processing logic.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-30 22:07:10 +02:00
Romain Beauxis
ba3d4c2ba2 libavformat/oggdec.{c, h}: Add new_extradata, use it to pass extradata to the next decoded packet.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-30 22:07:10 +02:00
Andreas Rheinhardt
96d4bcbcd8 avformat/matroskaenc: Use native id V_FFV1 instead of V_MS/VFW/FOURCC
Up until now, our muxer wrote FFV1 in video-for-windows
compatibility mode out of concern for old demuxers that
only support that (whereas the demuxer accepts V_FFV1).
This commit switches to using native mode, because
a) V_FFV1 is around long enough so that old demuxers
should not be an issue (support in FFmpeg has been added
in commit 9ae762da7e
in March 2017/FFmpeg 3.3),
b) using native mode uses fewer bytes for the CodecPrivate,
c) the VfW extradata is zero-padded to an even length
if necessary, but our demuxer forgot to undo the padding
until very recently (92e310eb82),
so that there are many versions of our demuxer around that
are buggy wrt VFW, but not V_FFV1.
This affects the FFV1 extradata checksums, specifically
the (experimental) version 4 files with error check version 2*
as created by
ffmpeg -i ../fate-suite/mpeg2/sony-ct3.bs -c:v ffv1 \
-slices 16 -frames 1 -level 4 -strict experimental ffv1.mkv
VFW files like the above created by this muxer before this patch
would not work with an old demuxer.

*: Without error check version 2, the CRC for the whole extradata
is zero, which is not changed by appending a zero byte.

Reviewed-by: compn <ff@hawaiiantel.net>
Reviewed-by: Dave Rice <dave@dericed.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-28 02:42:36 +02:00
Andreas Rheinhardt
8a936b8726 avformat/matroska: Support JPEG2000 for demuxing
Legal since commit 1cd0a9be4b2d1e7c60184ec68404e00e46e3123e
(Jan 4) in the Cellar Matroska specification git repo.
We still hold out on muxing it due to compatibility with
old demuxers.

Reviewed-by: compn <ff@hawaiiantel.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-28 02:09:28 +02:00
Andreas Rheinhardt
92e310eb82 avformat/matroskadec: Fix VfW extradata size
The structure is padded to an even length with an internal
size field to indicate the real size.
The matroska-matroska-display-metadata test (writing FFV1
in VFW mode) was affected by this.
It should also fix ticket #11613.

Reviewed-by: compn <ff@hawaiiantel.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-27 22:07:35 +02:00
Gyan Doshi
c79bce92b8 avformat/movenc: disallow buggy flags combination
Use of hybrid_fragmented and faststart together can result in files with
loss of sync and bitstream parsing errors upon playback.
2025-05-26 22:44:17 +05:30
Marcos Del Sol Vives via ffmpeg-devel
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
Kacper Michajłow
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
Erik Linge
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
Erik Linge
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
Jonathan Baudanza
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
Justin Ruggles
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
Andreas Rheinhardt
bd63c374d2 avformat/avformat: Remove outdated io_close2 documentation
The io_close callback has been removed in
d6799ee0e4.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-21 02:43:08 +02:00
Zhao Zhili
4f7bc62c66 avformat/allformats: Move avisynth and dvdvideo under external libraries group
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-05-20 21:17:28 +08:00
Romain Beauxis
9c5ed57f94 ogg/opus: implement header packet skip in chained ogg bitstreams. 2025-05-19 07:24:05 +02:00
Romain Beauxis
2fb6416dd0 ogg/flac: implement header packet skip in chained ogg bitstreams. 2025-05-19 07:24:05 +02:00
Pavel Koshevoy
0021484d05 avformat/mpegts: update stream info when PMT ES stream_type changes
I have several .ts captures where video and audio codec changes even
though the PMT version does not change and the PIDs stay the same.
This happens during transition to/from slate (mpeg2 video and audio)
to network broadcast (hevc video and eac3 audio in private PES).

I've updated fate ts-demux expected results.
2025-05-18 08:57:31 -06:00
Michael Niedermayer
05f8c8c4c2 avformat/matroskadec: check that channels fit in signed 32bit int
Fixes: signed integer overflow: -1384566925600903168 * 16 cannot be represented in type 'long'
Fixes: 407069502/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-5159255372267520

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-15 03:03:57 +02:00