Commit Graph

110308 Commits

Author SHA1 Message Date
Anton Khirnov a34f483291 fftools/ffmpeg: add muxer-input codec parameters to OutputStream
It stores codec parameters of the stream submitted to the muxer, which
may be different from the codec parameters in AVStream due to bitstream
filtering.

This avoids the confusing back and forth synchronisation between the
encoder, bitstream filters, and the muxer, now information flows only in
one direction. It also reduces the need for non-muxing code to access
AVStream.
2023-04-17 12:01:40 +02:00
Anton Khirnov a064aed4c3 fftools/ffmpeg: store stream media type in OutputStream
Reduces access to a deeply nested muxer property
OutputStream.st->codecpar->codec_type for this fundamental and immutable
stream property.

Besides making the code shorter, this will allow making the AVStream
(OutputStream.st) private to the muxer in the future.
2023-04-17 12:01:40 +02:00
Anton Khirnov de38e17583 fftools/ffmpeg: initialize no-filter streams earlier
There is no reason to postpone it until transcode_init() anymore, it can
be done right at the end of of_open().
2023-04-17 12:01:40 +02:00
Anton Khirnov 2058402e00 fftools/ffmpeg: open decoders right after we know they are needed
Will allow initializing subtitle encoding earlier.
2023-04-17 12:01:40 +02:00
Anton Khirnov c8fa58430e fftools/ffmpeg_dec: drop useless abort_codec_experimental()
It does nothing beyond exit_program().
2023-04-17 12:01:40 +02:00
Anton Khirnov 503c705634 fftools/ffmpeg_dec: reindent after previous commit 2023-04-17 12:01:40 +02:00
Anton Khirnov 9ce1a041d8 fftools/ffmpeg: move opening decoders to a new file
All decoding code will be moved to this file in the future.
2023-04-17 12:01:40 +02:00
Anton Khirnov ff92ecad2f fftools/ffmpeg: stop setting InputStream fields from muxing/filtering code
Set InputStream.decoding_needed/discard/etc. only from
ist_{filter,output},add() functions. Reduces the knowledge of
InputStream internals in muxing/filtering code.
2023-04-17 12:01:40 +02:00
Anton Khirnov ae071c9e39 fftools/ffmpeg: add a function adding a destination filter for InputStream
This way filtering code does not directly mess with InputStream
internals. Will become more useful in following commits.
2023-04-17 12:01:40 +02:00
Anton Khirnov c7438e8737 fftools/ffmpeg_mux_init: consolidate input stream flagging code
Makes it easier to see where the input stream is modified from muxer
code.
2023-04-17 12:01:40 +02:00
Anton Khirnov 0c44db4646 fftools/ffmpeg: drop unnecessary indirection
init_input_stream() can print log messages directly, there is no need to
ship them to the caller.

Also, log errors to the InputStream and avoid duplicate information in
the message.
2023-04-17 12:01:40 +02:00
Anton Khirnov 4358d4d8e7 fftools/ffmpeg: move a check to a more appropriate place
reap_filters() no longer needs to access the encoding context.
2023-04-17 12:01:40 +02:00
Anton Khirnov 4fc513b5e3 fftools/ffmpeg: move a misplaced assignment
Changing AVCodecContext.sample_aspect_ratio after the encoder was opened
is by itself questionable, but if anywhere it belongs in encoding rather
than filtering code.
2023-04-17 12:01:36 +02:00
Anton Khirnov a0452ee837 fftools/ffmpeg_mux_init: remove a redundant check 2023-04-17 12:00:06 +02:00
Anton Khirnov 12f3f41bbf fftools/ffmpeg: move init_output_stream_streamcopy() to ffmpeg_mux_init
Everything in it can be done immediately when creating the output
stream, there is no reason to postpone it.
2023-04-17 12:00:06 +02:00
Anton Khirnov 9bae55165d fftools/ffmpeg_mux_init: restructure output stream creation
Creating a new output stream of a given type is currently done by
calling new_<type>_stream(), which all start by calling
new_output_stream() to allocate the stream and do common init, followed
by type-specific init.

Reverse this structure - the caller now calls the common function
ost_add() with the type as a parameter, which then calls the
type-specific function internally. This will allow adding common code
that runs after type-specific code in future commits.
2023-04-17 12:00:06 +02:00
Anton Khirnov a7f26b1c63 fftools/ffmpeg_mux_init: move new_output_stream() lower in the file
Reduces the diff in the following commit.

Temporarily add a forward declaration for new_output_stream(), it will
be removed in the next commit.
2023-04-17 12:00:06 +02:00
Anton Khirnov 89c9a3ac35 fftools/ffmpeg: avoid possible invalid reads with short -tag values
Fixes #10319 and #10309.
2023-04-17 11:49:34 +02:00
jianfeng.zheng 65e537b833 vaapi: support VAProfileH264High10 encoding
see https://github.com/intel/libva/pull/664

Signed-off-by: jianfeng.zheng <jianfeng.zheng@mthreads.com>
2023-04-17 15:11:22 +08:00
jianfeng.zheng 1cd5a383d4 vaapi: support VAProfileH264High10 decoding
see https://github.com/intel/libva/pull/664

Signed-off-by: jianfeng.zheng <jianfeng.zheng@mthreads.com>
2023-04-17 15:11:22 +08:00
Jiasheng Jiang b9ba036680 avcodec/msvideo1enc: Add check for av_malloc
Add the check for the return value of the av_malloc in order to avoid
NULL pointer deference.

Fixes: e4be3485af ("MS Video 1 encoder")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
2023-04-16 23:36:03 -03:00
Jiasheng Jiang f8d0b13de5 avcodec/rv34: Add check for av_malloc
Add the check for the return value of the av_malloc in order to avoid
NULL pointer deference.

Fixes: b86ab38137 ("Add weighted motion compensation for RV40 B-frames")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
2023-04-16 23:36:03 -03:00
Michael Niedermayer a3f49168dc
avcodec/j2kenc: Add YA8 and YA16 support
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-04-14 18:59:48 +02:00
Michael Niedermayer c66e13cbac
avcodec/jpeg2000dec: Add YA16 support
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-04-14 18:59:48 +02:00
Michael Niedermayer fa618f5f49
Revert "avcodec/er: remove check for fields"
Fixes: out of array write on x86-32
Fixes: 57825/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG2VIDEO_fuzzer-6094366187061248
Fixes: 57829/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG2VIDEO_fuzzer-4526419991724032

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
This reverts commit f7abe92bd7.
2023-04-14 17:56:45 +02:00
Michael Niedermayer 5366ae12b9
avcodec/escape124: Check that blocks are allocated before use
Fixes: NULL pointer dereference
Fixes: 57819/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ESCAPE124_fuzzer-5077280228769792

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-04-14 17:56:44 +02:00
Michael Niedermayer 0ecda4fbce
avcodec/rka: Fix signed integer overflow in decode_filter()
Fixes: signed integer overflow: -631553 * 32768 cannot be represented in type 'int'
Fixes: 57814/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RKA_fuzzer-4614661233573888

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-04-14 17:56:44 +02:00
Michael Niedermayer 80ac1fd148
avcodec/hevc_ps: Check num_ref_loc_offsets
Fixes: Writing arbitrarily over the array end
Fixes: 57812/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-4536557859373056

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-04-14 17:56:44 +02:00
Michael Niedermayer 27e7857bd1
avcodec/huffyuvdec: Fix undefined behavior with shift
Fixes: left shift of negative value -1
Fixes: 57554/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFVHUFF_fuzzer-4853603839115264

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-04-14 17:56:36 +02:00
James Almer 7c6e26a184 avcodec/mp_cmp: reject invalid comparison function values
Fixes tickets #10306 and #10318.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-04-14 10:04:47 -03:00
James Almer 5cda6b94f4 avcodec/aacpsy: clip global_quality within the psy_vbr_map array boundaries
Fixes ticket #10317.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-04-14 10:04:47 -03:00
James Almer 92885f2681 avutil/wchar_filename: propagate MultiByteToWideChar() and WideCharToMultiByte() failures
Don't return success if the string could not be converted.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-04-14 10:04:47 -03:00
James Almer 19c2dc677f avformat/concatf: check if any nodes were allocated
Fixes ticket #10304

Signed-off-by: James Almer <jamrial@gmail.com>
2023-04-14 10:04:47 -03:00
Zhao Zhili c8e1955408 avformat/flvenc: avoid an extra allocate
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-04-15 04:21:33 +08:00
Zhao Zhili d5fdfbac4a avformat/flvenc: use local variable to shorten code
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-04-15 04:21:33 +08:00
Zhao Zhili f0f596dbc6 avutil/internal: remove timer.h again
timer.h has been removed from internal.h, and then added back with
3e6088f for convenience. This patch removed it again for the
following reasons:

1. Only includes what's necessary is a common and safe strategy.

2. It fixed some build errors on Android:
  a. libavutil/timer.h includes sys/ioctl.h, and ioctl.h includes
     termios.h on Android.
  b. termios.h reserves names prefixed with ‘c_’, ‘V’, ‘I’, ‘O’, and
     ‘TC’; and names prefixed with ‘B’ followed by a digit.
  c. libavcodec uses B0 B1 and so on as variable names a lot. So
     the code failed to build with --enable-linux-perf, or
     --target-os=Linux.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-04-15 04:21:33 +08:00
Nongji Chen eb96cfbf57 ffmpeg: make timestamp discontinuity logging a warning
In most cases this should only occur once or so per stream in an
input, and in case the logic ends up in an eternal loop, it should
be visible to the end user instead of being completely invisible.

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2023-04-14 15:06:41 +03:00
xufuji456 bd2f00f665 codec/aarch64/hevc: add transform_luma_neon
got 56% speed up (run_count=1000, CPU=Cortex A53)
transform_4x4_luma_neon: 45 transform_4x4_luma_c: 103

Signed-off-by: xufuji456 <839789740@qq.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2023-04-14 12:07:57 +03:00
Niklas Haas 4eaaa38d3d avutil: make av_frame_get_plane_buffer accept a const AVFrame*
Signed-off-by: Niklas Haas <git@haasn.dev>
2023-04-14 10:53:28 +02:00
Anton Khirnov cea71b2139 fftools/ffmpeg: stop using fake dts for generating timestamps
When no packet dts values are available from the container, video
decoding code will currently use its own guessed values, which will then
be propagated to pkt_dts on decoded frames and used as pts in certain
cases. This is inaccurate, fragile, and unnecessarily convoluted.
Simply removing this allows the extrapolation code introduced in the
previous commit to do a better job.

Changes the results of numerous h264 and hevc FATE tests, where no
spurious timestamp gaps are generated anymore. Several tests no longer
need -vsync passthrough.
2023-04-13 15:34:07 +02:00
Anton Khirnov 5d407cb2d7 fftools/ffmpeg: change video decoding timestamp generation
When no timestamps are available from the container, the video decoding
code will currently use fake dts values - generated in
process_input_packet() based on a combination of information from the
decoder and the parser (obtained via the demuxer) - to generate
timestamps during decoder flushing. This is fragile, hard to follow, and
unnecessarily convoluted, since more reliable information can be
obtained directly from post-decoding values.

The new code keeps track of the last decoded frame pts and estimates its
duration based on a number of heuristics. Timestamps generated when both
pts and pkt_dts are missing are then simple pts+duration of the last frame.
The heuristics are somewhat complicated by the fact that lavf insists on
making up packet timestamps based on its highly incomplete information.
That should be removed in the future, allowing to further simplify this
code.

The results of the following tests change:
* h264-3386 now requires -fps_mode passthrough to avoid dropping frames
  at the end; this is a pathology of the interaction of the new and old
  code, and the fact that the sample switches from field to frame coding
  in the last packet, and will be fixed in following commits
* hevc-conformance-DELTAQP_A_BRCM_4 stops inventing an arbitrary
  timestamp gap at the end
* hevc-small422chroma - the single frame output by this test now has a
  timestamp of 0, rather than an arbitrary 7
2023-04-13 15:34:07 +02:00
Anton Khirnov 380db56928 fftools/ffmpeg: use InputStream.pts as last resort for decoded frame pts 2023-04-13 15:34:07 +02:00
Anton Khirnov 95fa4edbd6 fftools/ffmpeg: improve decoder -ts_debug line
* log to the input stream log context
* drop the now-duplicate index/type information
* show pkt_dts and frame duration
2023-04-13 15:34:07 +02:00
Anton Khirnov be3b1e27e5 lavf/rawdec: mark raw demuxers as having no timestamps
Changes the result of the h264_redundant_pps-mov test, where the output
timebase is now 1001/24000 instead of 1/24. This is more correct, as the
source file actually is 23.98fps.
2023-04-13 15:34:07 +02:00
Anton Khirnov 7b827a0293 lavf/demux: treat streams with AVSTREAM_PARSE_FULL_RAW as having timestamps
In this case the timestamps are set by the parser.
Cf. a6b3471c44

Required by the following commit.
2023-04-13 15:34:07 +02:00
Anton Khirnov ba4b73c977 lavf/rawdec: set avg_frame_rate
Timestamps in two FATE H.264 conformance tests now start at 1 instead
of 0, which also happens in some other H.264 tests before this commit
and so is not a big issue.
Conversely, timestamps in some HEVC conformance tests start from a
smaller value now.
Ideally this should be addressed later in a more general way.

h264-conformance-frext-frext2_panasonic_b no longer requires -vsync
passthrough.
2023-04-13 15:34:07 +02:00
Anton Khirnov d56652fdc8 fftools/ffmpeg: stop using InputStream.pts for streamcopy
This field contains different values depending on whether the stream is
being decoded or not. When it is, InputStream.pts is set to the
timestamp of the last decoded frame. Otherwise, it is made equal to
InputStream.dts.

Since a given InputStream can be at the same time decoded and
streamcopied to any number of output streams, this use is incorrect, as
decoded frame timestamps can be delayed with respect to input packets by
an arbitrary amount (e.g. depending on the thread count when frame
threading is used).

Replace all uses of InputStream.pts for streamcopy with InputStream.dts,
which is its value when decoding is not performed. Stop setting
InputStream.pts for pure streamcopy.
Also, pass InputStream.dts as a parameter to do_streamcopy(), which
will allow that function to be decoupled from InputStream completely in
the future.
2023-04-13 15:32:56 +02:00
Anton Khirnov 106eb58ceb fftools/ffmpeg: move checking for input -t out of do_streamcopy()
This check is entirely about the properties of the input stream, while
do_streamcopy() should contain code specific to a given output stream.
2023-04-13 15:11:56 +02:00
Anton Khirnov 0feff04956 fftools/ffmpeg: only set InputStream.next_pts for decoding
It is write-only for streamcopy.
2023-04-13 15:11:56 +02:00
Anton Khirnov d867f9ab8c fftools/ffmpeg: use AVPacket.time_base to simplify do_streamcopy()
Besides making the code shorter, this also reduces the use of
InputStream in this function and will allow not accessing it at all in
the future.
2023-04-13 15:11:56 +02:00