Commit Graph

1935 Commits

Author SHA1 Message Date
Michael Niedermayer
5c46fdf305 avformat/utils: Check rfps_duration_sum for overflow
Fixes: signed integer overflow: 9151595917793558550 + 297519050751678697 cannot be represented in type 'long'
Fixes: 15496/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5722866475073536

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-07-19 21:42:38 +02:00
Michael Niedermayer
f57e97dfd9 avformat/utils: Check timebase before use in estimate_timings()
Fixes: division by 0
Fixes: 15480/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5746727434321920

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-07-08 09:56:09 +02:00
Jun Zhao
9521d7dd58 lavf/utils: Respect default disposition when select the AVStream
Respect default disposition when select the AVStream

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-07-03 10:33:31 +08:00
Marton Balint
f9271d0158 avformat/utils: fix stream ordering for program ID stream specifiers
Fixes a regression introduced in dbfd042983.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-05-24 21:39:07 +02:00
Marton Balint
c61d16cf3b Revert "lavf/utils: Allow url credentials to contain a slash."
This reverts commit dd06f022b0.

Fixes ticket #7871 and reopens ticket #7816.

The introduced regression caused URL's with @ in them to be parsed incorrectly
which is a bigger issue then not being able to specify the slash character as a
password.

I think there are better ways to fix the original issue, like being able to
specify HTTP username and password as a protocol option, or adding a protocol
option to percent-decode the URL first.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-05-18 17:07:21 +02:00
Andreas Hakon
e750dc9de6 libavformat: improve logs with cur_dts
This patch improves the logs when the message "cur_dts is invalid" appears.
If helps to identify which stream generates the trouble,
and the status of the stream.
A lot of users suffers with the message, and the origin varies.
The improved message can help to discover the cause.

Signed-off-by: Andreas Hakon <andreas.hakon@protonmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-19 17:14:44 +02:00
Carl Eugen Hoyos
dd06f022b0 lavf/utils: Allow url credentials to contain a slash.
Fixes ticket #7816.
2019-04-19 13:56:19 +02:00
Carl Eugen Hoyos
3aa6208db9 lavf: Constify AVInputFormat pointer. 2019-03-20 18:52:38 +01:00
Marton Balint
57580e2ab6 avformat/utils: fix indentation
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-03-01 22:31:00 +01:00
Marton Balint
d4ae28e494 avformat/utils: be even more strict about stream specifiers
After this change we always parse the full specifier even if we know the result
in the middle of the parsing. Sligtly slower, but this is needed to
consistently reject incorrect specifiers in both matching and non-matching
cases.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-03-01 22:31:00 +01:00
Marton Balint
24e0e149ad avformat/utils: be more strict about stream specifiers
This reworks the code to be more strict about accepting stream specifiers. From
now on we strictly enforce the syntax in the documentation up until the
decisive part of the stream specifier. Therefore matching stream specifiers
always need to be correct, non matching specifiers only need to be correct
until the decisive part.

Also recursion is changed to a simple loop.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-03-01 22:31:00 +01:00
Marton Balint
dbfd042983 avformat/utils: parse some stream specifiers recursively
This removes lots of code duplication and also allows more complex specifiers,
for example you can use p:204:aⓂ️language:eng to select the English language
audio stream from program 204.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-02-13 23:21:53 +01:00
Paul B Mahol
102c11745e avformat/utils: add support for reading ID3 tags at start of wav
Fixes #4140.
2018-12-13 10:01:15 +01:00
Michael Niedermayer
079d1a7175 avformat/utils: Never store negative values in last_IP_duration
Fixes: integer overflow compute_pkt_fields()
Fixes: compute_pkt_usan

Reported-by: Thomas Guilbert <tguilbert@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-18 02:28:54 +02:00
Michael Niedermayer
4e19cfcfa3 avformat/utils: Fix integer overflow in discontinuity check
Fixes: signed integer overflow: 7738135736989908991 - -7954308516317364223 cannot be represented in type 'long'
Fixes: find_stream_info_usan

Reported-by: Thomas Guilbert <tguilbert@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-18 02:28:54 +02:00
Michael Niedermayer
0a41a8bf29 avformat/utils: Fix potential integer overflow in extract_extradata()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-07 03:03:09 +02:00
Michael Niedermayer
b4a1ccfc41 avformat/utils: Do not use "i" as a context pointer, "i" is normally the integer counter in loops
This avoids surprising developers. Its bad to surprise developers with
such unexpected things.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-07 03:03:09 +02:00
Michael Niedermayer
beb3aea48e avformat/utils: Do not ignore failure in extract_extradata_init()
We check for the documented explanation of the "Ignore code" in extract_extradata_check() already

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-07 03:03:09 +02:00
Steven Liu
bb660800a5 avformat/utils: move mkdir_p to utils
Because it will be used by avformat/segment.c or other module which
need to automatically create sub-directories operation.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2018-09-25 21:57:49 +08:00
Baptiste Coudurier
dc58e33dd3 avformat/utils: set AV_PKT_FLAG_KEY for data packets 2018-09-24 13:51:13 -07:00
Dale Curtis
8ef7fb86d6 avformat/utils: Don't calculate duration using AV_NOPTS_VALUE for start_time.
Found by ClusterFuzz, https://crbug.com/879852

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-09-09 12:01:07 +02:00
Fredrik Hubinette
5ecd580953 avformat/utils: avoid undefined integer overflow behavior in update_stream_timings()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-08-22 18:54:23 +02:00
Gyan Doshi
02741853d7 avformat: correct fdebug loglevel
fftools/cmdutils sets loglevel for fdebug to DEBUG but all fdebug output
except for two were emitted at TRACE.
2018-08-14 22:06:30 +05:30
Vishwanath Dixit
f09635f2a2 avformat/utils: function to get the formatted ntp time
This utility function creates 64-bit NTP time format as per the RFC
5905.
A simple explaination of 64-bit NTP time format is here
http://www.beaglesoft.com/Manual/page53.htm
2018-05-29 09:31:29 +05:30
Aman Gupta
2b2f2f65f3 avformat: add fields to AVProgram/AVStream for PMT change tracking
These fields will allow the mpegts demuxer to expose details about
the PMT/program which created the AVProgram and its AVStreams.

In mpegts, a PMT which advertises streams has a version number
which can be incremented at any time. When the version changes,
the pids which correspond to each of it's streams can also change.

Since ffmpeg creates a new AVStream per pid by default, an API user
needs the ability to (a) detect when the PMT changed, and (b) tell
which AVStream were added to replace earlier streams.

This has been a long-standing issue with ffmpeg's handling of mpegts
streams with PMT changes, and I found two related patches in the wild
that attempt to solve the same problem:

The first is in MythTV's ffmpeg fork, where they added a
void (*streams_changed)(void*); to AVFormatContext and call it from
their fork of the mpegts demuxer whenever the PMT changes.

The second was proposed by XBMC in
https://ffmpeg.org/pipermail/ffmpeg-devel/2012-December/135036.html,
where they created a new AVMEDIA_TYPE_DATA stream with id=0 and
attempted to send packets to it whenever the PMT changed.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-05-18 19:00:29 -07:00
Aman Gupta
2734f8d63a avformat: add skip_estimate_duration_from_pts
For seekable mpegts streams, duration is calculated from
pts by seeking to the end of the file for a pts and subtracting
the initial pts to compute a duration.

This can be expensive in terms of added latency during
probe, especially when streaming over a network. This new
option lets you skip the duration calculation, which is useful
when you don't care about the value and want to save some overhead.

This patch is particularly useful when dealing with live mpegts
streams. Normally such streams are not seekable, so durations
are not calculated. However in my case I am dealing with a seekable
live mpegts stream (networked access to a .ts file which is still
being appended to).

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-05-17 11:33:01 -07:00
Aman Gupta
7b8daa771c avformat/utils: refactor upstream_stream_timings
Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-20 12:12:15 -07:00
Aman Gupta
fd6e89586c avformat/utils: ignore outlier durations on subtitle/data streams as well
Similar to 4c9c4fe8b2, but for durations. This fixes #7151, where
the report duration and bitrate on a mpegts stream is wildly off
due to the dvb_teletext stream's timings.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-20 12:12:07 -07:00
James Almer
23e994ca49 avformat/utils: use the existing packet reference when parsing complete frames
If the parser returns full frames, then the output pointer retured by
av_parser_parse2() is guaranteed to point to data contained in the
input packet's buffer.

Create a new reference to said buffer in that case, to avoid
unnecessary data copy when queueing the packet later in the function.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-13 21:19:22 -03:00
Michael Niedermayer
37d46dc21d avformat/utils: Check cur_dts in update_initial_timestamps() more
Fixes: runtime error: signed integer overflow: 18133149658382192 - -9223090561878065151 cannot be represented in type 'long long'
Fixes: crbug 831552

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-13 22:08:27 +02:00
Michael Niedermayer
c48ceff786 avformat/utils: Fix integer overflow in end time calculation in update_stream_timings()
Fixes: crbug 829153

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-13 21:46:16 +02:00
Bela Bodecs
3e1204b94d avformat/utils: Stream specifier enhancement 2.
In some cases, mainly working with multiprogram mpeg-ts containers as
input, it would be handy to select sub stream of a specific program by
their metadata.
This patch makes it possible to narrow the stream selection among
streams of the specified program by stream metadata.

Examples:
p:601:m:language:hun  will select all sub streams of program with id 601
where sub streams have metadata key named 'language' with value 'hun'.
p:602:m:guide  will select all sub streams of program with id 602 where
sub streams have metadata key named 'guide'.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-13 21:44:28 +02:00
Bela Bodecs
37d0213968 avformat/utils: Stream specifier enhancement
Currently when specifying the program id you can only decide to select
all stream of the specified program (e.g. p:103 will select all streams
of program 103) or narrow the selection to a specific stream sub index
(e.g. p:145:1 will select 2nd stream of program 145.) But you can not
specify like all audio streams of program 145 or 3rd video stream of
program 311.
In some case, mainly working with multiprogram mpeg-ts containers as
input, this feature would be handy.
This patch makes it possible to narrow the stream selection among
streams of the specified program by stream type and optionally its
index. Handled types: a, v, s, d.
Examples: p:601:a  will select all audio streams of program 601,
p:603:a:1 will select 2nd audio streams of program 603,
p:604:v:0 will select first video stream of program 604.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-12 23:52:59 +02:00
James Almer
58ce4fdeae avformat/utils: optimize ff_packet_list_free()
Don't constantly overwrite the list's head pointer.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 00:15:38 -03:00
James Almer
3a4d74c1ff avformat/utils: make AVPacketList helper functions shared
Based on a patch by Luca Barbato.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 00:15:37 -03:00
James Almer
02ae52db87 avformat/utils: use av_packet_make_refcounted to ensure packets are ref counted
Simplifies code, while also fixing a potential leak of side data in pkt.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-02 00:37:51 -03:00
Sasi Inguva
829aebf95d lavf/utils.c: Don't compute start_time from DISCARD packets for video.
Signed-off-by: Sasi Inguva <isasi@isasi.mtv.corp.google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-24 03:11:08 +01:00
Michael Niedermayer
1b1362e408 avformat/utils: Fix integer overflow of fps_first/last_dts
Fixes: runtime error: signed integer overflow: 7738135736989908991 - -7898362169240453118 cannot be represented in type 'long'
Fixes: Chromium bug 796778
Reported-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-07 20:37:33 +01:00
James Almer
2aa42fac77 avformat/utils: simplify ff_alloc_extradata()
Cosmetic refactor

Reviewed-by: 74a2fa708af88d225ed708af758f236f869b1a57
Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-06 19:13:46 -03:00
James Almer
0ca33b1d4e avformat/utils: free existing extradata before trying to allocate a new one
This prevents leaks in the rare cases the function is called when extradata
already exists.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-06 19:13:12 -03:00
James Almer
f235359b2b avformat/utils: don't overwrite the return value of read_packet()
This only affected demuxers that didn't return reference counted packets.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-26 22:17:21 -03:00
Tomas Härdin
5655048c73 Add muxer/demuxer for raw codec2 and .c2 files 2018-02-24 17:06:31 +01:00
Marton Balint
fa8308d3d4 avformat: deprecate AVFormatContext filename field
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01: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
Marton Balint
ea3672b7d6 avformat: add url field to AVFormatContext
This will replace the 1024 character limited filename field. Compatiblity for
output contexts are provided by copying filename field to URL if URL is unset
and by providing an internal function for muxers to set both url and filename
at once.

Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Richard Shaffer
8a4cc0a256 avformat: add option to parse/store ID3 PRIV tags in metadata.
Enables getting access to ID3 PRIV tags from the command-line or metadata API
when demuxing. The PRIV owner is stored as the metadata key prepended with
"id3v2_priv.", and the data is stored as the metadata value. As PRIV tags may
contain arbitrary data, non-printable characters, including NULL bytes, are
escaped as \xXX.

Similarly, any metadata tags that begin with "id3v2_priv." are inserted as ID3
PRIV tags into the output (assuming the format supports ID3). \xXX sequences in
the value are un-escaped to their byte value.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2018-01-24 04:01:01 +01:00
wm4
631c56a8e4 avformat: make avformat_network_init() explicitly optional
It was sort of optional before - if you didn't call it, networking was
initialized on demand, and an ugly warning was logged. Also, the doxygen
comments threatened that it would be made strictly required one day.

Make it explicitly optional. I would prefer to deprecate it fully, but
there might still be legitimate reasons to use this. But the average
user won't need it.

This is needed only for two reasons: to initialize TLS libraries like
OpenSSL and GnuTLS, and winsock.

OpenSSL and GnuTLS were already silently initialized on demand if the
global network init function was not called. They also have various
thread-safety acrobatics, which make concurrent initialization within
libavformat safe. In addition, the libraries are moving towards making
their global init functions safe, which removes all need for central
global init. In particular, GnuTLS 3.5.16 and OpenSSL 1.1.0g have been
found to have safe init functions. In all cases, they use internal
reference counters to avoid that the global uninit functions interfere
with concurrent uses of the library by other API users who called global
init.

winsock should be thread-safe as well, and maintains an internal
reference counter as well.

Since we still support ancient TLS libraries, which do not have this
fixed, and since it's unknown whether winsock and GnuTLS
reinitialization is costly in any way, don't deprecate the libavformat
functions yet.
2018-01-16 12:57:04 +01:00
wm4
6512ff72f9 avformat: deprecate another ffserver API leftover 2018-01-16 12:54:53 +01:00
Karthick Jeyapal
e8f71ef338 avformat/hlsenc, utils: Moved is_http_proto from hlsenc to utils for re-use
Reviewed-by: Aman Gupta <aman@tmm1.net>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2017-12-29 18:11:09 +08:00
wm4
86a13bf2ff lavc, lavf: move avformat static mutex from avcodec to avformat
It's completely absurd that libavcodec would care about libavformat
locking, but it was there because the lock manager was in libavcodec.

This is more stright forward. Changes ABI, but we don't require ABI
compatibility currently.
2017-12-26 02:50:00 +01:00
James Almer
31de45d20b avformat/utils: fix mixed declarations and code
Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-24 17:46:16 -03:00
Dale Curtis
03fbc0daa7 avformat/utils: Prevent undefined shift with wrap_bits > 64.
2LL << (wrap_bits=64 - 1) does not fit in int64_t; change the
code to use a uint64_t (2ULL) and add an av_assert2() to
ensure wrap_bits <= 64.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-24 19:03:03 +01:00
James Almer
d8ea66ab33 avformat/utils: remove usage of AVCodecContext accessors
Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-15 01:14:22 -03:00
Michael Niedermayer
b197d83ca3 avformat/utils: Look at the first 3 frames if timestamps indicate frame reorder but decoder delay does not
Fixes: Ticket6487

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-11 14:15:15 +01:00
John Stebbins
c84bc81158 avformat/utils: preserve AV_PKT_FLAG_DISCARD in parse_packet
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-11 14:15:15 +01:00
Aurelien Jacobs
018eef1a1b aptx: add raw muxer and demuxer for aptX 2017-11-10 21:32:06 +00:00
James Almer
cd1ff3e45d avformat: move priv_pts from AVStream to an internal struct
It has no reason to be in a public header, even if defined as private.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-07 23:20:50 -03:00
James Almer
b7785d10b0 avformat: deprecate getters and setters for AVFormatContext and AVStream fields
The fields can be accessed directly, so these are not needed anymore.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-29 10:29:43 -03:00
James Almer
1e5669457f Merge commit '9e4a5eb51b9f3b2bff0ef08e0074b7fe4893075d'
* commit '9e4a5eb51b9f3b2bff0ef08e0074b7fe4893075d':
  avformat: Free the internal codec context at the end

Merged-by: James Almer <jamrial@gmail.com>
2017-10-28 14:01:25 -03:00
James Almer
b89081e01b avformat: remove dead av_stream_get_side_data() cruft
Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-22 01:36:28 -03:00
James Almer
ca4df37f06 avformat: remove ABI portion of the side data merging API
Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-22 01:29:41 -03:00
Lukas Stabe
1fd80106be avformat: fix id3 chapters
These changes store id3 chapter data in ID3v2ExtraMeta and introduce
ff_id3v2_parse_chapters to parse them into the format context if needed.

Encoders using ff_id3v2_read, which previously parsed chapters into the
format context automatically, were adjusted to call
ff_id3v2_parse_chapters.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2017-10-05 17:10:23 +02:00
Carl Eugen Hoyos
2f3a3a7e32 lavf/utils: Do not force chapter end time before chapter start.
Fixes ticket #6671.
2017-09-20 00:57:29 +02:00
Marton Balint
7160992431 avformat/utils: always av_reduce r_frame_rate
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-08-17 21:02:40 +02:00
Steven Siloti
949debd1d1 avformat/utils: fix memory leak in avformat_free_context
The pointer to the packet queue is stored in the internal structure
so the queue needs to be flushed before internal is freed.

Signed-off-by: Steven Siloti <ssiloti@bittorrent.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-08-05 23:24:02 +02:00
wm4
66cf78e932 lavf: consider codec framerate for framerate detection
Fixes detection of some TV sample as 24.5 FPS. With the patch applied,
it's detected as 25 FPS.

This is enabled for mpegts only.
2017-06-07 11:08:06 +02:00
Michael Niedermayer
850cbd496f avformat/utils: Slightly un-clutter code in determinable_frame_size() by using a switch
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-06 18:31:47 +02:00
Marton Balint
880504814a avformat/utils: change bitrate to int64_t in av_find_best_stream
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-06-04 15:02:53 +02:00
Marton Balint
47c699f7be avformat/utils: return impaired streams in av_find_best_stream if only those exist
Fixes ticket #6397.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-06-04 15:02:53 +02:00
Michael Niedermayer
53e0d5d724 avformat/options: log filename on open
The loglevel is choosen so that the main filename and any images of
multi image sequences are shown only at debug level to avoid
clutter.

This makes exploits in playlists more visible. As they would show
accesses to private/sensitive files

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-03 23:14:04 +02:00
Aaron Levinson
b9d2005ea5 avformat/utils: free AVStream.codec properly in free_stream()
Fixes memory leaks.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-06 17:23:28 -03:00
Luca Barbato
9e4a5eb51b avformat: Free the internal codec context at the end
Avoid a use after free in avformat_find_stream_info.

CC: libav-stable@libav.org
2017-04-13 13:37:10 +02:00
James Almer
b8f26779d6 lavf: use the new bitstream filter for extracting extradata
This merges commits 8e2ea69135 and
096a8effa3 by Anton Khirnov, with the
following change:

- extract_extradata_check() is added to know if the codec is supported
by the bsf before trying to initialize it. This behaviour is similar to
the old AVCodecParser.split checks.

The FATE reference changes are due to the filtered out NAL units that
the old AVCodecParser.split implementation left alone.
Decoding is unchanged as the functions that parse extradata simply
ignored said unnecessary NAL units.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-07 17:16:17 -03:00
James Almer
40fa9d416a Revert "Merge commit '8e2ea691351c5079cdab245ff7bfa5c0f3e3bfe4'"
This reverts commit 1c193ac1f9, reversing
changes made to 7ebc9f8df4.

Several FATE tests started failing after this merge, so it's reverted
until it can be properly fixed.
2017-03-23 19:34:00 -03:00
James Almer
1c193ac1f9 Merge commit '8e2ea691351c5079cdab245ff7bfa5c0f3e3bfe4'
* commit '8e2ea691351c5079cdab245ff7bfa5c0f3e3bfe4':
  lavf: use the new bitstream filter for extracting extradata

Merged-by: James Almer <jamrial@gmail.com>
2017-03-23 16:52:42 -03: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
wm4
d682ae70b4 avcodec, avformat: deprecate anything related to side data merging
This patch deprecates anything that has to do with merging/splitting
side data. Automatic side data merging (and splitting), as well as all
API symbols involved in it, are removed completely.

Two FF_API_ defines are dedicated to deprecating API symbols related to
this: FF_API_MERGE_SD_API removes av_packet_split/merge_side_data in
libavcodec, and FF_API_LAVF_KEEPSIDE_FLAG deprecates
AVFMT_FLAG_KEEP_SIDE_DATA in libavformat.

Since it was claimed that changing the default from merging side data to
not doing it is an ABI change, there are two additional FF_API_ defines,
which stop using the side data merging/splitting by default (and remove
any code in avformat/avcodec doing this): FF_API_MERGE_SD in libavcodec,
and FF_API_LAVF_MERGE_SD in libavformat.

It is very much intended that FF_API_MERGE_SD and FF_API_LAVF_MERGE_SD
are quickly defined to 0 in the next ABI bump, while the API symbols are
retained for a longer time for the sake of compatibility.
AVFMT_FLAG_KEEP_SIDE_DATA will (very much intentionally) do nothing for
most of the time it will still be defined. Keep in mind that no code
exists that actually tries to unset this flag for any reason, nor does
such code need to exist. Code setting this flag explicitly will work as
before. Thus it's ok for AVFMT_FLAG_KEEP_SIDE_DATA to do nothing once
side data merging has been removed from libavformat.

In order to avoid that anyone in the future does this incorrectly, here
is a small guide how to update the internal code on bumps:

- next ABI bump (probably soon):
  - define FF_API_LAVF_MERGE_SD to 0, and remove all code covered by it
  - define FF_API_MERGE_SD to 0, and remove all code covered by it
- next API bump (typically two years in the future or so):
  - define FF_API_LAVF_KEEPSIDE_FLAG to 0, and remove all code covered
    by it
  - define FF_API_MERGE_SD_API to 0, and remove all code covered by it

This forces anyone who actually wants packet side data to temporarily
use deprecated API to get it all. If you ask me, this is batshit fucked
up crazy, but it's how we roll. Making AVFMT_FLAG_KEEP_SIDE_DATA to be
set by default was rejected as an ABI change, so I'm going all the way
to get rid of this once and for all.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-21 06:13:45 +01:00
Michael Niedermayer
3206ea4ba3 avformat/utils: Also fill dts==RELATIVE_TS_BASE packets in update_initial_durations()
This dts value can end up in the list in the absence of durations and is in that
case semantically identical to AV_NOPTS_VALUE. We can alternatively prevent
storing RELATIVE_TS_BASE if there is no duration.

Fixes Ticket3640

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-02-19 02:07:12 +01:00
Paul Arzelier
65862f57ad avformat: Ignore ID3v2 tags if other tags are present e.g. vorbis
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-01-28 23:08:42 +01:00
Matt Wolenetz
fe7547d69e lavf/utils.c Protect against accessing entries[nb_entries]
In ff_index_search_timestamp(), if b == num_entries,
m == num_entries - 1, and entries[m].flags & AVINDEX_DISCARD_FRAME is
true, then the search for the next non-discarded packet could access
entries[nb_entries], exceeding its bounds. This change adds a protection
against that scenario. Reference: https://crbug.com/666770

Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-30 00:11:18 +01:00
Ståle Kristoffersen
d8b9bef1a0 avformat: Auto-detect mjpeg 2000 in mpeg-ts
This makes it possible to decode motion jpeg 2000
encoded in a transport stream without a correct PMT/PAT.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-17 23:52:25 +01:00
Michael Niedermayer
f0bdd53871 avformat/utils: Print verbose error message if stream count exceeds max_streams
Reviewed-by: Andreas Cadhalpun <andreas.cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-13 15:55:42 +01:00
Michael Niedermayer
1296f84495 avformat: Add max_streams option
This allows user apps to stop OOM due to excessive number of streams

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-08 18:25:30 +01:00
Jun Zhao
f17eea883a lavf: fix the wrong warning msg and comments about av_find_stream_info
av_find_stream_info() was deprecated by avformat_find_stream_info(),
correct the warning message in the avformat_find_stream_info() and
comments in the avformat.h

Signed-off-by: Jun Zhao <jun.zhao@intel.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-05 21:30:12 +01:00
Michael Niedermayer
90da187f1d avformat/utils: Check start/end before computing duration in update_stream_timings()
Fixes undefined behavior
Fixes: 637428.ogg

Found-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-03 03:59:13 +01:00
Michael Niedermayer
a06e84b56e avformat/utils: Fix type mismatch
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-11-27 04:08:00 +01:00
Andreas Cadhalpun
ff5f4bd976 lavf: always forward codec_whitelist in avformat_find_stream_info
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-11-26 23:37:55 +01:00
James Almer
79ff9935ae utils: Add av_stream_add_side_data()
Functionally similar to av_packet_add_side_data(). Allows the use of an
already allocated buffer as stream side data.

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2016-11-23 10:36:13 -05:00
James Almer
0b8df0ce48 avformat/utils: add missing brackets around arguments in av_realloc() call
Found-by: Neil Birkbeck <neil.birkbeck@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-21 23:02:20 -03:00
James Almer
0ffea35657 avformat/utils: check for overflow before reallocating side data
This makes av_stream_add_side_data() consistent with av_packet_add_side_data().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-19 20:11:50 -03:00
James Almer
2ab50647ff avformat/utils: add av_stream_add_side_data()
Functionally similar to av_packet_add_side_data(). Allows the use of an
already allocated buffer as stream side data.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-18 22:17:13 -03:00
Andreas Cadhalpun
f84ae3f04a avformat: close parser if codec changed
The parser depends on the codec and thus must not be used with a different one.
If it is, the 'avctx->codec_id == s->parser->codec_ids[0] ...' assert in
av_parser_parse2 gets triggered.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-11-02 22:19:14 +01:00
Michael Niedermayer
2b09a3ad19 Revert "img2 encoder: allow %t in filename, based on patch from Yuval Adam"
breaks API

Found-by: jamrial
This reverts commit 1a956c64c8.
2016-11-01 23:03:24 +01:00
rogerdpack
1a956c64c8 img2 encoder: allow %t in filename, based on patch from Yuval Adam
Signed-off-by: rogerdpack <rogerpack2005@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-11-01 22:29:23 +01:00
Michael Niedermayer
077939626e avformat/flvdec: Fix regression loosing streams
Fixes: unknown_video.flv

Found-by: Thierry Foucu <tfoucu@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-10-28 12:31:01 +02:00
Michael Niedermayer
38e5a4f3bb Revert "avformat/utils: Discard huge timestamps which would cause overflows if used in basic computations"
Some people seem to oppose this the patch seems to have been missed for a month on the ML
lets restart the discussion and solve this after the release

This reverts commit e936c8d176.
2016-10-26 20:31:04 +02:00
Michael Niedermayer
e936c8d176 avformat/utils: Discard huge timestamps which would cause overflows if used in basic computations
Allowing larger timestamps makes it impossible to calculate basic things like the
difference of 2 timestamps or their sum without checking each individual computation for
overflow.
This should avoid a significant number of overflow checks

Fixes Ticket5136

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-10-26 19:46:00 +02:00
Anton Khirnov
096a8effa3 lavf: check that the codec is supported by extract_extradata
Avoids superfluous error message spam after
8e2ea69135
2016-10-21 10:11:20 +02:00
Andreas Cadhalpun
a5b4476a60 avformat: prevent triggering request_probe assert in ff_read_packet
If probe_codec is called with pkt == NULL, it sets probe_packets to 0
and request_probe to -1.
However, request_probe can change when calling s->iformat->read_packet
and thus a probe_packets value of 0 doesn't guarantee a request_probe
value of -1.
In that case calling probe_codec again is necessary to prevent
triggering the assert.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-10-19 23:13:28 +02:00
Anton Khirnov
8e2ea69135 lavf: use the new bitstream filter for extracting extradata
This also fixes a minor bug introduced in the codecpar conversion, where
the termination condition for extracting the extradata does not match
the actual extradata setting code. As a result, the packet durations
made up by lavf go back to their values before the codecpar conversion.
That is of little consequence since that code should eventually be
dropped completely.
2016-10-16 20:27:30 +02:00