1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00
Commit Graph

101920 Commits

Author SHA1 Message Date
Andreas Rheinhardt
6c2cc205f6 avcodec/mpegvideo: Deprecate duplicate matrix opt for unsupported codecs
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 04:17:44 +02:00
Andreas Rheinhardt
2de159fcf1 avcodec/mpegvideo: Deprecate a53cc option for encoders != MPEG-2
The MPEG-2 encoder is the only mpegvideo-based encoder that supports
embedding a53 side data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 04:16:54 +02:00
Andreas Rheinhardt
42c895ef5c avcodec/mpegvideo: Deprecate mpeg_quant option for codecs != MPEG-4
mpeg_quant may only be set for MPEG-4 and MPEG-2, yet for the latter
it is no option as the code acts as if it were always set.
So deprecate the option for all codecs for which it makes no sense.

Furthermore, given that the code already errors out if the option is set
for a codec that doesn't support it we can restrict the range of
the option for all these codecs without breaking something. This means
that the checks for whether mpeg_quant is set for these codecs can be
removed as soon as AVCodecContext.mpeg_quant is removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:56:39 +02:00
Andreas Rheinhardt
dff774042a avcodec/mpegvideo_enc: Combine identical checks
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:56:33 +02:00
Andreas Rheinhardt
bf61cbb7fc avcodec/mpeg12enc: Perform size/level/profile checks earlier
This has the advantage that one does not waste some allocations
if one errors out because of these checks.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:54:45 +02:00
Andreas Rheinhardt
d5c7e5cb65 avcodec/mpeg12enc: Move MPEG-1/2 dimension checks to mpeg12enc
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:53:54 +02:00
Andreas Rheinhardt
80410674bd avcodec/mpegvideo_enc: Remove redundant time_base check
This check is dead as ff_encode_preinit() has an even stricter check.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:53:45 +02:00
Andreas Rheinhardt
4782124b90 fftools/ffmpeg_filter: Don't needlessly copy string
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:53:40 +02:00
Andreas Rheinhardt
6b72410e01 fftools/ffmpeg_filter: Don't write string that is never used
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:53:33 +02:00
Andreas Rheinhardt
80399c7910 fftools/ffmpeg_filter: Avoid allocations when configuring output filters
Use an AVBPrint to handle the (typically short) strings involved here.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:51:50 +02:00
Andreas Rheinhardt
059fc2d9da avcodec/mjpegenc: Include all supported pix_fmts in mpegenc pix_fmts
Currently said list contains only the pixel formats that are always
supported irrespective of the range and the value of
strict_std_compliance. This makes the MJPEG encoder an outlier as all
other codecs put all potentially supported pixel formats into said list
and error out if the chosen pixel format is unsupported. This commit
brings it therefore in line with the other encoders.

The behaviour of fftools/ffmpeg_filter.c has been preserved. A more
informed decision would be possible if colour range were available
at this point, but it isn't.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:48:41 +02:00
Andreas Rheinhardt
48cda7d02b avcodec/ljpegenc: Allow full range yuv420p, yuv422p, yuv444p by default
The documentation for AV_PIX_FMT_YUVJ420P reads:
"planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of
AV_PIX_FMT_YUV420P and setting color_range"
Yet the LJPEG encoder only accepts full scale yuv420p when strictness is
set to unofficial or lower; with default strictness it emits a nonsense
error message that says that limit range YUV is unofficial. This has
been changed to allow full range yuv420p, yuv422p and yuv444p irrespective
of the level of strictness.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:47:08 +02:00
Andreas Rheinhardt
159bcb19b9 avcodec/mpegvideo_enc: Remove redundant pixel format checks
All encoders using ff_mpv_encode_init() already have pix_fmts set
so that the pixel format is already checked in ff_encode_preinit().
The one exception to this is MJPEG whose check remains.

(Btw: The AVCodec.pix_fmts check for AMV is stricter than the check
in ff_mpv_encode_init().)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:46:07 +02:00
Andreas Rheinhardt
d0dcfaef51 avcodec/mjpegenc: Remove dependency of AMV encoder on mjpegenc_huffman
Using optimal Huffman tables is not supported for AMV and always
disabled by ff_mpv_encode_init(); therefore one can build
the AMV encoder without mjpegenc_huffman if one adds the necessary
compile-time checks.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:45:18 +02:00
Andreas Rheinhardt
b3a38eaff4 avcodec/mpegvideo_enc: Make AMV encoder usable without MJPEG encoder
Up until now the relevant checks all checked for the existence of the
MJPEG encoder only.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:31:04 +02:00
Andreas Rheinhardt
7c109cb923 avcodec/proresenc_kostya: Remove harmful check
The ProRes encoder allocates huge worst-case buffers just to be safe;
and for huge resolutions (8k in this case) these can be so big that the
number of bits does no longer fit into a (signed 32-bit) int; this means
that one must no longer use the parts of the PutBits API that deal with
bit counters. Yet proresenc_kostya did it, namely for a check about
whether we are already beyond the end. Yet this check is unnecessary
nowadays, because the PutBits API comes with automatic checks (with
a log message and a av_assert2() in put_bits() and an av_assert0() in
flush_put_bits()), so this is unnecessary. So simply remove the check.

Fixes ticket #9173.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:20:53 +02:00
Michael Niedermayer
d7301f1b75 Changelog: Add new <next> line after 4.4
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-09 06:30:31 +02:00
Michael Niedermayer
3c8c3e0b86 Changelog: replace <next> by 4.4
Found-by: <jamrial>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-09 06:29:52 +02:00
Anton Khirnov
b593abda6c lavc/pngdec: always create a copy for APNG_DISPOSE_OP_BACKGROUND
Calling av_frame_make_writable() from decoders is tricky, especially
when frame threading is used. It is much simpler and safer to just make
a private copy of the frame.
This is not expected to have a major performance impact, since
APNG_DISPOSE_OP_BACKGROUND is not used often and
av_frame_make_writable() would typically make a copy anyway.

Found-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-08 22:40:26 +02:00
Michael Niedermayer
caaf463311 avcodec/msp2dec: Check available space in RLE decoder
Fixes: out of array read
Fixes: 32968/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MSP2_fuzzer-5315296027082752

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-08 16:59:27 +02:00
Andreas Rheinhardt
44c8b67502 avformat/webvttenc: Fix use of uninitialized variable
Happened in 9168a1c0e6.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 14:14:45 +02:00
Andreas Rheinhardt
d393c45051 avcodec/mpegvideo_enc: Don't segfault on unorthodox mpeg_quant
The (deprecated) field AVCodecContext.mpeg_quant has no range
restriction; MpegEncContext.mpeg_quant is restricted to 0..1.
If the former is set, the latter is overwritten with it without
checking the range. This can trigger an av_assert2() with the MPEG-4
encoder when writing said field.

Fix this by just setting MpegEncContext.mpeg_quant to 1 if
AVCodecContext.mpeg_quant is set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 11:32:33 +02:00
Andreas Rheinhardt
6e8e9b7633 avcodec/encode: Fix check for allowed LJPEG pixel formats
The pix_fmts of the LJPEG encoder already contain all supported pixel
formats (including the ones only supported when strictness is unofficial
or less); yet the check in ff_encode_preinit() ignored this list in case
strictness is unofficial or less. But the encoder presumed that it is
always applied and blacklists some of the entries in pix_fmts when
strictness is > unofficial. The result is that if one uses an entry not
on that list and sets strictness to unofficial, said entry passes both
checks and this can lead to segfaults lateron (e.g. when using gray).

Fix this by removing the exception for LJPEG in ff_encode_preinit().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 11:08:10 +02:00
Andreas Rheinhardt
4666ce0aef avformat/rmdec: Don't rely on unspecified order of evaluation
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 11:05:16 +02:00
Andreas Rheinhardt
9a471c5437 avformat/rmdec: Fix memleaks upon read_header failure
For both the RealMedia as well as the IVR demuxer (which share the same
context) each AVStream's priv_data contains an AVPacket that might
contain data (even when reading the header) and therefore needs to be
unreferenced. Up until now, this has not always been done:

The RealMedia demuxer didn't do it when allocating a new stream's
priv_data failed although there might be other streams with packets to
unreference. (The reason for this was that until recently rm_read_close()
couldn't handle an AVStream without priv_data, so one had to choose
between a potential crash and a memleak.)

The IVR demuxer meanwhile never ever called read_close so that the data
already contained in packets leaks upon error.

This patch fixes both demuxers by adding the appropriate cleanup code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 11:05:16 +02:00
Anton Khirnov
f6ea2ee005 fftools/ffmpeg: copy average framerate for streamcopy, when known 2021-04-08 11:03:15 +02:00
Anton Khirnov
04feb1c038 lavf: do not derive timebase from avg_frame_rate
avg_frame_rate is the _average_ framerate, its presence does not
guarantee that the stream is CFR, so it should not be used for setting
the timebase.
2021-04-08 11:03:15 +02:00
Anton Khirnov
0214da22ca fftools/ffmpeg: when framerate is set, prefer its inverse as output timebase
Codec timebase is not well-defined for streamcopy, so it should only be
used as the last resort.
2021-04-08 11:03:15 +02:00
Anton Khirnov
7ec8229982 lavf/movenc: use framerate correctly in mov_write_tmcd_tag
Current code uses its inverse.
2021-04-08 11:03:15 +02:00
Anton Khirnov
6ad79047a7 lavc: postpone FF_API_AVCTX_TIMEBASE
There are still several decoders setting it and the situation is
non-trivial to resolve.
2021-04-08 11:03:15 +02:00
Anton Khirnov
270ddc2baf lavf: postpone removal of FF_API_COMPUTE_PKT_FIELDS2
The infrastructure to fully handle generating timestamps e.g. for raw
video streamcopy is still not present.
2021-04-08 11:03:15 +02:00
Anton Khirnov
9168a1c0e6 lavf/webvttenc: fix avio_printf argument types after bump
Field precision supplied with the '*' specification must be an int.
2021-04-08 11:03:15 +02:00
Anton Khirnov
2822bfbbfb lavf/matroskaenc: fix avio_printf argument types after bump
Field precision supplied with the '*' specification must be an int.

Also, make sure converting those fields to int does not overflow.
2021-04-08 11:03:15 +02:00
Anton Khirnov
19e8103406 lavc/pngdec: use a separate bytestream reader for each chunk
This makes sure that reading a truncated chunk will never overflow into
the following chunk. It also allows to remove many repeated lines
skipping over the trailing crc checksum.
2021-04-08 11:03:15 +02:00
Anton Khirnov
ae08eec6a1 lavc/pngdec: improve chunk length check
The length does not cover the chunk type or CRC.
2021-04-08 11:03:15 +02:00
Anton Khirnov
8e4390de48 tests/fate: add tests for PNG side/meta data 2021-04-08 11:03:15 +02:00
Anton Khirnov
8d74baccff lavc/pngdec: restructure exporting frame meta/side data
This data cannot be stored in PNGDecContext.picture, because the
corresponding chunks may be read after the call to
ff_thread_finish_setup(), at which point modifying shared context data
is a race.

Store intermediate state in the context and then write it directly to
the output frame.

Fixes exporting frame metadata after 5663301560
Fixes #8972

Found-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-04-08 11:03:15 +02:00
Anton Khirnov
89ea5057bf lavc/pngdec: remove unnecessary context variables
Do not store the image buffer pointer/linesize in the context, just
access them directly from the frame.
Stop assuming that linesize is the same for the current and last frame.
2021-04-08 11:03:15 +02:00
Anton Khirnov
5a50bd88db lavc/pngdec: perform APNG blending in-place
Saves an allocation+free and two frame copies per each frame.
2021-04-08 11:03:15 +02:00
Andreas Rheinhardt
98060a198e avcodec/vc1dec: Fix memleak upon allocation error
ff_vc1_decode_init_alloc_tables() had one error path that forgot to free
already allocated buffers; these would then be overwritten on the next
allocation attempt (or they would just not be freed in case this
happened during init, as the decoders for which it is used do not have
the FF_CODEC_CAP_INIT_CLEANUP set).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 10:51:59 +02:00
Guo, Yejun
13bf797ced lavfi/dnn: add post process for detection 2021-04-08 09:23:02 +08:00
Guo, Yejun
59021d79a2 lavfi/dnn: refine code for frame pre/proc processing 2021-04-08 09:23:02 +08:00
Guo, Yejun
d2ccbc966b lavfi/dnn_backend_openvino.c: only allow DFT_PROCESS_FRAME to get output dim 2021-04-08 09:23:02 +08:00
Andreas Rheinhardt
5106fe85f7 avcodec/h261dec: Initialize IDCT context during init
Before 998c9f15d1, initializing an
MpegEncContext's IDCT parts occured in ff_mpv_common_init() and this
has been called in h261_decode_frame(), not h261_decode_init().

Yet said commit factored this out of ff_mpv_common_init() and therefore
there is no reason any more not to set this during init as this commit
does.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 01:17:49 +02:00
Andreas Rheinhardt
9abda1365c avcodec/rv34, mpegvideo: Fix segfault upon frame size change error
The RealVideo 3.0 and 4.0 decoders call ff_mpv_common_init() only during
their init function and not during decode_frame(); when the size of the
frame changes, they call ff_mpv_common_frame_size_change(). Yet upon
error, said function calls ff_mpv_common_end() which frees the whole
MpegEncContext and not only those parts that
ff_mpv_common_frame_size_change() reinits. As a result, the context will
never be usable again; worse, because decode_frame() contains no check
for whether the context is initialized or not, it is presumed that it is
initialized, leading to segfaults. Basically the same happens if
rv34_decoder_realloc() fails.

This commit fixes this by only resetting the parts that
ff_mpv_common_frame_size_change() changes upon error and by actually
checking whether the context is in need of reinitialization in
ff_rv34_decode_frame().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 01:17:24 +02:00
Andreas Rheinhardt
8ffd3ef9d9 avcodec/rv10: Don't presume context to be initialized
In case of resolution changes rv20_decode_picture_header() closes and
reopens its MpegEncContext; it checks the latter for errors, yet when
an error happens, it might happen that no new attempt at
reinitialization is performed when decoding the next frame; this leads
to crashes lateron.

This commit fixes this by making sure that initialization will always
be attempted if the context is currently not initialized.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-08 01:16:25 +02:00
Andreas Rheinhardt
9bab7de175 avcodec/mpegvideo: Factor common freeing code out
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-04-08 01:14:04 +02:00
Andreas Rheinhardt
ff0706cde8 avcodec/mpegvideo: Fix memleak upon allocation error
When slice-threading is used, ff_mpv_common_init() duplicates
the first MpegEncContext and allocates some buffers for each
MpegEncContext (the first as well as the copies). But the count of
allocated MpegEncContexts is not updated until after everything has
been allocated and if an error happens after the first one has been
allocated, only the first one is freed; the others leak.

This commit fixes this: The count is now set before the copies are
allocated. Furthermore, the copies are now created and initialized
before the first MpegEncContext, so that the buffers exclusively owned
by each MpegEncContext are still NULL in the src MpegEncContext so
that no double-free happens upon allocation failure.

Given that this effectively touches every line of the init code,
it has also been factored out in a function of its own in order to
remove code duplication with the same code in
ff_mpv_common_frame_size_change() (which was never called when using
more than one slice (and if it were, there would be potential
double-frees)).

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-04-08 01:09:09 +02:00
Andreas Rheinhardt
d4b9e117ce Revert "avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common_init()"
This mostly reverts commit 4b2863ff01.
Said commit removed the freeing code from ff_mpv_common_init(),
ff_mpv_common_frame_size_change() and ff_mpeg_framesize_alloc() and
instead added the FF_CODEC_CAP_INIT_CLEANUP to several codecs that use
ff_mpv_common_init(). This introduced several bugs:

a) Several decoders using ff_mpv_common_init() in their init function were
forgotten: This affected FLV, Intel H.263, RealVideo 3.0 and V4.0 as well as
VC-1/WMV3.
b) ff_mpv_common_init() is not only called from the init function of
codecs, it is also called from AVCodec.decode functions. If an error
happens after an allocation has succeeded, it can lead to memleaks;
furthermore, it is now possible for the MpegEncContext to be marked as
initialized even when ff_mpv_common_init() returns an error and this can
lead to segfaults because decoders that call ff_mpv_common_init() when
decoding a frame can mistakenly think that the MpegEncContext has been
properly initialized. This can e.g. happen with H.261 or MPEG-4.
c) Removing code for freeing from ff_mpeg_framesize_alloc() (which can't
be called from any init function) can lead to segfaults because the
check for whether it needs to allocate consists of checking whether the
first of the buffers allocated there has been allocated. This part has
already been fixed in 76cea1d2ce.
d) ff_mpv_common_frame_size_change() can also not be reached from any
AVCodec.init function; yet the changes can e.g. lead to segfaults with
decoders using ff_h263_decode_frame() upon allocation failure, because
the MpegEncContext will upon return be flagged as both initialized and
not in need of reinitialization (granted, the fact that
ff_h263_decode_frame() clears context_reinit before the context has been
reinited is a bug in itself). With the earlier version, the context
would be cleaned upon failure and it would be attempted to initialize
the context again in the next call to ff_h263_decode_frame().

While a) could be fixed by adding the missing FF_CODEC_CAP_INIT_CLEANUP,
keeping the current approach would entail adding cleanup code to several
other places because of b). Therefore ff_mpv_common_init() is again made
to clean up after itself; the changes to the wmv2 decoder and the SVQ1
encoder have not been reverted: The former fixed a memleak, the latter
allowed to remove cleanup code.

Fixes: double free
Fixes: ff_free_picture_tables.mp4
Fixes: ff_mpeg_update_thread_context.mp4
Fixes: decode_colskip.mp4
Fixes: memset.mp4

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-04-08 01:07:50 +02:00
Marton Balint
fb4da90fec avformat/url: add ff_make_absolulte_url2 to be able to test windows path cases
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-04-07 22:14:56 +02:00