Commit Graph

1585 Commits

Author SHA1 Message Date
Michael Niedermayer 1cd4184020 avformat/mov: Check STCO location
Fixes: bypassing of checks and assertion failure
Fixes: asan_1003879.mp4

Found-by: Clusterfuzz + asan
Reported-by: Thomas Guilbert <tguilbert@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-30 19:58:45 +01:00
Andreas Rheinhardt 43f58f2354 avformat/mov: Don't leak MOVFragmentStreamInfo on error
Fixes Coverity issue #1441933.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-28 17:18:27 +01:00
Andreas Rheinhardt 3999c4b374 avformat/mov: Free encryption data on error
Fixes memleak and Coverity issue #1439587.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-28 17:18:27 +01:00
Gyan Doshi febd37f4bd avformat/mov: update extensions
Added all extensions used by the mov muxer family, except m4v which
is also used for raw MPEG-4 Part 2 bitstreams
2020-01-28 11:10:24 +05:30
Andreas Rheinhardt ad1b0a12f3 avformat/mov: Use AV_DICT_DONT_STRDUP_VAL to avoid av_strdup
This will likely also fix CID 1452574 and 1452565, false positives
resulting from Coverity thinking that av_dict_set() automatically
frees its key and value parameters (even without the
AV_DICT_DONT_STRDUP_* flags).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-10 17:52:14 +01:00
Andreas Rheinhardt 82d61a9ce3 avformat: Don't free old extradata before ff_alloc/get_extradata
These functions already free it themselves before they allocate the new
extradata.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-12 19:25:33 +01:00
Andreas Rheinhardt c1e439d7e9 avformat: Forward errors where possible
It is not uncommon to find code where the caller thinks to know better
what the return value should be than the callee. E.g. something like
"if (av_new_packet(pkt, size) < 0) return AVERROR(ENOMEM);". This commit
changes several instances of this to instead forward the actual error.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-12 19:25:33 +01:00
Andreas Rheinhardt 56ce2ad2cc avformat/mov: Use ff_alloc_extradata for dvdsub extradata
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: "mypopy@gmail.com" <mypopy@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-12 19:25:33 +01:00
Zhao Zhili 57db9f488f avformat/mov: fix typo in help text
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-11-16 20:57:45 +01:00
Jun Zhao 3dce89e55e lavf/mov: add log context dump in log message
add log context dump in log message.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-11-08 11:39:02 +08:00
Matthieu Bouron 1921f866ec avformat/mov: parse sdtp atom and set the pkt disposable flag accordingly
Allows the creation of the sdtp atom while remuxing MP4 to MP4. This
atom is required by Apple devices (iPhone, Apple TV) in order to accept
2160p medias.
2019-10-12 14:36:15 +02:00
Jun Li c23797bc33 lavf/mov: Fix timestamp rescale on sidx atom
Fix #5090
Fix the timestamp rescale issue, from sidx timebase to
stream's timebase.
2019-09-26 06:55:44 +08:00
Michael Niedermayer 093d1f4250 avformat/mov: Check for EOF in mov_read_meta()
Fixes: Timeout (195sec -> 2ms)
Fixes: 16735/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5090676403863552

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-17 14:41:07 +02:00
Andreas Rheinhardt 34bd293b01 avformat/mov: Fix memleak
When the mov/mp4 demuxer encounters an error during decrypting a packet,
it returns the error, yet doesn't free the packet, so that the packet
leaks. This has been fixed in this commit.

Fixes the memleaks from ticket #8150.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-17 14:41:07 +02:00
Paul B Mahol 428b4aacb1 avformat/mov: improve timecode calculation
Fixes timecode calculation for NTSC frame rates.
Fixes ticket #5978.
2019-08-28 16:27:58 +02:00
James Almer d1409fe952 avformat/mov: add demuxing support for Dolby TrueHD streams
Signed-off-by: James Almer <jamrial@gmail.com>
2019-08-24 22:41:58 -03:00
Gyan Doshi d51d71c1e3 avformat/mov: fix return code for trun box with no sample entries
A value of zero for sample_count in trun box is not
prohibited by 14496-12 section 8.8.8. 4a9d32baca
disallowed this which led the demuxer to error out
when reading the header of valid files.
2019-07-22 22:38:09 +05:30
Michael Niedermayer 696312c487 avformat/mov: Set fragment.found_tfhd only after TFHD has been parsed
Fixes: Assertion failure
Fixes: crbug971646.mp4

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-06-25 13:30:09 +02:00
Gyan Doshi 6223d076e3 avformat/mov: set AVFMT_SEEK_TO_PTS flag
Ever since 59ad504696, the demuxer expects its seek arg to be PTS
and adjusts internally to search index by DTS.
2019-05-03 10:18:53 +05:30
Michael Niedermayer 18a567c369 avformat/mov: Skip stsd adjustment without chunks
Fixes: Assertion failure
Fixes: clusterfuzz-testcase-minimized-media_pipeline_integration_fuzzer-5683096400822272

Found-by: Clusterfuzz
Reported-by: Dan Sanders <sandersd@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-24 17:05:02 +02:00
Dan Sanders 22c820f509 libavformat/mov: limit nb_frames_for_fps to INT_MAX
It's this or add overflow detection in mov_read_header().

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-23 22:13:34 +02:00
Michael Niedermayer ff13a92a6f avformat/mov: Fix potential integer overflow in entry check in mov_read_trun()
No testcase

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-03-25 13:20:30 +01:00
Carl Eugen Hoyos 4d8875ec23 lavf: Constify the probe function argument.
Reviewed-by: Lauri Kasanen
Reviewed-by: Tomas Härdin
2019-03-21 11:42:17 +01:00
Justin Ruggles 97f47fd601 mov: Fix start_time for streams with empty edits in the middle
Empty edits can occur at any position within the edit list except for at
the end. Empty edits in the middle should not impact the reported stream
start_time or the video PTS adjustment, so only include empty edits at
the start of the list in empty_edits_sum_duration.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2019-02-26 14:48:27 -05:00
Michael Niedermayer b0d8b7cb8e avformat/mov: Do not use reference stream in mov_read_sidx() if there is no reference stream
Fixes: NULL pointer dereference
Fixes: clusterfuzz-testcase-minimized-audio_decoder_fuzzer-5634316373721088

Reported-by: Chris Cunningham <chcunningham@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-14 21:55:43 +01:00
Charles Liu aa25198f1b avformat/mov: fix hang while seek on a kind of fragmented mp4
Binary searching would hang if the fragment items do NOT have timestamp for the
specified stream.

For example, a fmp4 consists of separated 'moof' boxes for each track, and
separated 'sidx' for each segment, but no 'mfra' box.  Then every fragment item
only have the timestamp for one of its tracks.

Example:
ffmpeg -f lavfi -i testsrc -f lavfi -i sine -movflags dash+frag_keyframe+skip_trailer+separate_moof -t 1 out.mp4
ffmpeg -ss 0.5 -i out.mp4 -f null none

Also fixes the hang in ticket #7572, but not the reason for having
AV_NOPTS_VALUE timestamps there.

Signed-off-by: Charles Liu <liuchh83@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-02-11 22:01:06 +01:00
James Almer 00fd38f184 avformat/mov: don't rescale mastering display values from the SmDm atom
Simplifies code.

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-02-11 16:58:27 -03:00
chcunningham 1c15449ca9 avformat/mov: validate chunk_count vs stsc_data
Bad content may contain stsc boxes with a first_chunk index that
exceeds stco.entries (chunk_count). This ammends the existing check to
include cases where chunk_count == 0. It also patches up the case
when stsc refers to unknown chunks, but stts has no samples (so we
can simply ignore stsc).

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-08 12:00:59 +01:00
chcunningham 3ea87e5d9e avformat/mov.c: require tfhd to begin parsing trun
Detecting missing tfhd avoids re-using tfhd track info from the previous
moof. For files with multiple tracks, this may make a mess of the
avindex and fragindex, which can later trigger av_assert0 in
mov_read_trun().

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-08 12:00:59 +01:00
Carl Eugen Hoyos 5d958f0955 lavf/mov: Do not fail hard for more invalid atoms.
This is what several other players do and what FFmpeg already does for the sidx atom.

Fixes ticket #7679.
2019-01-14 22:30:27 +01:00
Derek Buitenhuis 8f585c3c55 mov: Remove duration-of-last-frame heuristic hack
This breaks totally valid files that get caught in its heuristic.

This, according to the commit message, is my own doing, having asked
Michael to implement this check and providing a sample that was
"wrong". I am now atoning for my sins, and removing this hack, having
seen the light (aka that this was silly to do in the first place).

Resotores correct behavior on valid files.

This reverts commit 8e5e84c2a2.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2019-01-02 10:45:43 -05:00
Jacob Trimble 555f332e7a libavformat/mov: Fix NULL-dereference read for some encrypted content.
When reading frames, we need to use the fragment for the correct
stream.  Sometimes the "current" fragment is not the same as the one
the frame is for.

Found by Chromium's ClusterFuzz:
https://crbug.com/906392 and https://crbug.com/915524

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-20 23:32:36 +01:00
Michael Niedermayer 21f4b456f1 avformat/mov: Simplify get_stream_info_time()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-19 20:09:03 +01:00
Jan Ekström a1f0dd24f6 lavf/mov: document the dvh1 codec switch based on hvcC availability 2018-12-17 23:25:43 +02:00
chcunningham c9f7b6f7a9 lavf/mov: ensure only one tkhd per trak
Chromium fuzzing produced a whacky file with extra tkhds. This caused
an AVStream that was already in use to be corrupted by assigning it a
new id, which blows up later in mov_read_trun because the
MOVFragmentStreamInfo.index_entry now points OOB.

Reviewed-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-16 09:49:07 +01:00
Justin Ruggles d2047c14c0 Use QT format for audio sample descriptors depending on stsd version.
ISOBMFF does not allow AudioSampleEntryV1 in stsd version 0, so
assume the descriptor format is QTFF SoundDescriptionV1. ISOBMFF does
not define a version 2.

This fixes audio decoding for some MP4 files generated with Apple
tools. The additional fields present in SoundDescriptionV1/V2 need to
be read in order to correctly read additional boxes that contain
information required for decoding the stream.

Fixes #7376.

Also see: https://github.com/HandBrake/HandBrake/issues/1555

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2018-09-09 19:52:53 +01:00
John Stebbins 3318ac5b9a lavf/mov: factor out setting codec_id
Since it is performed in all cases now.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-09-08 19:08:35 -03:00
John Stebbins c9a992d931 lavf/mov: add AVCodecTag entry for GoPro metadata
This allows for validation of the track type

Signed-off-by: James Almer <jamrial@gmail.com>
2018-09-08 19:08:34 -03:00
Dale Curtis 320b631a99 avformat/mov: Error on too large stsd entry counts.
Entries are always at least 8 bytes per the parsing code, so if we
see an impossible entry count avoid massive allocations. This is
similar to an existing check in mov_read_stsc().

Since ff_mov_read_stsd_entries() does eof checks, an alternative
approach could be to clamp the entry count to atom.size / 8.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-09-01 19:26:40 +02:00
Dale Curtis e7080d1fe2 avformat/mov: Correct opus-in-mp4 pre-skip to be uint16_t versus int16_t.
This field is a uint16_t, see docs:
http://opus-codec.org/docs/opus_in_isobmff.html#4.3.2

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-08-23 16:00:26 +02:00
Jacob Trimble eb350ab738 avformat/mov: Allow saio/saiz in clear content.
If there is a saio/saiz in clear content, we shouldn't create the
encryption index if we don't already have one.  Otherwise it will
confuse the cenc_filter.

The changed method is also used for senc atoms, but they should not
appear in clear content.

Found by Chromium's ClusterFuzz: https://crbug.com/873432

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-08-22 18:54:23 +02:00
James Almer 8d5604a69a avformat/av1: update ff_isom_write_av1c() to the latest revision of the spec
This will get ISOBMFF and Matroska up to date with the revised AV1 Codec
Configuration Box spec.
For now keep propagating raw OBUs as extradata until all libavcodec modules
are adapted to handle AV1CodecConfigurationRecord formatted extradata.

Tested-by: Thomas Daede <bztdlinux@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-08-17 15:09:02 -03:00
Sasi Inguva 12673bb253 lavf/mov.c: Set start_time for all streams (in case of edit lists).
Fixes vorbis mp4 audio files, with edit list specified. Since
st->skip_samples is not set in case of vorbis , ffmpeg computes the
start_time as negative.

Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-08-11 02:37:42 +02:00
Carl Eugen Hoyos 6130068453 lavf/mov: Force HEVC codec_id for code-point dvh1 and an hvcC atom.
The mp4 registration authority accepted a code-point for Dolby Vision
HEVC that was already used as a fourcc for DVCPRO 100.

Fixes ticket #7347.
2018-08-09 00:44:07 +02:00
Michael Niedermayer a37c620269 avformat/mov: Check default_encrypted_sample before use in mov_read_sample_encryption_info()
Fixes: 2018-0721-sample
Fixes: null pointer dereference

Found-by: Nikita Knyzhov (knnikita@yandex.ru)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-26 02:42:42 +02:00
James Almer 9ca7ad246d avformat/mov: add support for AV1 streams
Signed-off-by: James Almer <jamrial@gmail.com>
2018-07-20 11:43:25 -03:00
Gyan Doshi 8aa6d9a8d3 avformat/mov: only set handler_name from mdia->hdlr
6 FATE references updated.

Fixes #7104
2018-07-16 21:33:01 +05:30
Michael Niedermayer b0644f7f72 avformat/mov: Simplify last element computation in mov_estimate_video_delay()
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-13 02:19:50 +02:00
Michael Niedermayer aba13dc13e avformat/mov: Break out of inner loop early in mov_estimate_video_delay()
0.266 <- 0.299 sec (this is time ffmpeg so containing alot other things)

Sample for benchmark was: ffmpeg -f rawvideo -pix_fmt yuv420p -s 32x32 -i /dev/zero -t 24:00:00.00 out.mp4

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-13 02:19:50 +02:00
Michael Niedermayer 3ce4034308 avformat/mov: Eliminate variable buf_size from mov_estimate_video_delay()
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-12 01:28:23 +02:00
Michael Niedermayer c995e01b1e avformat/mov: remove modulo operations from mov_estimate_video_delay()
0.324 <-0.491 sec

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-12 01:28:23 +02:00
Jacob Trimble 7e22f5d457 avformat/mov: Expose encryption info to the app.
This exposes encryption info from the container to the app.  This
includes key ID, IV, and subsample byte ranges.  The info is passed
using the new side-data AV_PKT_DATA_ENCRYPTION_DATA and
AV_PKT_DATA_ENCRYPTION_INIT_DATA.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-04 01:10:28 +02:00
Carl Eugen Hoyos a990184007 lavf/mov: Do not fail hard for truncated stsz atoms.
Fixes ticket #6433.
2018-06-19 22:48:04 +02:00
Michael Niedermayer 8176799f31 avformat/mov: Only set pkt->duration to non negative values
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-14 18:55:45 +02:00
Jacob Trimble 4aba45ca1f avformat/mov: Add check for per-sample IV size.
Found by Chrome's ClusterFuzz: http://crbug.com/849062.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-13 16:46:40 +02:00
Jacob Trimble cf81a9c078 avformat/mov: Fix reading saio/saiz for clear content.
This validates that the common encryption saio/saiz atoms only appear
when the data is actually encrypted.  This also ignores those atoms
in clear content.

Found by Chrome's ClusterFuzz: http://crbug.com/850389

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-09 20:44:50 +02:00
Sasi Inguva fe6c4f0c47 lavf/mov.c: Set st->start_time for video streams explicitly.
If start_time is not set, ffmpeg takes the duration from the global
movie instead of the per stream duration.
Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-06 01:53:30 +02:00
Sasi Inguva 318d0fcbfe lavf/mov.c: Fix timestamps to be strictly monotonic for video also.
We already do this for audio, but it should be done for video too.
If we don't, seeking back to the start of the file, for example, can
become quite broken, since the first N packets will have repeating
and nonmonotonic PTS, yet they need to be decoded even if they are
to be discarded.

Signed-off-by: Sasi Inguva <isasi@isasi.mtv.corp.google.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2018-06-05 16:00:19 +01:00
Jacob Trimble 9827bb88e7 libavformat/mov: Fix heap buffer overflow.
Found by Chrome's ClusterFuzz: https://crbug.com/847060

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-02 01:55:12 +02:00
Michael Niedermayer fe84f70819 avformat/mov: replace a value error by clipping into valid range in mov_read_stsc()
Fixes: #7165

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-22 21:05:45 +02:00
Michael Niedermayer 2c2d689c56 avformat/mov: Only fail for STCO/STSC contradictions if both exist
Fixes regression with playback of GF9720Repeal20the20Eighth20with20Helen20Linehan.m4a
See: crbug 822666

Found-by: "Mattias Wadman <mattias.wadman@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-21 01:50:21 +02:00
Michael Niedermayer 56e76bd057 avformat/mov: Break out early if chunk_count is 0 in mov_build_index()
Without this some operations might overflow (undefined behavior)
even though the index adding loop would never execute

No testcase known

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-21 01:38:56 +02:00
Derek Buitenhuis 28503c5aea mov: Properly abide by the track's media duration
The track's media duration from the mdhd atom takes precedence
over both the stts and elst atom for calculating and setting
the track's total duraion.

Technically, we shouldn't be using the stts atom at all for
calculating stream durations.

This fixes incorrect stream and final packet durations on files
with edit lists that are longer than the media duration.

The FATE changes are expected, and output is more correct (the
AAC frame is not 1028 samples).

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2018-04-26 14:42:15 +01:00
Jacob Trimble e5ba5fab49 avformat/mov: Fix parsing of saio/siaz atoms in encrypted content.
This doesn't support saio atoms with more than one offset.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-21 00:45:31 +02:00
Jacob Trimble baf9c0bd99 avformat/mov: Remove old encryption info methods.
Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-19 21:49:47 +02:00
Jacob Trimble 606c5c7f3a avformat/mov: Fix memory leak in encryption info.
Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-19 21:49:47 +02:00
Jacob Trimble f7221d8e67 avformat/mov: Increase support for common encryption.
- Parse schm atom to get different encryption schemes.
- Allow senc atom to appear in track fragments.
- Allow 16-byte IVs.
- Allow constant IVs (specified in tenc).
- Allow only tenc to specify encryption (i.e. no senc/saiz/saio).
- Use sample descriptor to detect clear fragments.

This doesn't support:
- Different sample descriptor holding different encryption info.
  - Only first sample descriptor can be encrypted.
- Encrypted sample groups (i.e. seig).
- Non-'cenc' encryption scheme when using -decryption_key.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-19 03:15:32 +02:00
Michael Niedermayer 0a8133119c avformat/mov: Fix extradata memleak
Fixes: crbug 822705

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-12 23:52:59 +02:00
Jacob Trimble b08c132a9c avformat/mov: Fix parsing of tfdt when using sample descriptors.
Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-05 20:10:24 +02:00
Timo Teräs 8c980b1c92 avformat/mov: parse multiple iTunes cover images
Multiple cover images are supported by having multiple data atoms
inside the covr atom. AtomicParsley and mutagen amongst others
support and document this construct.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-01 02:58:51 +02:00
Michael Niedermayer eb60b9d3aa avformat/mov: Move +1 in check to avoid hypothetical overflow in add_ctts_entry()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-26 02:16:48 +02:00
Michael Niedermayer 9e67447a4f avformat/mov: Check STSC and remove invalid entries
Fixes assertion failure
Fixes: crbug 822547, crbug 822666 and crbug 823009

Affects: aark15sd_9A62E2FA.mp4

Found-by: ClusterFuzz
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-20 22:59:40 +01:00
Michael Niedermayer 2f37082827 avformat/mov: Fix integer overflows related to sample_duration
Fixes: runtime error: signed integer overflow: -9166684017437101870 + -2495066639299164439 cannot be represented in type

Fixes: Chromium bug 791349

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-12 01:32:42 +01:00
Sasi Inguva 43205df645 lavf/mov.c: Use the correct offset to shift timestamp when seeking.
Fixes seek for files with empty edits and files with negative ctts
(dts_shift > 0). Added fate samples and tests.

Signed-off-by: Sasi Inguva <isasi@isasi.mtv.corp.google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-10 17:55:50 +01:00
James Almer c4cee26129 avformat/mov: print the projection type when reporting it as unsupported
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-09 12:17:53 -03:00
Xiaohan Wang 3386be16d5 ffmpeg: Fix stts_data memory allocation
In this loop, |i| is the "index". And the memory allocated should be at
least the current "count", which is |i + 1|.

BUG=801821

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-09 02:39:21 +01:00
Michael Niedermayer 367929bed9 avformat/mov: Fix integer overflow in mov_get_stsc_samples()
Fixes: runtime error: signed integer overflow: 5 * -2147483647 cannot be represented in type 'int'
Fixes: Chromium bug 817338
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Reported-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-07 20:37:33 +01:00
Matt Wolenetz 133ddd3875 avformat/mov: Initialize a potential gap in ctts_data in mov_build_index
mov_read_ctts ignores ctts entries having count <= 0. Generally, the
aggregate of all ctts entries' count fields resulting from mov_read_ctts
can be less than the corresponding sample_count.

mov_build_index attempts to normalize any existing ctts_data counts to
be 1, to make a 1-1 mapping of a ctts_data entry to a sample.

That 1-1 mapping left a tail of uninitialized ctts_data entries when the
aggregate, normalized ctts_count < sample_count.

Even more generally, later usage of ctts_data may depend on the entire
ctts_allocated_size having been initialized.

This change memsets the entire allocation of the normalized ctts_data in
mov_build_index, to prevent use of uninitialized data later.

BUG=816787

Change-Id: I7fd7db255e3aeed076ee32c90cb2df211741c052
Reviewed-on: https://chromium-review.googlesource.com/947110
Reviewed-by: Xiaohan Wang <xhwang@chromium.org>

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-05 01:16:34 +01:00
Tianqiang Liu 5df9d75b44 avformat/mov: Add manu/modl to mov_read_udta_string.
Documentation: http://mp4ra.org/atoms.html

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-03 23:01:41 +01:00
Xiaohan Wang f5f2209d68 ffmpeg: Fix memset size on ctts_data in mov_read_trun() (round 2)
The allocated size of sc->ctts_data is
(st->nb_index_entries + entries) * sizeof(*sc->ctts_data).

The size to memset at offset sc->ctts_data + sc->ctts_count should be
(st->nb_index_entries + entries - sc->ctts_count) *
sizeof(*sc->ctts_data))

The current code missed |entries| I believe, which was introduced in
https://patchwork.ffmpeg.org/patch/5541/.

However, after offline discussion, it seems the original code is much
more clear to read (before https://patchwork.ffmpeg.org/patch/5541/).

Hence this CL revert the memset logic to it's previous state by
remembering the |old_ctts_allocated_size|, and only memset the newly
allocated entries.

BUG=812567

Change-Id: Ibe94c7138e5818bfaae76866bfa6619a9b8a2b6b
Reviewed-on: https://chromium-review.googlesource.com/934925
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-01 22:54:49 +01:00
Xiaohan Wang dd5208aaf5 avformat/mov: Fix ctts_index calculation
An index should never be equal to the count. Hence we must make sure
*ctts_index < ctts_count.

Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-02-10 03:57:13 +01:00
James Almer f7aacf4ab7 avformat/mov: add VP8 codec support
Demuxing only. Muxing is disabled as altref frame handling is not
defined in the spec, and there's no way to know the presence of
such frames during stream initialization.

Based on a patch by Steven Liu.

Fixes ticket #7000

Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-06 23:08:42 -03:00
Marton Balint 18ac642359 avformat: migrate to AVFormatContext->url
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Carl Eugen Hoyos 1112ba012d lavf/mov: Use av_fast_realloc() in mov_read_stts().
Avoids large allocations for short files with invalid stts entry.
Fixes bugzilla 1102.
2018-01-01 22:27:29 +01:00
James Almer bc10260f49 avformat/mov: simplify parsing of mdcv atom using av_make_q()
Signed-off-by: James Almer <jamrial@gmail.com>
2017-12-21 01:23:17 -03:00
Sasi Inguva 58a25aeb8e lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.
Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-20 22:27:06 +01:00
Michael Niedermayer 74f408cc8e avformat/mov: Fix the the typo
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-18 19:57:43 +01:00
tiejun.peng 6bf5d69b2f lavf/mov: modify code indentation
Signed-off-by: tiejun.peng <tiejun.peng@foxmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-09 23:12:30 +01:00
tiejun.peng ab651587a7 lavf/mov: add some useful warning log of eof
Signed-off-by: tiejun.peng <tiejun.peng@foxmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-09 23:12:30 +01:00
Carl Eugen Hoyos 894f1c399b lavf/mov: Fix missing newline. 2017-12-04 04:15:49 +01:00
John Stebbins 2d015d3bf9 lavf/mov: fix huge alloc in mov_read_ctts
An invalid file may cause huge alloc.  Delay expansion of ctts entries
until the number of samples is known in mov_build_index.

Fixes: 23

Found-by: zhao dongzhuo, AD-lab of Venustech
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-01 00:07:30 +01:00
Pan Bian f63450c8e4 avformat/mov: return correct value in mov_read_cmov
On some failure paths, the error code is not correctly set.

Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-28 21:42:48 +01:00
Pan Bian 3f81259f33 avformat/mov: set correct error code in mov_read_custom
In function mov_read_custom(), it returns 0 on the path that av_malloc()
returns a NULL pointer. 0 indicates success. An error code should be
assigned to ret.

Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-28 21:42:48 +01:00
Vittorio Giovara 10db42f117 mov: Support mdcv and clli boxes for mastering display an color light level
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-11-28 12:40:40 -05:00
Michael Niedermayer 883de7e8b4 libavformat/mov: Replace duplicate stream_nb check by assert
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-27 03:31:54 +01:00
John Stebbins bdddcb7b03 lavf/mov: fix crash in mov_read_sidx
Use correct index into streams

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-25 02:32:33 +01:00
Carl Eugen Hoyos 8b62647a5f lavf/mov: Read aspect ratio from AVID jpeg2000 mov files. 2017-11-23 02:57:24 +01:00
Dale Curtis 6db511a783 avformat/mov: Increment stsd_count while processing stsd data; avoids leaks.
In the event of ff_mov_read_stsd_entries() failure, sc->stsd_count
is not updated, even if the function allocates extradata memory.
Instead update the sc->stsd_count as entries are parsed so that
mov_read_close() can do the right thing.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-22 13:06:50 +01:00
Jacob Trimble 2d9cf3bf16 avformat/mov: Propagate errors in mov_switch_root.
Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-21 03:13:03 +01:00
Carl Eugen Hoyos 0f75d77a16 lavf/mov: Do not mix variable declaration and code.
Fixes a warning:
libavformat/mov.c:1195:5: warning: ISO C90 forbids mixed declarations and code
2017-11-20 13:48:28 +01:00
John Stebbins 20c38f2e70 lavf/mov: don't read outside frag_index bounds
Potentially fixes:
https://bugs.chromium.org/p/chromium/issues/detail?id=786269#c1

In theory, the crash can be triggered by an invalid stream that has
either tfdt or trun outside of the moof

Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-18 11:57:57 +01:00
Dale Curtis d073be2291 Fix leak of frame_duration_buffer in mov_fix_index().
Should be unconditionally freed at the end of mov_fix_index() in
case it hasn't been used during the fix up.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Sasi Inguva <isasi-at-google.com@ffmpeg.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-18 11:57:57 +01:00
Fredrik Hubinette a6fdd75fe6 avformat/mov: Check size of STSC allocation
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-16 23:26:36 +01:00
Sasi Inguva 54f8ac199f lavf/mov.c: Don't correct edit list start to zero, when we can't find a frame before edit list start.
After c2a8f0fcbe this can happen on normal edit lists starting on a B-frame.

Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-14 21:02:31 +01:00
Sasi Inguva bc50961731 lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.
Partially fixes t/6699.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-11 14:15:15 +01:00
James Almer 73198aca2c Merge commit 'defe307fb22beca60a632e976ab97e5edd4aee25'
* commit 'defe307fb22beca60a632e976ab97e5edd4aee25':
  mov: move stsd finalization to an appropriate place
  mov: Do not set stsd_count if mov_read_stsd() fails
  mov: log and return early on non-positive stsd entry counts

See 8b43ee4054
656feb641d

Merged-by: James Almer <jamrial@gmail.com>
2017-11-11 00:28:53 -03:00
Sasi Inguva c2a8f0fcbe lavf/mov.c: Refine edit list start seek, based on PTS computed from CTTS.
Partially fixes t/6699.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-04 05:05:03 +01:00
Jonas Licht 59ad504696 libavformat/mov.c: use calculated dts offset when seeking in streams
Subtract the calculated dts offset from the requested timestamp before
seeking. This fixes an error "Error while filtering: Operation not
permitted" observed with a short file which contains only one key frame
and starts with negative timestamps.

Then, av_index_search_timestamp() returns a valid negative timestamp,
but mov_seek_stream bails out with AVERROR_INVALIDDATA.

Fixes ticket #6139.

Signed-off-by: Jonas Licht <jonas.licht@fem.tu-ilmenau.de>
Signed-off-by: Peter Große <pegro@friiks.de>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-10-30 01:09:40 +01:00
Sasi Inguva 8013753113 lavf/mov.c: Fix parsing of edit list atoms with invalid elst entry count.
Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-10-28 20:24:04 +02:00
James Almer 4bb09bf5a0 Merge commit '604fbb3132e88727e496c96c92cfe02748c25a1a'
* commit '604fbb3132e88727e496c96c92cfe02748c25a1a':
  mov: Move code shared with CAF to a separate file

Merged-by: James Almer <jamrial@gmail.com>
2017-10-26 15:21:59 -03:00
John Stebbins 4a9d32baca mov: fix decode of fragments that overlap in time
When keyframe intervals of dash segments are not perfectly aligned,
fragments in the stream can overlap in time. The previous sorting by
timestamp causes packets to be read out of decode order and results
in decode errors.

Insert new "trun" index entries into index_entries in the order that
the trun are referenced by the sidx.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-10-23 12:41:04 +02:00
Dale Curtis a5fd8aa45b avformat/mov: Set start_pad correctly in mov_fix_index()
Sets the correct start padding value when an edit list is present.

A new fate test is added, fate-mov-440hz-10ms, to ensure this is
handled correctly.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Sasi Inguva <isasi-at-google.com@ffmpeg.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-10-21 03:12:43 +02:00
James Almer 552d2cb6f7 Merge commit '0f8512c4a87b89b4694053d8ffda48066ee1da62'
* commit '0f8512c4a87b89b4694053d8ffda48066ee1da62':
  mov: Validate spherical metadata version

Merged-by: James Almer <jamrial@gmail.com>
2017-10-17 15:27:43 -03:00
James Almer 9780d5839e Merge commit '236577230051ad61ec67fa2d68e817d54232d2a0'
* commit '236577230051ad61ec67fa2d68e817d54232d2a0':
  mov: Ignore old spherical metadata when newer version is present

Merged-by: James Almer <jamrial@gmail.com>
2017-10-17 15:26:27 -03:00
Pablo Montilla 1015982f45 lavf/mov: Allow reading very large files.
The Sample count in the time-to-sample table is defined as
32-bit unsigned integer by the QT specification.

Fixes ticket #6700.
2017-09-28 23:46:57 +02:00
James Almer d99c3af707 Merge commit 'b446f0e98f85e2e931b476e52b319f1c49244660'
* commit 'b446f0e98f85e2e931b476e52b319f1c49244660':
  mov: Do not try to parse multiple stsd for the same track

See 8b43ee4054

Merged-by: James Almer <jamrial@gmail.com>
2017-09-28 00:10:42 -03:00
James Almer b35f6d3aa3 Merge commit '53ea595eec984e3109310e8bb7ff4b5786d91057'
* commit '53ea595eec984e3109310e8bb7ff4b5786d91057':
  mov: Rework stsc index validation

See e26e6240b6.

Merged-by: James Almer <jamrial@gmail.com>
2017-09-27 20:43:17 -03:00
James Almer a6596831a0 Merge commit '708e84cda1bdbffb92847f3d6ccf6fbeb26d9948'
* commit '708e84cda1bdbffb92847f3d6ccf6fbeb26d9948':
  mov: Avoid memcmp of uninitialised data

Merged-by: James Almer <jamrial@gmail.com>
2017-09-26 14:48:22 -03:00
Michael Niedermayer 9cb4eb7728 avformat/mov: Fix DoS in read_tfra()
Fixes: Missing EOF check in loop
No testcase

Found-by: Xiaohei and Wangchu from Alibaba Security Team
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-09-07 15:19:22 +02:00
Daniel Glöckner feb1dbc7bd avformat/mov: prevent duplication of first fragment's ctts_data
MP4 files with fragments might have the first moof box that is mentioned
in a fragment index before the first mdat box. Since it is then already
parsed by mov_read_header, we have to make sure that mov_switch_root
will not parse it again when seeking by setting the headers_read flag in
the index. Parsing it a second time would cause the ctts_data array to
receive a second copy of the information from the trun box, leading to
wrong PTS values for the second and following fragments in presence of
B-frames.

Fixes ticket 6560.

Signed-off-by: Daniel Glöckner <daniel-gl@gmx.net>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-09-01 00:56:32 +02:00
Dale Curtis f1e47f8713 avformat/mov: Bail when invalid sample data is present.
ctts data in ffmpeg relies on the index entries array to be 1:1
with samples... yet sc->sample_count can be read directly from
the 'stsz' box and index entries are only generated if a chunk
count has been read from 'stco' box.

Ensure that if sc->sample_count > 0, sc->chunk_count is too as
a basic sanity check. Additionally we need to check that after
the index is built we have the right number of entries, so we
also check in mov_read_trun() that sc->sample_count ==
st->nb_index_entries.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-09-01 00:56:32 +02:00
Dale Curtis 37e8edc9f5 avformat/mov: Fix trampling of ctts during seeks when sidx support is enabled.
When sidx box support is enabled, the code will skip reading all
trun boxes (each containing ctts entries for samples inthat box).

If seeks are attempted before all ctts values are known, the old
code would dump ctts entries into the wrong location. These are
then used to compute pts values which leads to out of order and
incorrectly timestamped packets.

This patch fixes ctts processing by always using the index returned
by av_add_index_entry() as the ctts_data index. When the index gains
new entries old values are reshuffled as appropriate.

This approach makes sense since the mov demuxer is already relying
on the mapping of AVIndex entries to samples for correct demuxing.

As a result of this all ctts entries are now 1-count. A followup
change will be submitted to remove support for > 1 count entries
which will simplify seeking.

Notes for future improvement:
Probably there are other boxes (stts, stsc, etc) that are impacted
by this issue... this patch only attempts to fix ctts since it
completely breaks packet timestamping.

This patch continues using an array for the ctts data, which is not
the most ideal given the rearrangement that needs to happen (via
memmove as new entries are read in). Ideally AVIndex and the ctts
data would be set-type structures so addition is always worst case
O(lg(n)) instead of the O(n^2) that exists now; this slowdown is
noticeable during seeks.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-08-24 11:02:22 +02:00
Vitaly Buka 4a404cb5b9 avformat/mov: Fix signed integer overflows with total_size
Signed integer overflow is undefined behavior.
Detected with clang and -fsanitize=signed-integer-overflow

Signed-off-by: Vitaly Buka <vitalybuka@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-08-23 03:17:11 +02:00
Jacob Trimble f4544163b2 libavformat/mov: Fix inserting frames before current_frame.
When using streaming input, it may be possible to see frames that appear
before the current_frame.  When these frames are inserted into the
index, the current_frame needs to be updated so it is still pointing
at the same frame.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-08-18 03:02:11 +02:00
Nikolas Bowe 4b54d5a721 avformat/mov: Fix memory leak when reading DDTS box.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-08-16 03:35:13 +02:00
Sean McGovern defe307fb2 mov: move stsd finalization to an appropriate place
mov_finalize_stsd_codec() parses stream information from the ALAC extradata,
so run it after the extradata processing is completed in mov_read_stsd().

Fixes playback of 96kHz ALAC streams muxed by qaac or the reference alac encoder.

Adapted from an FFmpeg patch by Hendrik Leppkes <h.leppkes@gmail.com>

Bug-Id: 1072
2017-07-31 17:41:01 -04:00
Sean McGovern 3050dabaa9 mov: Do not set stsd_count if mov_read_stsd() fails
Based on an FFmpeg patch by Michael Niedermayer <michael@niedermayer.cc>
2017-07-31 17:41:01 -04:00
Sean McGovern d7bdab1ad7 mov: log and return early on non-positive stsd entry counts
Based on an FFmpeg patch by Michael Niedermayer <michael@niedermayer.cc>
2017-07-30 10:51:12 -04:00
James Almer e3887c0a2c avformat/mov: add support for reading VP Codec Configuration Box
As defined in "VP Codec ISO Media File Format Binding v1.0"
https://github.com/webmproject/vp9-dash/blob/master/VPCodecISOMediaFileFormatBinding.md

Signed-off-by: James Almer <jamrial@gmail.com>
2017-06-11 15:28:34 -03:00
Sasi Inguva 93db5e3fc4 lavf/mov.c: offset index timestamps by the minimum pts to make first pts zero
If the videos starts with B frame, then the minimum composition time
as computed by stts + ctts will be non-zero. Hence we need to shift
the DTS, so that the first pts is zero. This was the intention of that
code-block. However it was subtracting by the wrong amount.

For example, for one of the videos in the bug nonFormatted.mp4 we have

stts:
sample_count  duration
960           1001

ctts:
sample_count  duration
1             3003
2             0
1             3003
....

The resulting composition times are :  3003, 1001, 2002, 6006, ...

The minimum composition time or PTS is 1001, which should be used to
offset DTS. However the code block was wrongly using ctts[0] which is
3003. Hence the PTS was negative. This change computes the minimum pts
encountered while fixing the index, and then subtracts it from all the
timestamps after the edit list fixes are applied.

Samples files available from:

https://bugs.chromium.org/p/chromium/issues/detail?id=721451
https://bugs.chromium.org/p/chromium/issues/detail?id=723537

fate-suite/h264/twofields_packet.mp4 is a similar file starting with 2
B frames. Before this change the PTS of first two B-frames was -6006
and -3003, and I am guessing one of them got dropped when being decoded
and remuxed  to the framecrc before, and now it is not being dropped.

Signed-off-by: Sasi Inguva <isasi@google.com>
2017-06-09 18:13:33 +02:00
James Almer 24133973fc avformat/mov: add support for reading Content Light Level Box
As defined in "VP Codec ISO Media File Format Binding v1.0"
https://github.com/webmproject/vp9-dash/blob/master/VPCodecISOMediaFileFormatBinding.md

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-27 16:14:24 -03:00
James Almer ab05bd6e6c avformat/mov: add support for reading Mastering Display Metadata Box
As defined in "VP Codec ISO Media File Format Binding v1.0"
https://github.com/webmproject/vp9-dash/blob/master/VPCodecISOMediaFileFormatBinding.md

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-27 16:09:55 -03:00
Matthieu Bouron ab61b79b1c lavf/mov: make invalid m{d,v}hd time_scale default to 1 instead of erroring out
Some samples have their metadata track time_scale incorrectly set to 0
and the check introduced by a398f054fd
prevents playback of those samples. Setting the time_scale to 1 fixes
playback.
2017-05-20 12:56:35 +02:00
Clément Bœsch e166fe2e1f Merge commit '46191a2da16f751e53d93646ae1388d421d12bee'
* commit '46191a2da16f751e53d93646ae1388d421d12bee':
  mov: fix a possible invalid read in mov_read_mac_string()

Merged-by: Clément Bœsch <u@pkh.me>
2017-04-29 12:46:48 +02:00
Carl Eugen Hoyos c6aaf0840c lavf/mov: Only copy extradata if it exists.
Avoids undefined call of memcpy(ptr, NULL, 0);
2017-04-19 23:33:47 +02:00
Matthew Gregan 3041b5d03b avformat/mo: Add experimental demuxing support for Opus in ISO BMFF (MP4).
Based on the draft spec at http://vfrmaniac.fushizen.eu/contents/opus_in_isobmff.html

Signed-off-by: Matthew Gregan <kinetik@flim.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-04-11 21:28:52 +02:00
Thierry Foucu ac24a8202a libavformat/mov: Fix memory leak, need to free the chapter tracks array
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-04-06 04:05:04 +02:00
Michael Niedermayer 39ee3ddff8 avformat/mov: Check creation_time for overflow
Fixes integer overflow
Fixes: 701640

Found-by: Found-by: Thomas Guilbert <tguilbert@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-04-04 00:56:21 +02:00
Diego Biurrun 604fbb3132 mov: Move code shared with CAF to a separate file 2017-04-03 13:50:00 +02:00
Sasi Inguva ef71dc7948 lavf/mov.c: Add -advanced_editlist option for mov format.
Adding an MOV format option to turn on/off the editlist supporting code, introduced in ca6cae73db

Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-31 13:59:21 +02:00
Michael Niedermayer 77a3c288bd avformat/mov: Init ref_sc / ref_st to NULL
This is more robust in case some change or corner case causes them to be
dereferenced before being set

Fixes CID1396274, CID1396275

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-30 23:35:18 +02:00
Clément Bœsch 549045254c Fix all -Wformat warnings raised by DJGPP 2017-03-29 14:49:29 +02:00
Clément Bœsch bec96a7286 lavf: use av_fourcc2str() where appropriate 2017-03-29 14:49:29 +02:00
wm4 ddef3d902f avformat, ffmpeg: deprecate old rotation API
The old "API" that signaled rotation as a metadata value has been
replaced by DISPLAYMATRIX side data quite a while ago.

There is no reason to make muxers/demuxers/API users support both. In
addition, the metadata API is dangerous, as user tags could "leak" into
it, creating unintended features or bugs.

ffmpeg CLI has to be updated to use the new API. In particular, we must
not allow to leak the "rotate" tag into the muxer. Some muxers will
catch this properly (like mov), but others (like mkv) can add it as
generic tag. Note applications, which use libavformat and assume the
old rotate API, will interpret such "rotate" user tags as rotate
metadata (which it is not), and incorrectly rotate the video.

The ffmpeg/ffplay tools drop the use of the old API for muxing and
demuxing, as all muxers/demuxers support the new API. This will mean
that the tools will not mistakenly interpret per-track "rotate" user
tags as rotate metadata. It will _not_ be treated as regression.

Unfortunately, hacks have been added, that allow the user to override
rotation by setting metadata explicitly, e.g. via

  -metadata:s:v:0 rotate=0

See references to trac #4560. fate-filter-meta-4560-rotate0 tests this.
It's easier to adjust the hack for supporting it than arguing for its
removal, so ffmpeg CLI now explicitly catches this case, and essentially
replaces the "rotate" value with a display matrix side data. (It would
be easier for both user and implementation to create an explicit option
for rotation.)

When the code under FF_API_OLD_ROTATE_API is disabled, one FATE
reference file has to be updated (because "rotate" is not exported
anymore).

Tested-by: Michael Niedermayer <michael@niedermayer.cc>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-27 13:20:27 +02:00
James Almer d054069c15 avformat/mov: stop using deprecated codec flags
Signed-off-by: James Almer <jamrial@gmail.com>
2017-03-25 21:37:40 -03:00
Clément Bœsch 46f4f8ad86 Merge commit '1263b2039eb5aaf1522e9de9f07c787ab30a5f50'
* commit '1263b2039eb5aaf1522e9de9f07c787ab30a5f50':
  Adjust printf conversion specifiers to match variable signedness

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-24 13:34:39 +01:00
Clément Bœsch 1436769c57 Merge commit 'ca1e5eea0c7b72a6e30aa6488cfeced3a4853521'
* commit 'ca1e5eea0c7b72a6e30aa6488cfeced3a4853521':
  Remove some pointless TRACE level debug code

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-24 13:23:52 +01:00
Clément Bœsch 30ac66abf0 Merge commit '4b07ebf1eb13561492f7e3c30a67f34415016b3e'
* commit '4b07ebf1eb13561492f7e3c30a67f34415016b3e':
  mov: Update colr values

Mostly noop, see a3cab3d433

Only the use of av_color_{primaries,transfer,space}_name() is merged.

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-24 11:33:47 +01:00
Vittorio Giovara 5f90ad99bb spherical: Change types of bounding and pad to uint32_t
These values are defined to be 32bit in the specification,
so it makes more sense to store them as fixed width.

Based on a patch by Micahel Niedermayer <michael@niedermayer.cc>.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-03-23 10:09:18 +01:00
James Almer 4de591e6fb Merge commit '83548fe894cdb455cc127f754d09905b6d23c173'
* commit '83548fe894cdb455cc127f754d09905b6d23c173':
  lavf: fix usage of AVIOContext.seekable

Merged-by: James Almer <jamrial@gmail.com>
2017-03-21 17:02:30 -03:00