1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-12 19:18:44 +02:00
Commit Graph

105318 Commits

Author SHA1 Message Date
Andreas Rheinhardt
9f7e0b37ff avformat/matroskaenc: Don't waste bytes on BlockGroup length fields
This commit uses the new EbmlWriter API to write the length fields
of the BlockGroup and its descendants that are themselves Master
elements (namely BlockAdditions and BlockMore) on the least amount of
bytes.

This fixes regressions introduced when the special code for writing
general subtitles was removed. Accordingly, the binsub-mksenc and
matroska-zero-length-block FATE-tests have now been reverted back
to their old state again; the advantages of this approach are evident
with the matroska-vp8-alpha-remux test which up until now wrote
all the length fields of all BlockGroups, BlockAdditions and BlockMore
on eight bytes.

Using the EbmlWriter API also allowed to improve locality in
mkv_write_block(): E.g. both DiscardPadding as well as the
BlockAdditional side-data are now directly used to add elements
to the writer whereas the earlier code had to first check
for whether a BlockGroup should be used and then check again
(after the place where a BlockGroup would be opened if one were
used) for whether there is DiscardPadding or BlockAdditional
side-data to write.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 12:18:14 +01:00
Andreas Rheinhardt
abbc111067 avformat/matroskaenc: Redo applying ProRes offset
Add a field to mkv_track that is set to the offset instead
of checking for whether the track is ProRes when writing
the Block. This makes writing the Block independent
of the AVCodecParameters.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 12:12:56 +01:00
Andreas Rheinhardt
6a9830f503 avformat/matroskaenc: Pass more parameters explicitly to mkv_write_block
This e.g. stops recalculating ts again.
Also pass the AVFormatContext as pointer to void as it is only used
for logging.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 12:12:15 +01:00
Andreas Rheinhardt
03d31ef39c avformat/matroskaenc: Remove special code for writing subtitles
Once upon a time, mkv_write_block() only wrote a (Simple)Block,
not a BlockGroup which is needed for subtitles to convey
the duration. But with the introduction of support for writing
BlockAdditions and DiscardPadding (both of which require a BlockGroup),
mkv_write_block() can also open and close a BlockGroup of its own. This
naturally led to some code duplication which is removed in this commit.

This new code leads to one regression: It always uses eight bytes for
the BlockGroup's length field, whereas the earlier code usually used the
lowest amount of bytes needed. This will be fixed in a future commit.

This temporary regression is also the reason for changes to the
binsub-mksenc and matroska-zero-length-block fate tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 12:08:05 +01:00
Andreas Rheinhardt
d328467dd3 avformat/matroskaenc: Avoid temporary buffers when reformatting H.2645
Do this by using the new NALUList API. This avoids an allocation
of a dynamic buffer per packet as well as the (re)allocation
of the actual buffer as well as copying the data around.

This improves performance: The time for one call to write_packet
decreased from 703501 to 357900 decicyles when remuxing a 5min
14000 kb/s H.264 transport stream.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 12:03:34 +01:00
Andreas Rheinhardt
b177fca06b avformat/avc: Add functions to split access unit into list of NALUs
This will allow to avoid the temporary buffer and memcpys
when repacketing annex B to mp4-style H.264/H.265 without
searching twice for start codes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 12:02:36 +01:00
Andreas Rheinhardt
f9b8b89b75 avformat/matroskaenc: Use common function for H.2645 annex B->mp4
Matroska does not have different profiles that allow or disallow
in-band extradata, so one can just use the ordinary H.264 function
for H.265, too. (Both use ff_avc_parse_nal_units() internally anyway.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:59:42 +01:00
Andreas Rheinhardt
8318627558 avformat/matroskaenc: Redo reformatting AV1
This avoids allocations+copies in all cases, not only those
in which the desired OBUs are contiguous in the input buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:59:05 +01:00
Andreas Rheinhardt
5f973193e5 avformat/av1: Document actual behaviour of ff_av1_filter_obus()
Document that it can be used with a NULL AVIOContext to
get the output size in a first pass.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:57:58 +01:00
Andreas Rheinhardt
396efc73e3 avformat/matroskaenc: Speed up reformatting WavPack
WavPack's blocks use a length field, so that parsing them is fast.
Therefore it makes sense to parse the block twice, once to get
the length of the output packet and once to write the actual data
instead of writing the data into a temporary buffer in a single pass.

This speeds up muxing from 1597092 to 761850 Decicycles per
write_packet call for a 2000kb/s stereo WavPack file muxed to /dev/null
with writing CRC-32 disabled.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:55:34 +01:00
Andreas Rheinhardt
c1b6acde36 avformat/matroskaenc: Allow to use custom reformatting functions
Matroska uses variable-length elements and in order not to waste
bytes on length fields, the length of the data to write needs to
be known before writing the length field. Annex B H.264/5 and
WavPack need to be reformatted to know this length and this
currently involves writing the data into temporary buffers;
AV1 sometimes suffers from this as well.

This commit aims to solve this by adding a callback that is called
twice per packet: Once to get the size and once to actually write
the data. In case of WavPack and AV1 (where parsing is cheap due
to length fields) both calls will just parse the data with only
the second function writing anything. For H.264/5, the position
of the NALUs will need to be stored to be written lateron.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:54:23 +01:00
Andreas Rheinhardt
6221491f90 avformat/matroskaenc: Factor writing Info out
Avoids the surprise of using pb for the main AVIOContext
at the beginning and end of mkv_write_header() and for
for the dynamic buffer opened for the Info element
in the middle of mkv_write_header().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:53:30 +01:00
Andreas Rheinhardt
a04c917399 avformat/matroskaenc: Don't waste bytes on ChapterAtoms length fields
Also check the (user-provided) metadata tags for being too long.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:52:15 +01:00
Andreas Rheinhardt
e8065c7def avformat/matroskaenc: Don't waste bytes on Video element length fields
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:50:27 +01:00
Andreas Rheinhardt
0e548fab42 avformat/matroskaenc: Factor writing TrackVideo out
It is already quite big.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:42:22 +01:00
Andreas Rheinhardt
6b1968e939 avformat/matroskaenc: Avoid seeks when writing EBML header
Using start/end_ebml_master() to write an EBML Master element
uses seeks under the hood. This does not work if the output is
unseekable with the AVIOContext's buffer being very small
(the size of the currently written Matroska EBML header is 40)
or with the AVIOContext being in direct mode, because then
this seek can't be performed in the AVIOContext's buffer.
So using an approach that does not rely on seeking at all
is preferable; this is achieved by switching to EbmlWriter.

Also factor writing the EBML header out into a function of its own.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:40:56 +01:00
Andreas Rheinhardt
dc555de823 avformat/matroskaenc: Don't waste bytes on AttachedFiles' length fields
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:37:39 +01:00
Andreas Rheinhardt
0148e85c3c avformat/matroskaenc: Don't waste bytes on SimpleTags length fields
Also check the (user-provided) tags for being overlong; the earlier
code had an implicit unchecked size_t->int conversion.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:34:36 +01:00
Andreas Rheinhardt
b845fff57d avformat/matroskaenc: Add API to write Masters with minimal length field
This muxer currently uses two ways to ensure that no bytes
are wasted by writing unnecessary long EBML length fields
for Master elements and the (Simple)Block element
(all the other elements are fine as one either already has
the right length or getting the actual length is easy
and necessary anyway):
Either use an upper bound that is good enough in case one
is available or write the data into a dynamic buffer first
to get the length; the former approach is impossible in
lots of cases, whereas the latter incurs allocations and
memcpying. It is therefore unfeasible to use the latter
for e.g. the attachments or the BlockGroups.
This patch adds a third alternative to complement the other two:
It consists of an EbmlWriter that one can add EBML elements to
that can be written later by calling ebml_writer_write();
the latter function first traverses the written elements recursively
and calculates the length of each element; then a second pass
is performed in which all the elements are written directly
(without any seeks).
This new API also performs checks for overlong elements;
this is in contrast to put_ebml_string() which simply performs
a size_t->int conversion even for strings originating from the user.

The new API is designed to have very low overhead: It uses
stack arrays and performs no allocations; this also comes
at a price: Right now, it can only be used in contexts in which
there is a compile-time upper bound for the number of elements.
It is also incompatible with storing the offset of an element
in order to update this field later. Furthermore, it puts
the onus of memory management (i.e. ensuring that pointers stay valid)
on the user.

These restrictions might be overcome in the future.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:34:17 +01:00
Andreas Rheinhardt
5e186f9693 avformat/matroskaenc: Don't open BlockGroup twice
This would happen in case non-WebVTT-subtitles had BlockAdditional
or DiscardPadding side-data. Given that these are not accounted for
in the length of the outer BlockGroup (which is a quite sharp upper
bound) it is possible for the outer BlockGroup to use an insufficient
number of bytes which leads to an assert in end_ebml_master().

Fix this by not opening a second BlockGroup inside an already opened
BlockGroup.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:22:34 +01:00
Andreas Rheinhardt
ca16863549 avformat/matroskaenc: Fix potential overflow
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-19 11:21:53 +01:00
erankor
625ea2d2a9 http: honor response headers in redirect caching
add a dictionary that maps "src_url" -> "expiry;dst_url", the dictionary
is checked before issuing an http request, and updated after getting a
3xx redirect response.

the cache expiry is determined according to the following (in desc
priority) -
1. Expires header
2. Cache-Control containing no-cache/no-store (disables caching)
3. Cache-Control s-maxage/max-age
4. Http codes 301/308 are cached indefinitely, other codes are not
   cached
2022-01-18 17:35:26 -05:00
Haihao Xiang
641c4346b3 lavc/qsvenc_hevc: add -pic_timing_sei option
The SDK may insert picture timing SEI for hevc and the code to set mfx
parameter has been added in qsvenc, however the corresponding option is
missing in the hevc option array

Reviewed-by: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-01-18 16:25:33 +08:00
Haihao Xiang
c4ae6908f2 lavc/qsvenc: add encode support for screen content coding extension
Enables HEVC Screen Content Coding extension support on ICL+ platform

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-01-18 16:24:57 +08:00
Fei Wang
a17c990265 avfilter/tonemap_vaapi: set va parameters filters and numbers
This can fill VAProcPipelineParameterBuffer correctly and make the
pipeline works.

Reviewed-by: Soft Works <softworkz@hotmail.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-01-17 16:32:17 +08:00
Xinpeng Sun
516496069d avfilter: add overlay vaapi filter
Overlay one video on the top of another.

It takes two inputs and has one output. The first input is the "main" video on
which the second input is overlaid. This filter requires same memory layout for
all the inputs.

An example command to use this filter to overlay overlay.mp4 at the top-left
corner of the main.mp4:

ffmpeg -init_hw_device vaapi=foo:/dev/dri/renderD128 \
-hwaccel vaapi -hwaccel_device foo -hwaccel_output_format vaapi -c:v h264 -i main.mp4 \
-hwaccel vaapi -hwaccel_device foo -hwaccel_output_format vaapi -c:v h264 -i overlay.mp4 \
-filter_complex "[0:v][1:v]overlay_vaapi=0:0:100💯0.5[t1]" \
-map "[t1]" -an -c:v h264_vaapi -y out_vaapi.mp4

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Signed-off-by: Xinpeng Sun <xinpeng.sun@intel.com>
Signed-off-by: Zachary Zhou <zachary.zhou@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-01-17 16:32:17 +08:00
Rudolf Polzer
dcc9454ab9 vf_paletteuse: fix color cache lookup for Bayer dithering mode.
To trigger this bug, use `paletteuse=dither=bayer:bayer_scale=0`; you will see
that adjacent pixel lines will use the same dither pattern, instead of being
shifted from each other by 32 units (0x20).

One way to demostrate the bug is:

$ convert -size 64x256 gradient:black-white -rotate 270 grad.png
$ echo 'P2 2 1 255 0 255' > bw.pnm
$ ffmpeg -i grad.png -filter_complex 'movie=bw.pnm,scale=256x1[bw]; [0:v][bw]paletteuse=dither=bayer:bayer_scale=0' gradbw.png

Previously: https://www.rm.cloudns.org/img/uploaded/0bd152c11b9cd99e5945115534b1bdde.png
Now:        https://www.rm.cloudns.org/img/uploaded/89caaa5e36c38bc2c01755b30811f969.png

This was caused by passing inconsistent color vs (a,r,g,b) parameters to
color_get(), and NBITS being 5 meaning actually hitting the same cache node
does happen in this case, but ONLY if bayer_scale is zero.

The fix is passing the correct color value to color_get().

Also added a previous-failing FATE test; image comparison of the first frame:

Previously: https://www.rm.cloudns.org/img/uploaded/d0ff9db8d8a7d8a3b8b88bbe92bf5fed.png
Now:        https://www.rm.cloudns.org/img/uploaded/a72389707e719b5cd1c58916a9e79ca8.png

(on this less synthetic test image, the bug basically causes noise from cache
 hits vs misses)

Tested: FATE passes, which exercises this filter but at the default bayer_scale.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
2022-01-17 01:31:06 +05:30
Gyan Doshi
bca30570d2 avformat/mpegts: add option max_packet_size
Makes maximum size of emitted packet user-tunable.

Default is existing 204800 bytes.
2022-01-16 10:46:38 +05:30
James Almer
b1ef5882e3 fate/ffmpeg: add missing samples dependency to fate-shortest
Signed-off-by: James Almer <jamrial@gmail.com>
2022-01-16 00:32:52 -03:00
James Almer
45e45a6060 avcodec/libmp3lame: return proper error codes
Signed-off-by: James Almer <jamrial@gmail.com>
2022-01-14 22:09:20 -03:00
Vittorio Giovara
7d377558a6 vf_tonemap: Fix order of planes
This resulted in a dimmed tonemapping due to bad resulting luma
calculation.

Found by: Derek Buitenhuis

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2022-01-14 15:48:36 +01:00
Limin Wang
edd305ed54 avcodec/libopenh264enc: set iEntropyCodingModeFlag by coder option
For high/main profile, user can choose to use cavlc by specify "-coder cavlc",
for default, it'll will use cabac, if it's baseline, we'll use cavlc by specs anyway.

ffmpeg -y -f lavfi -i testsrc -c:v libopenh264 -profile:v main -coder cavlc -frames:v 1 -bsf trace_headers -f null -
before the patch:
entropy_coding_mode_flag                                    0 = 1

after the patch:
entropy_coding_mode_flag                                    0 = 0

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-01-14 22:00:19 +08:00
Limin Wang
f74e90c2a0 avcodec/libopenh264enc: make the profile configuablable correctly
due to the limitations set in d3a7bdd4ac,
you weren't able to use main profile with OpenH264 1.8, or high profile
with older versions

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-01-14 22:00:19 +08:00
Limin Wang
008cc90d1a avcodec/libopenh264enc: support for colorspace and range information
Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-01-14 22:00:19 +08:00
Andreas Rheinhardt
b57656e28b fate/matroska: Add test for QT-mode
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 21:00:26 +01:00
Andreas Rheinhardt
99a4d16658 avformat/matroskaenc: Add option to shift data to write cues at front
This is similar to the faststart option of the mov muxer, yet
in contrast to it it works together with reserve_index_space
(the equivalent to reserved_moov_size): If the reserved space
does not suffice, the data is shifted; if not, the Cues are
written at the front without shifting the data.
Several tests that cover (not only) this have been added.

Implements #7017.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 21:00:26 +01:00
Andreas Rheinhardt
46309f262c avcodec/vp3: Don't output bogus warning
It is perfectly fine to have from one to seven bits left
at the end of parsing.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 21:00:26 +01:00
Michael Niedermayer
c36a5dfc8f avformat/rawvideodec: check packet size
Fixes: division by zero
Fixes: integer overflow
Fixes: 43347/clusterfuzz-testcase-minimized-ffmpeg_dem_V210X_fuzzer-5846911637127168

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: lance.lmwang@gmail.com
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-01-13 19:43:03 +01:00
Andreas Rheinhardt
c936c319bd avcodec/mpegpicture: Decrease size of encoding_error array
The current size is AV_NUM_DATA_POINTERS (i.e. eight).
This number is chosen in order to minimize the amount of allocations
for AVFrame.extended_(data|buf) for audio; it is meaningless
for video for which four is sufficient. So decrease this array
in order to minimize what is copied in ff_mpeg_ref_picture()
and at the places that copy a whole MpegEncContext.

Also do the same for snowenc.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:31:02 +01:00
Andreas Rheinhardt
fbeb8eab44 avcodec/mpeg4videodec: Avoid multiple consecutive av_log()
These messages belong together, yet they can be torn apart
if some other call to av_log() happens between them.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:30:21 +01:00
Andreas Rheinhardt
b263415ab7 avcodec/mpegvideo: Don't set unrestricted_mv for decoders
It is write-only for them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:29:44 +01:00
Andreas Rheinhardt
3988016fa3 avcodec/h264pred: Reindentation
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:28:56 +01:00
Andreas Rheinhardt
c32f6b7f8a avcodec/h264pred: Remove dead > 8 pixels checks for 8bit codecs
RV40, SVQ3 and VP7/VP8 are eight-bit only, so it makes no sense
to check for them in the codepath initializing > eight bit contexts.
Move the codec-specific code to a switch located after the eight-bit
init code where this is easily possible; and add checks to the macro
to enable the compiler to remove the remaining checks when initializing
bitdepths > 8 at compile-time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:27:52 +01:00
Andreas Rheinhardt
0a6e000d75 avcodec/h264pred: Don't compile > 8 bit versions of VP7/8 functions
VP7 and VP8 are eight bit only.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:26:39 +01:00
Andreas Rheinhardt
d0bf242d02 avcodec/h264_slice: Inline H264 codec id
This code is only reached by the H.264 decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:26:26 +01:00
Andreas Rheinhardt
67cccd442f avcodec/svq3: Remove dead topright_samples_available variable, code
Topright samples are always available.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:26:13 +01:00
Andreas Rheinhardt
42d30c9019 avcodec/mpegvideo, svq3: Remove unused next_p_frame_damaged
Always zero since 4d2858deac.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:25:10 +01:00
Andreas Rheinhardt
75a3268bee avcodec/h264_slice, mpeg4videodec: Don't use %s to write single char
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:24:47 +01:00
Andreas Rheinhardt
c21433c953 avcodec/mpeg4video: Split off data in a header of its own
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:15:28 +01:00
Limin Wang
8b9ef5a516 avutil/parseutils: use quadhd for Quad HD
qHD is 960x540 (q stands for quarter) and QHD is 2560x1440 (Q is quad).
use quadhd for QHD for abbreviation.

Fix ticket#9591

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-01-12 13:42:26 +08:00