Commit Graph

22149 Commits

Author SHA1 Message Date
Gyan Doshi 0b1ff3265e avformat/yuv4mpegdec: increase header limit
Allows demuxing UHD 30000/1001 fps yuvj420p files
2020-01-26 21:44:43 +05:30
Gyan Doshi 724e6b3d63 avformat/yuv4mpegdec: better error logging 2020-01-26 21:44:38 +05:30
Andreas Rheinhardt a3e43e0cf3 avformat/av1: Avoid allocation + copying when filtering OBUs
Certain types of OBUs are stripped away before muxing into Matroska and
ISOBMFF; there are two functions to do this: One that outputs by
directly writing in an AVIOContext and one that returns a freshly
allocated buffer with the units not stripped away copied into it.

The latter option is bad for performance, especially when the input
does already not contain any of the units intended to be stripped away
(this covers typical remuxing scenarios). Therefore this commit changes
this by avoiding allocating and copying when possible; it is possible if
the OBUs to be retained are consecutively in the input buffer (without
an OBU to be discarded between them). In this case, the caller receives
the offset as well as the length of the part of the buffer that contains
the units to be kept. This also avoids copying when e.g. the only unit
to be discarded is a temporal delimiter at the front.

For a 22.7mb/s file with average framesize 113 kB this improved the time
for the calls to ff_av1_filter_obus_buf() when writing Matroska from
313319 decicycles to 2368 decicycles; for another file with 1.5mb/s
(average framesize 7.3 kB) it improved from 34539 decicycles to 1922
decicyles. For these files the only units that needed to be stripped
away were temporal unit delimiters at the front.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:32 -03:00
Andreas Rheinhardt 2eee34372f avformat/av1: Fix nits in the documentation of ff_av1_filter_obus_buf()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:32 -03:00
Andreas Rheinhardt 2899995a6f avformat/av1, avc, hevc: Remove av_freep()
ff_av1_filter_obus_buf() and ff_avc_parse_nal_units_buf() both have a
pointer-to-pointer parameter which they use to pass a newly allocated
buffer to the caller. And both functions freed what this pointer points to
before overwriting it. But no caller of these functions used this feature,
but some had to initialize the pointer just because of this. So remove
it and update the documentation of ff_av1_filter_obus_buf() wrt this fact.

ff_hevc_annexb2mp4_buf in contrast did not free the pointer. This has been
documented, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:32 -03:00
Andreas Rheinhardt d4bbc0db01 avformat/av1: Improve filtering AV1 OBUs
Both ISOBMFF as well as Matroska require certain OBUs to be stripped
before muxing them. There are two functions for this purpose; one writes
directly into an AVIOContext, the other returns a freshly allocated
buffer with the undesired units stripped away.

The latter one actually relies on the former by means of a dynamic
buffer. This has several drawbacks: The underlying buffer might have to
be reallocated multiple times; the buffer will eventually be
overallocated; the data will not be directly copied into the final
buffer, but rather first in the write buffer (in chunks of 1024 byte)
and then written in these chunks. Moreover, the API for dynamic buffers
is defective wrt error checking and as a consequence, the earlier code
would indicate a length of -AV_INPUT_BUFFER_PADDING_SIZE on allocation
failure, but it would not return an error; there would also be no error
in case the arbitrary limit of INT_MAX/2 that is currently imposed on
dynamic buffers is hit.

This commit changes this: The buffer is now parsed twice, once to get
the precise length which will then be allocated; and once to actually
write the data.

For a 22.7mb/s file with average framesize 113 kB this improved the time
for the calls to ff_av1_filter_obus_buf() when writing Matroska from
753662 decicycles to 313319 decicycles (based upon 50 runs a 2048 frames
each); for another 1.5mb/s file (with average framesize of 7.3 kB) it
improved from 79270 decicycles to 34539 decicycles (based upon 50 runs a
4096 frames).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:32 -03:00
Andreas Rheinhardt e8518c2580 avformat/movenc: Check for reformatting errors when writing hint tracks
If this is not done, the avio_write() calls will cause segfaults
immediately afterwards on error.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:31 -03:00
Andreas Rheinhardt 22ec35a428 avformat/av1, hevc: Make *_buf-functions return 0 on success
The output size is already returned via a pointer argument, so there is
no need to return it via the ordinary return value as well. The
rationale behind this is to not poison the return value on success.
It also unifies the behaviour of the *_buf-functions for AVC, AV1 and
HEVC.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:31 -03:00
Andreas Rheinhardt 680cd59bb2 avformat/hevc: Fix potential leak in case of ff_hevc_annexb2mp4_buf failure
ff_hevc_annexb2mp4_buf() could indicate an error, yet leave cleaning
after itself to the caller, so that a caller could not simply return the
error, but had to free the buffer first.

(Given that all current callers have set filter_ps = 0, this error can
currently not be triggered.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:31 -03:00
Andreas Rheinhardt e4749a4497 avformat/matroskaenc: Cosmetics
Add {, } in situations like
if ()
    ...
else if ()
    /* Comment */
    ...
else ...

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:31 -03:00
Andreas Rheinhardt 58428bef4b avformat/matroskaenc: Check for reformatting errors
This is needed especially for AV1: If a reformatting error happens (e.g.
if the length field of an OBU contained in the current packet indicates
that said OBU extends beyond the current packet), the data pointer is
still NULL, yet the size is unchanged, so that writing the data leads
to a segmentation fault.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-26 12:41:31 -03:00
Zane van Iperen dc3aa376dc avformat: add demuxer for argonaut games' ASF format
Adds support for the custom ASF container used by some Argonaut Games'
games, such as 'Croc! Legend of the Gobbos', and 'Croc 2'.

Can also handle the sample files in:
https://samples.ffmpeg.org/game-formats/brender/part2.zip

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2020-01-26 10:24:00 +01:00
Marton Balint 15d160cc0b avformat/udp: increase the default buffer size of a receiving socket to 384K
It is a common mistake that people only increase fifo_size when they experience
drops, unfortunately this does not help for higher bitrate (> 100 Mbps) streams
when the reader thread simply might not receive the packets in time (especially
under high CPU load) if the default 64 KB of kernel buffer size is used.

New default is determined so that common linux systems can set this buffer size
without tuning kernel parameters.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-25 23:16:47 +01:00
Marton Balint 67f39b32db avformat/udp: properly use return value of pthread_cond_timedwait
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-25 23:16:47 +01:00
Marton Balint f61e9f8aef avformat/udp: add newline after warning
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-25 23:16:47 +01:00
Gyan Doshi 75d1d9eb34 avformat/movenc: allow ISMV timescale to be user-set
As per the PIFF standard, the timescale of 10000000
is recommended but not mandatory, so don't override
the user-set value.

A warning is shown for non-recommended values.
2020-01-25 21:36:17 +05:30
Marton Balint fee4cafbf5 avformat/libsrt: add missing SRT_VERSION_VALUE check
This was missed in d7e2a2bb35.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-23 22:41:43 +01:00
Gyan Doshi 41f283ec7a avformat/utils: log corrupt packets 2020-01-23 12:08:20 +05:30
Andriy Gelman c07565627b avformat/libzmq: Replace fail statements with goto
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-21 15:56:39 +01:00
Andriy Gelman 1054b68a62 avformat/libzmq: Check return of zmq_setsockopt
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-21 15:56:39 +01:00
Bela Bodecs 8c3e9c9cbb avformat/hlsenc: fix default AES key file url with variant streams
Currently when hls_enc is active and there are multiple variant stream
outputs, default key file url construction does not work, because it is
based on the FormatContext' url field. But in case of multiple variant
streams, it contains the variant m3u8 output playlist url that contains
the %v placeholder. So the result key file url will hold the %v
placeholder causing run time error message about "could not write the
key file".
This patch correct this behaviour, and use the master playlist url for
constructing the output key file url when master playlist is vailable.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
2020-01-20 14:34:30 +08:00
Bela Bodecs dd5c7378bb avformat/hlsenc: program_date_time and append_list flags conflict
When program_date_time flag is present, in m3u8 playlist file each
segment has a corresponding EXT-X-PROGRAM-DATE-TIME value. The intial
program-date-time value is the actual current time at init and
each new segment increments this value by its duration. When append_list
flags is also present, existing playlist parsing by hls_append_segment
treats existing segments as new segments regarding the program-date-time
calculation. But it should not do that, because this way all real the
new segments' EXT-X-PROGRAM-DATE-TIME values will be shifted erroneously
by the sum duration of existing segments. Instead it should have
decremented the initial program-date-time value by its duration. This
would ensure that
the first new segment's program-date-time value had the current time as
it is expected.
This patch corrects this behaviour and prevent existing segments to
increment the value of initial_prog_date_time variable but decrements
it.

Reviewed-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
2020-01-20 14:34:26 +08:00
Xuchen Su 9faee5bc14 avformat/udp: modify the not write-only to read-only mode.
not write-only include read-write pseudo flag. so make the flag read-only

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-01-20 14:28:56 +08:00
Steven Liu bc0bedf3c9 avformat/hlsenc: compare without the last directory separator in get_relative_url
fix ticket: 8461
there is no problem before commit 75aea52a10

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-01-20 14:23:56 +08:00
Marton Balint b5dba152ef avformat/dashenc: use ff_rename instead of avpriv_io_move
ff_rename always logs the error message.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-19 22:17:04 +01:00
Marton Balint 19b9f8996e avformat/avio: fix ff_rename to respect used protocol
Also simplify it and make it always log the error.

This fixes for example the image2 muxer when used with an URL which also
contains the protocol:

ffmpeg -f lavfi -i testsrc -vframes 10 -atomic_writing 1 file:out%d.png

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-19 22:17:04 +01:00
Marton Balint df993269ec avformat/avio: move ff_rename implementation from internal.h to avio.c
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-19 22:17:04 +01:00
Anthony Delannoy f8990c5f41 avformat/libsrt: fix enabling nonblocking mode
As written in https://github.com/Haivision/srt/blob/v1.4.1/docs/API.md,
the nonblock mode is activated if SRTO_SNDSYN and SRTO_RCVSYN, for
sending and receiving respectively, are set to 0.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-19 00:17:11 +01:00
Marton Balint 3ffe3b1db0 avformat/img2enc: add support for specifying protocol options
v2: simplified example

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-18 23:51:17 +01:00
Michael Niedermayer 934cc1faf4 avformat/dtsdec: make S16LE discrimination sharper
Both S16LE as well as DTS can have lots of 0 bytes in silent segments
Using these results in error. Thus this patch skips 0 bytes in
comparission.

Fixes Ticket6561

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-18 18:35:57 +01:00
Steven Liu b9606064c4 avformat/hls: support data protocol in uri for EXT-X-MAP
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-01-18 22:41:11 +08:00
Andreas Rheinhardt 5b7e90b252 avformat/oggparsevorbis: Use AV_DICT_DONT_STRDUP_VAL to avoid av_strdup
This will likely also fix CID 1452427, a false positive resulting from
Coverity thinking that av_dict_set() automatically frees its key and
value parameters (even without the AV_DICT_DONT_STRDUP_* flags).

(AV_DICT_APPEND and AV_DICT_DONT_STRDUP_VAL are compatible with each
other since a8c5b455, so we can reset this flag here. It has originally
been removed in 0dc66553 when appending was added.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-17 20:17:55 +01:00
Andreas Rheinhardt 42df71d0c5 avformat/flvenc: Avoid unnecessary seek
When shifting the already written data in order to write the keyframe
index, the flv muxer would first store the pre-shift size, then
calculate how big the index will be eventually, then perform some seeks
to update some size fields, then seek back to the end of the file to get
the new position, followed by a seek to the position where writing will
really start. Seeking back to the (already known) end position (that is
actually used to perform this seek) to get the end position is of course
unnecessary. It has been removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-17 20:17:55 +01:00
Andreas Rheinhardt 61e0d71946 avformat/movenc, segafilmenc: Remove unnecessary avio_tell()
When the faststart option for the mov/mp4 muxer is used, the current
position (i.e. the size of the already written data pre-shifting) was
evaluated twice: First in an initialization and then again later,
overwriting the first value without having ever touched it. So remove
the initialization.

Also, the clone of this code in the Sega FILM muxer behaves the same and
has been treated the same.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-17 20:17:55 +01:00
James Almer ab9627223e Revert "avformat/utils: make ff_ntp_time() accept a timestamp as input argument"
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-16 22:27:35 -03:00
Nicolas Gaullier 80c3a15a1b avformat/s337m: Use base AVClass for av_log usage
s337m_get_offset_and_codec does not make use of
AVFormatContext: AVClass is enough for logging.
Will facilitate further use from outside

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-16 21:45:45 +01:00
James Almer e7c04eaf50 avformat/dashenc: document the new options
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:37 -03:00
James Almer 05b3460991 avformat/dashenc: add an option to write a Latency element
Allows to set an intended target latency while streaming that clients can use
to measure when using low latency mode.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:22 -03:00
Anton Khirnov bc4f0e713b dashenc: support setting arbitrary HTTP protocol options
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:22 -03:00
James Almer c96a9636c8 avformat/dashenc: allow setting custom movflags using format_options
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:21 -03:00
James Almer cc929cee76 avformat/movenc: add a flag to enable CMAF compatability
Sets some required constrains and reports compatability with the relevant
compatible brand.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:21 -03:00
James Almer f63407a986 avformat/dashenc: implement DVB-DASH profile
Add new required elements and constrain presence and values for existing
ones based on the spec.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:21 -03:00
James Almer 21847e2a52 avformat/dashenc: add an option to enable low latency Dash manifest
In combination with the streaming option it constrains the value of a few elements,
to prevet clients from buffering too much data before starting presentation.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:20 -03:00
James Almer 7e5d143bb5 avformat/dashenc: Write a Producer Reference Time element
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:20 -03:00
James Almer 7abc0979e6 avformat/movenc: use AVProducerReferenceTime side data to write the prft atom
If not available, set flags to 24 (bits 4 and 5), to signal the wallclock value
is read at the time of writing the atom.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:20 -03:00
James Almer 4e4ac20340 avformat/utils: make ff_ntp_time() accept a timestamp as input argument
Will be needed by the next patch.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:20 -03:00
James Almer ea5a910628 avformat/dashenc: allow splitting fragments following P-Frame reordering
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 12:22:29 -03:00
James Almer ceb236c1c5 avformat/dashenc: allow setting fragment durations
Implemented as as a frag_duration muxer option and key=value entry in the
adaptation_sets muxer option. It has the same syntax as the seg_duration option.
A new frag_type option is also introduced to select the kind of fragmentation.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 12:22:28 -03:00
James Almer 0c19dd2df4 avformat/dashenc: allow setting segment durations per AdaptationSet
Implemented as as a seg_duration key=value entry in the adaptation_sets muxer
option.
It has the same syntax as the global seg_duration option, and has precedence
over it if set.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 12:22:28 -03:00
Andreas Rheinhardt b55c6b8c40 avformat/avformat: Update AVInputFormat.read_packet documentation
Since bae8844e35, the packet is automatically unreferenced in
ff_read_packet() when an error is returned; but the documentation of
this of AVInputFormat.read_packet has not been updated accordingly.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-14 23:00:35 +01:00