Commit Graph

24502 Commits

Author SHA1 Message Date
Andreas Rheinhardt 707ad03096 avformat/movenc: Simplify creating chapter track extradata
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-11 18:08:31 +01:00
Jack Bruienne e6e3aae294 avformat: add DFPWM WAV container support
This commit adds support for storing DFPWM audio in a WAV container.
It uses the WAVEFORMATEXTENSIBLE structure, following these conventions:
https://gist.github.com/MCJack123/90c24b64c8e626c7f130b57e9800962c
The implementation is very simple: it just adds the GUID to the list of
WAV GUIDs, and modifies the WAV muxer to always use WAVEFORMATEXTENSIBLE
format with that GUID.

This creates a standard container format for DFPWM besides raw data.
It will allow users to transfer DFPWM audio in a standard container
format, with the sample rate and channel count contained in the file
as opposed to being an external parameter as in the raw format.

This format is already supported in my AUKit library, which is the CC
analog to libav (albeit much smaller). Support in other applications is TBD.

Signed-off-by: Jack Bruienne <jackbruienne@gmail.com>
2022-03-10 14:11:12 +01:00
Jack Bruienne 70fef2371c avformat: add DFPWM raw format
This patch builds on my previous DFPWM codec patch, adding a raw
audio format to be able to read/write the raw files that are most commonly
used (as no other container format supports it yet).

The muxers are mostly copied from the PCM demuxer and the raw muxers, as
DFPWM is typically stored as raw data.

Please see the previous patch for more information on DFPWM.

Signed-off-by: Jack Bruienne <jackbruienne@gmail.com>
2022-03-10 14:11:12 +01:00
Michael Niedermayer ec8ff659f5 avformat/avidec: Check height
Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
Fixes: Ticket8486

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-08 00:47:21 +01:00
Michael Niedermayer 15a646e501 avformat/rmdec: Better duplicate tags check
Fixes: memleaks
Fixes: 44810/clusterfuzz-testcase-minimized-ffmpeg_dem_IVR_fuzzer-5619494647627776

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-08 00:47:21 +01:00
Paul B Mahol 93dfb6afdd avformat/mpegtsenc: fix muxing pcm-bluray 2022-03-06 12:45:59 +01:00
Clément Bœsch 1a502b99e8 avformat/mov: reindent after previous commit 2022-03-04 15:50:51 +01:00
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