Commit Graph

24495 Commits

Author SHA1 Message Date
Clément Bœsch
ab77b878f1 avformat/mov: fix seeking with HEVC open GOP files
This was tested with medias recorded from an iPhone XR and an iPhone 13.

Here is how a typical stream looks like in coding order:

    ┌────────┬─────┬─────┬──────────┐
    │ sample | PTS | DTS | keyframe |
    ├────────┼─────┼─────┼──────────┤
    ┊        ┊     ┊     ┊          ┊
    │   53   │ 560 │ 510 │    No    │
    │   54   │ 540 │ 520 │    No    │
    │   55   │ 530 │ 530 │    No    │
    │   56   │ 550 │ 540 │    No    │
    │   57   │ 600 │ 550 │    Yes   │
    │ * 58   │ 580 │ 560 │    No    │
    │ * 59   │ 570 │ 570 │    No    │
    │ * 60   │ 590 │ 580 │    No    │
    │   61   │ 640 │ 590 │    No    │
    │   62   │ 620 │ 600 │    No    │
    ┊        ┊     ┊     ┊          ┊

In composition/display order:

    ┌────────┬─────┬─────┬──────────┐
    │ sample | PTS | DTS | keyframe |
    ├────────┼─────┼─────┼──────────┤
    ┊        ┊     ┊     ┊          ┊
    │   55   │ 530 │ 530 │    No    │
    │   54   │ 540 │ 520 │    No    │
    │   56   │ 550 │ 540 │    No    │
    │   53   │ 560 │ 510 │    No    │
    │ * 59   │ 570 │ 570 │    No    │
    │ * 58   │ 580 │ 560 │    No    │
    │ * 60   │ 590 │ 580 │    No    │
    │   57   │ 600 │ 550 │    Yes   │
    │   63   │ 610 │ 610 │    No    │
    │   62   │ 620 │ 600 │    No    │
    ┊        ┊     ┊     ┊          ┊

Sample/frame 58, 59 and 60 are B-frames which actually depends on the
key frame (57). Here the key frame is not an IDR but a "CRA" (Clean
Random Access).

Initially, I thought I could rely on the sdtp box (independent and
disposable samples), but unfortunately:

    sdtp[54] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0
    sdtp[55] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0
    sdtp[56] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0
    sdtp[57] is_leading:0 sample_depends_on:2 sample_is_depended_on:0 sample_has_redundancy:0
    sdtp[58] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0
    sdtp[59] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0
    sdtp[60] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0
    sdtp[61] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0
    sdtp[62] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0

The information that might have been useful here would have been
is_leading, but all the samples are set to 0 so this was unusable.

Instead, we need to rely on sgpd/sbgp tables. In my case the video track
contained 3 sgpd tables with the following grouping types: tscl, sync
and tsas. In the sync table we have the following 2 entries (only):

    sgpd.sync[1]: sync nal_unit_type:0x14
    sgpd.sync[2]: sync nal_unit_type:0x15

(The count starts at 1 because 0 carries the undefined semantic, we'll
see that later in the reference table).

The NAL unit types presented here correspond to:

    libavcodec/hevc.h:    HEVC_NAL_IDR_N_LP       = 20,
    libavcodec/hevc.h:    HEVC_NAL_CRA_NUT        = 21,

In parallel, the sbgp sync table contains the following:

    ┌────┬───────┬─────┐
    │ id │ count │ gdi │
    ├────┼───────┼─────┤
    │  0 │   1   │  1  │
    │  1 │   56  │  0  │
    │  2 │   1   │  2  │
    │  3 │   59  │  0  │
    │  4 │   1   │  2  │
    │  5 │   59  │  0  │
    │  6 │   1   │  2  │
    │  7 │   59  │  0  │
    │  8 │   1   │  2  │
    │  9 │   59  │  0  │
    │ 10 │   1   │  2  │
    │ 11 │   11  │  0  │
    └────┴───────┴─────┘

The gdi column (group description index) directly refers to the index in
the sgpd.sync table. This means the first frame is an IDR, then we have
batches of undefined frames interlaced with CRA frames. No IDR ever
appears again (tried on a 30+ seconds sample).

With that information, we can build an heuristic using the presentation
order.

A few things needed to be introduced in this commit:

1. min_sample_duration is extracted from the stts: we need the minimal
   step between sample in order to PTS-step backward to a valid point
2. In order to avoid a loop over the ctts table systematically during a
   seek, we build an expanded list of sample offsets which will be used
   to translate from DTS to PTS
3. An open_key_samples index to keep track of all the non-IDR key
   frames; for now it only supports HEVC CRA frames. We should probably
   add BLA frames as well, but I don't have any sample so I prefered to
   leave that for later

It is entirely possible I missed something obvious in my approach, but I
couldn't come up with a better solution. Also, as mentioned in the diff,
we could optimize is_open_key_sample(), but the linear scaling overhead
should be fine for now since it only happens in seek events.

Fixing this issue prevents sending broken packets to the decoder. With
FFmpeg hevc decoder the frames are skipped, with VideoToolbox the frames
are glitching.
2022-03-04 15:50:51 +01:00
Clément Bœsch
e05e4398c3 avformat/mov: add parsing for the sgpd sync box
sgpd means Sample Group Description Box.

For now, only the sync grouping type is parsed, but the function can
easily be adjusted to support other flavours.

The sbgp (Sample to Group Box) sync_group table built in previous commit
contains references to this table through the group_description_index
field.
2022-03-04 15:50:51 +01:00
Clément Bœsch
eb947471b2 avformat/mov: add support for sync group in sbgp box 2022-03-04 15:50:51 +01:00
Clément Bœsch
954f488ea3 avformat/mov: prepare sbgp parsing for other grouping types 2022-03-04 15:50:51 +01:00
Stephen Hutchinson
e81242bb13 avformat/avisynth: fix fallbacks for four frameprops
If _FieldBased, _Matrix, _ColorRange, or _ChromaLocation haven't
been set, that absence would be interpreted as 0, leading to those
being set to case 0 instead of default. There is no case 0 for
_Primaries and _Transfer, so those were correctly falling back
to the default case.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
2022-03-02 17:45:40 -05:00
Michael Niedermayer
4419433d77 avformat/mov: Disallow empty sidx
It appears this is not allowed "Each Segment Index box documents how a (sub)segment is divided into one or more subsegments
(which may themselves be further subdivided using Segment Index boxes)."
Fixes: Null pointer dereference
Fixes: Ticket9517

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-02 17:51:35 +01:00
James Almer
7a4840a8ca avformat/av1: reduce the scope of some variables
Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-28 09:12:51 -03:00
James Almer
76e10325fc avformat/av1: support av1C extradata in ff_av1_parse_seq_header()
Fixes dash manifest creation for av1 streams with av1C formatted extradata.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-28 09:08:27 -03:00
James Almer
b6c7f82db7 avformat: always compile isom_tags
It's needed for avformat_get_mov_video_tags() and avformat_get_mov_audio_tags(),
both public symbols defined in avformat.h

Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-28 09:08:19 -03:00
James Almer
df272928ff configure: stop allowing disabling lzo
The module is now always compiled in.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-26 14:22:07 -03:00
Michael Niedermayer
70a1024290 avformat/argo_cvg:: Fix order of operations in error check in argo_cvg_write_trailer()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-25 22:23:03 +01:00
Michael Niedermayer
c8c12fb5d6 avformat/argo_asf: Fix order of operations in error check in argo_asf_write_trailer()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-25 22:23:03 +01:00
Michael Niedermayer
36680078ca avformat/matroskadec: Check duration
Fixes: -nan is outside the range of representable values of type 'long'
Fixes: 44614/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-6216204841254912

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-25 22:23:03 +01:00
Andreas Rheinhardt
636631d9db Remove unnecessary libavutil/(avutil|common|internal).h inclusions
Some of these were made possible by moving several common macros to
libavutil/macros.h.

While just at it, also improve the other headers a bit.

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-24 12:56:49 +01:00
Andreas Rheinhardt
155cd6baa4 Remove obsolete version.h inclusions
Forgotten in e7bd47e657.

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-24 12:56:49 +01:00
Andreas Rheinhardt
321a3c244d avutil/log: Don't include avutil.h
It has been included since af5f434f8c
for deprecation reasons, but removing it has been forgotten after
it had served is purpose. So remove it.

For convenience, include version.h instead as LIBAVUTIL_VERSION_INT
is supposed to be used when creating AVClasses.

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-24 12:56:49 +01:00
Andreas Rheinhardt
12a540352b avformat/avio: Don't include common.h
Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-24 12:56:49 +01:00
Stephen Hutchinson
ce0000dc98 avformat/avisynth: remove framedata variable
It's just a simple index.

Addresses Coverity issue 1500290

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
2022-02-23 12:59:15 -05:00
Stephen Hutchinson
5df71a5e8d avformat/avisynth: remove unused variable 'frameprop'
Since the check got simplified and stdbool was no longer necessary
to include, neither is that variable.  Silences a warning.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
2022-02-23 12:59:11 -05:00
Jiasheng Jiang
9cf652cef4 avformat/nutdec: Add check for avformat_new_stream
Check for failure of avformat_new_stream() and propagate
the error code.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-23 14:13:16 +01:00
Pierre-Anthony Lemieux
12139d1103
avformat/imf: document IMFVirtualTrackResourcePlaybackCtx 2022-02-20 18:32:09 +10:00
Pierre-Anthony Lemieux
b0193e26ca
avformat/imf: fix packet pts, dts and muxing
The IMF demuxer does not set the DTS and PTS of packets accurately in all
scenarios. Moreover, audio packets are not trimmed when they exceed the
duration of the underlying resource.

imf-cpl-with-repeat FATE ref file is regenerated.

Addresses https://trac.ffmpeg.org/ticket/9611
2022-02-20 18:32:09 +10:00
Pierre-Anthony Lemieux
ef0d5245d6
avformat/imf: open resources only when first needed
IMF CPLs can reference thousands of files, which can result in system limits
for the number of open files to be exceeded. The following patch opens and
closes files as needed.

Addresses https://trac.ffmpeg.org/ticket/9623
2022-02-20 18:25:42 +10:00
Stephen Hutchinson
0d34e21282 avformat/avisynth: fix frameprop version check
Trying to be clever about determining between interface version 8
and 8.1 ended up with pre-8.1 versions of AviSynth+ segfaulting.

The amount of time between interface version 8.1 and 9 is small,
so just restrict the frameprop awareness to version 9 and call it
a day.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
2022-02-18 17:11:19 -05:00
Peter Ross
6474300dc4 avformat/utils: fix logic error in ff_mkdir_p
Fix ticket# 9605

Signed-off-by: Peter Ross <pross@xvid.org>
2022-02-16 08:21:58 +11:00
Michael Niedermayer
2db9ffb88b avformat/argo_cvg: Fix checksum
Reviewed-by: Zane van Iperen <zane@zanevaniperen.com>

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-15 21:36:08 +01:00
Michael Niedermayer
8ee0e4abcb avformat/mov: Corner case encryption error cleanup in mov_read_senc()
Fixes: memleak
Fixes: 42341/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-4566632823914496

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-15 21:25:43 +01:00
Wolfgang Müller
a67734596d avformat/id3v2: Add Grouping frame to id3v2.4 metadata table
The ID3v2.4.0 standard defines TIT1 as the "Content group description"
tag [1]. This frame is usually referred to as the "Grouping" tag and in
de-facto use under that name by Vorbis and APEv2 [2].

This commit introduces a mapping from "TIT1" to "grouping" in the
id3v2.4 metadata conversion table. This will enable software to access
it using that name. In particular, MPD will now read this tag correctly
when using the ffmpeg decoder plugin.

[1] https://id3.org/id3v2.4.0-frames (4.2.1)
[2] https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#grouping-3

Signed-off-by: Wolfgang Müller <wolf@oriole.systems>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-02-15 10:15:25 +01:00
Andreas Schneider
6f1e14ebed avformat/gnutls: Use the systems default crypto policy
We should use the systems crypto policy by default. If there is no
system policy, gnutls will use the "NORMAL" policy.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-02-15 10:15:25 +01:00
Stephen Hutchinson
af69e4c241 avisynth: use AviSynth+'s frame properties to set various fields
* Field Order
* Chroma Location
* Color Transfer Characteristics
* Color Range
* Color Primaries
* Matrix Coefficients

The existing TFF/BFF detection is retained as a fallback for
older versions of AviSynth that can't access frame properties.
The other properties have no legacy equivalent to detect them.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
2022-02-13 18:24:37 -05:00
emcodem
05c492eeb0 avisynth: corrected interlace detection
AviSynth works on frame-based video by default, which can
be either progressive or interlaced. Some filters can break
frames into half-height fields, at which point it considers
the clip to be field-based (avs_is_field_based can be used
to check for this situation).

To properly detect the field order of a typical video clip,
the frame needs to have been weaved back together already,
so avs_is_field_based should actually report 'false' when
checked.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
2022-02-13 18:24:33 -05:00
Limin Wang
e8f439631f avformat/udp: remove IPPROTO_IPV6 macro
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-02-12 08:41:55 +08:00
Limin Wang
268d00bb87 avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility
Suggested by zhilizhao, vlc project has solved the compatibility by
the same way, so I borrowed the comments from vlc project.

Fixes ticket #9449

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-02-12 08:41:55 +08:00
Limin Wang
c0817ee92e avformat/udp: use one setsockopt for ipv4/ipv6
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-02-12 08:41:55 +08:00
Limin Wang
1de24ee512 avformat/udp: properly check for valid ttl in url
Zhao Zhili added a ttl upper bound in commit 9daac85da8,
but the check for ttl in url is missing still.

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-02-12 08:41:55 +08:00
Justin Ruggles
0dd1ff67c8 http: Send a Range header even when the offset is 0
Using Range allows for getting the full file size from the
Content-Range header in the response, even if the server sends
back the response using chunked Transfer-Encoding, which does not
allow using Content-Length.
2022-02-11 11:31:38 +01:00
Justin Ruggles
c1228315c9 http: Improve handling of Content-Range with Transfer-Encoding:chunked
When Transfer-Encoding:chunked is used, the client must ignore a
Content-Length header, if present. However, it should not ignore a
Content-Range header, which also includes the full size of the
entity.
2022-02-11 11:31:38 +01:00
Gyan Doshi
b6bb6b9f22 avformat/mpegts: initialize max_packet_size when sub-demuxer
bca30570d2 added a user option to set max_packet_size replacing
a hardcoded value. This had a side-effect of leaving the field
set to 0 when packet demuxing is carried out from another demuxer
using avpriv functions, which could lead to demux failure.

Hardcoded max_packet_size inside avpriv_mpegts_parse_open to
2048000 to avoid this. Value chosen to be 10x that of default value
to accommodate large payloads.
2022-02-10 16:57:59 +05:30
Michael Niedermayer
bf33a38499 avformat/hls: Use unsigned for iv computation
Fixes: signed integer overflow: 9223372036854775748 + 60 cannot be represented in type 'long'
Fixes: 44417/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-5802443881971712

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:50:35 +01:00
Michael Niedermayer
5038933977 avformat/matroskadec: Check desc_bytes
Fixes: Division by 0
Fixes: 44035/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-4826721386364928

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:50:35 +01:00
Michael Niedermayer
59328aabd2 avformat/utils: Fix invalid NULL pointer operation in ff_parse_key_value()
Fixes: pointer index expression with base 0x000000000000 overflowed to 0xffffffffffffffff
Fixes: 44012/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-5670607746891776

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:50:35 +01:00
Michael Niedermayer
9c3d2cbb51 avformat/matroskadec: Fix infinite loop with bz decompression
The same check is added to zlib too, it seems not needed there though

Fixes: Infinite loop
Fixes: 43932/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-6175167573786624

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:49:05 +01:00
Michael Niedermayer
948c262099 avformat/utils: keep chapter monotonicity on chapter updates
Updating a chapter with the same id does not break monotonicity
Fixes: Timeout
Fixes: 43727/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-4960623367159808

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:26:35 +01:00
Gustav Grusell
e78d0810d1 avformat/hls: Implement support for using AVSEEK_FLAG_BACKWARD when seeking
Before, seeking in hls streams would always seek to the next keyframe
after the given timestamp. With this fix, if seeking in videostream and
AVSEEK_FLAG_BACKWARD is set, seeking will be to the first keyframe of
the segment containing the given timestamp. This fixes #7485.

Signed-off-by: Gustav Grusell <gustav.grusell@gmail.com>
2022-02-09 13:49:23 +08:00
Andreas Rheinhardt
70a90fb73e avcodec/internal.h: Move avpriv_find_start_code() to startcode.h
This is by definition the appropriate place for it.
Remove all the now unnecessary libavcodec/internal.h inclusions;
also remove other unnecessary headers from the affected files.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:22:14 +01:00
Andreas Rheinhardt
27f22f3383 all: Remove unnecessary libavcodec/internal.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:16:26 +01:00
Anton Khirnov
36117968ad lavf/async: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
70a1774f1a lavf/udp: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
5fe2c37734 lavf/swfenc: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
ea511196a6 lavf/mpegenc: switch to new FIFO API 2022-02-07 00:31:23 +01:00