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

107495 Commits

Author SHA1 Message Date
Anton Khirnov
52bc8a842e fftools/ffmpeg_mux: return errors from of_submit_packet()
Do not call exit_program(), as that would conflict with moving this code
into a separate thread.
2022-07-23 11:53:19 +02:00
Anton Khirnov
ff593c6c88 fftools/ffmpeg: make the muxer AVFormatContext private to ffmpeg_mux.c
Since the muxer will operate in a separate thread in the future, the
muxer context should not be accessed from the outside.
2022-07-23 11:53:19 +02:00
Anton Khirnov
4403851ca9 fftools/ffmpeg: only set OutputStream.frame_number for video encoding
It is unused otherwise.

Rename the field to vsync_frame_number to better reflect its current
purpose.
2022-07-23 11:53:19 +02:00
Anton Khirnov
4cd19eaffa fftools/ffmpeg: stop using OutputStream.frame_number in print_report()
This field means different things when the video is encoded (number of
frames emitted to the encoding sync queue/encoder by the video sync
code) or copied (number of packets sent to the muxer sync queue).

Print the value of packets_written instead, which means the same thing
in both cases. It is also more accurate, since packets may be dropped by
the sync queue or bitstream filters.
2022-07-23 11:53:19 +02:00
Anton Khirnov
587081a179 fftools/ffmpeg: use the sync queues to handle -frames
Same issues apply to it as to -shortest.

Changes the results of the following tests:
- matroska-flac-extradata-update
  The test reencodes two input FLAC streams into three output FLAC
  streams. The last output stream is limited to 8 frames. The current
  code results in the first two output streams having 12 frames, after
  this commit all three streams have 8 frames and are the same length.
  This new result is better, since it is predictable.
- mkv-1242
  The test streamcopies one video and one audio stream, video is limited
  to 11 frames. The new result shortens the audio stream so that it is
  not longer than the video.
2022-07-23 11:53:19 +02:00
Anton Khirnov
919638ff5c fftools/ffmpeg_mux: reindent 2022-07-23 11:53:19 +02:00
Anton Khirnov
4740fea7dd fftools/ffmpeg: rework -shortest implementation
The -shortest option (which finishes the output file at the time the
shortest stream ends) is currently implemented by faking the -t option
when an output stream ends. This approach is fragile, since it depends
on the frames/packets being processed in a specific order. E.g. there
are currently some situations in which the output file length will
depend unpredictably on unrelated factors like encoder delay. More
importantly, the present work aiming at splitting various ffmpeg
components into different threads will make this approach completely
unworkable, since the frames/packets will arrive in effectively random
order.

This commit introduces a "sync queue", which is essentially a collection
of FIFOs, one per stream. Frames/packets are submitted to these FIFOs
and are then released for further processing (encoding or muxing) when
it is ensured that the frame in question will not cause its stream to
get ahead of the other streams (the logic is similar to libavformat's
interleaving queue).

These sync queues are then used for encoding and/or muxing when the
-shortest option is specified.

A new option – -shortest_buf_duration – controls the maximum number of
queued packets, to avoid runaway memory usage.

This commit changes the results of the following tests:
- copy-shortest[12]: the last audio frame is now gone. This is
  correct, since it actually outlasts the last video frame.
- shortest-sub: the video packets following the last subtitle packet are
  now gone. This is also correct.
2022-07-23 11:53:19 +02:00
Anton Khirnov
9ac78fb347 fftools: add an object pool
Allows to avoid constantly allocating and freeing objects like AVFrame
or AVPacket.
2022-07-23 11:53:19 +02:00
Anton Khirnov
d02ae31fb2 fftools/ffmpeg: use pre-BSF DTS for choosing next output
The following commits will add a new buffering stage after bitstream
filters, which should not be taken into account for choosing next
output.

OutputStream.last_mux_dts is also used by the muxing code to make up
missing DTS values - that field is now moved to the muxer-private
MuxStream object.
2022-07-23 11:53:19 +02:00
Anton Khirnov
b2b9e9ccee fftools/ffmpeg: use last filter output pts to choose next output stream
This will be needed in following commits that will add new buffering
stages after encoding and bitstream filtering.
2022-07-23 11:53:19 +02:00
Anton Khirnov
d55b8dbcff fate/ffmpeg: add a test for interleaving video+subs 2022-07-23 11:53:19 +02:00
Anton Khirnov
f52d045e34 fftools/ffmpeg: do not send spurious EOF for streamcopy when looping 2022-07-23 11:53:19 +02:00
Anton Khirnov
481b27e850 fftools/ffmpeg: use refcounted packets for encoded subtitles 2022-07-23 11:53:19 +02:00
Anton Khirnov
dceccd4aeb fftools/ffmpeg: move freeing 2pass input stats to a better place
The current placement of this free is historical - it used to be
followed by avcodec_close(), since removed.

The proper place for freeing the stats is currently right before the
encoder context itself is freed.
2022-07-23 11:53:19 +02:00
Anton Khirnov
52fee96ae9 fftools/ffmpeg: move output file opts into private context
It is private to the muxer, no reason to access it from outside.
2022-07-23 11:53:19 +02:00
Anton Khirnov
ec00b005f9 fftools/ffmpeg_mux: split of_write_packet()
It is currently called from two places:
- output_packet() in ffmpeg.c, which submits the newly available output
  packet to the muxer
- from of_check_init() in ffmpeg_mux.c after the header has been
  written, to flush the muxing queue

Some packets will thus be processed by this function twice, so it
requires an extra parameter to indicate the place it is called from and
avoid modifying some state twice.

This is fragile and hard to follow, so split this function into two.
Also rename of_write_packet() to of_submit_packet() to better reflect
its new purpose.
2022-07-23 11:53:19 +02:00
Anton Khirnov
6999a3cb18 fftools/ffmpeg_mux: split queuing packets into a separate function 2022-07-23 11:53:19 +02:00
Anton Khirnov
9c2b800203 fftools/ffmpeg: move the mux queue into muxer private data
The muxing queue currently lives in OutputStream, which is a very large
struct storing the state for both encoding and muxing. The muxing queue
is only used by the code in ffmpeg_mux, so it makes sense to restrict it
to that file.

This makes the first step towards reducing the scope of OutputStream.
2022-07-23 11:53:19 +02:00
Anton Khirnov
35bfcff07f fftools/ffmpeg: do not log to the muxer context
All other logging goes to NULL context.
2022-07-23 11:53:19 +02:00
Anton Khirnov
48989efb76 fftools/ffmpeg: access output file chapters through a wrapper
Avoid accessing the muxer context directly, as this will become
forbidden in future commits.
2022-07-23 11:53:19 +02:00
Anton Khirnov
4877842bb5 fftools/ffmpeg: refactor the code checking for bitexact output
Figure out earlier whether the output stream/file should be bitexact and
store this information in a flag in OutputFile/OutputStream.

Stop accessing the muxer in set_encoder_id(), which will become
forbidden in future commits.
2022-07-23 11:53:19 +02:00
Anton Khirnov
cc1cc2c65e fftools/ffmpeg: move closing the file into of_write_trailer()
The current code postpones closing the files until after printing the
final report, which accesses the output file size. Deal with this by
storing the final file size before closing the file.
2022-07-23 11:53:19 +02:00
Anton Khirnov
cc49646077 fftools/ffmpeg: write the header for stream-less outputs when initializing the muxer
There is no reason to delay this.
2022-07-23 11:53:19 +02:00
Anton Khirnov
12e9e50219 fftools/ffmpeg: set want_sdp when initializing the muxer
Allows making the variable local to ffmpeg_mux.
2022-07-23 11:53:19 +02:00
Anton Khirnov
d8e944c238 fftools/ffmpeg: refactor limiting output file size with -fs
Move the file size checking code to ffmpeg_mux. Use the recently
introduced of_filesize(), making this code consistent with the size
shown by print_report().
2022-07-23 11:53:19 +02:00
Anton Khirnov
81af4dec27 fftools/ffmpeg: fix the type of limit_filesize
The option is parsed as INT64 (signed). It is also compared to the
output of avio_tell(), which is also int64_t.
2022-07-23 11:53:19 +02:00
Anton Khirnov
9fe62a545f fftools/ffmpeg: add a helper function to access output file size
Stop accessing muxer internals from outside of ffmpeg_mux.
2022-07-23 11:53:19 +02:00
Anton Khirnov
6a23be92d2 fftools/ffmpeg_mux: add private muxer context
Move header_written into it, which is not (and should not be) used by
any code outside of ffmpeg_mux.

In the future this context will contain more muxer-private state that
should not be visible to other code.
2022-07-23 11:53:19 +02:00
Michael Niedermayer
009ef35d38 avcodec/hevc_filter: copy_CTB() only within width&height
Fixes: out of array access
Fixes: 49271/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5424984922652672

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-22 17:25:25 +02:00
Michael Niedermayer
76112c2b41 avcodec/tiff: Check tile_length and tile_width
Fixes: Division by 0
Fixes: 49235/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-5495613847896064

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-22 17:25:25 +02:00
James Almer
5114ce1e2a avcodec/aacdec: remove skip samples multiplier
The amount of padding samples reported by containers take into account the
extended samplerate in HE-AAC.

Fixes ticket #9671.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-07-22 09:19:11 -03:00
Ting Fu
130d19bf20 lavf/sr: fix the segmentation fault caused by incorrect input frame free.
This issue would cause segmetaion fault when running srcnn model with
sr filter by TensorFlow backend. This filter would free the frame incorectly.

Signed-off-by: Ting Fu <ting.fu@intel.com>
2022-07-22 08:15:04 +08:00
Michael Niedermayer
4e145f1dcd avcodec/mss4: Check image size with av_image_check_size2()
Fixes: Timeout
Fixes: 48418/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MTS2_fuzzer-4834851466903552

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:30:14 +02:00
Michael Niedermayer
8af798171b avformat/mpc8: Check and propagate more errors
Fixes: Timeout
Fixes: 48846/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-5278532493770752

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:28:52 +02:00
Michael Niedermayer
ceff5d7b74 avformat/flvdec: Check for EOF in index reading
Fixes: Timeout
Fixes: 47992/clusterfuzz-testcase-minimized-ffmpeg_dem_LIVE_FLV_fuzzer-6020443879899136

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:28:27 +02:00
Michael Niedermayer
b5de084aa6 avformat/nutdec: Check get_packetheader() in mainheader
Fixes; Timeout
Fixes: 48794/clusterfuzz-testcase-minimized-ffmpeg_dem_NUT_fuzzer-6524604713140224

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:27:52 +02:00
Michael Niedermayer
744ad45c44 avformat/mov: Check for EOF in mov_read_iloc()
Fixes: Timeout
Fixes: 49216/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-6563000529584128

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:27:45 +02:00
Michael Niedermayer
9b23eb8a10 tools/target_dec_fuzzer: Adjust threshold for MWSC
Fixes: Timeout
Fixes: 49172/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MWSC_fuzzer-5213749102903296

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:27:38 +02:00
Michael Niedermayer
8ed78486fc avformat/asfdec_f: Use 64bit for packet start time
Fixes: signed integer overflow: 2147483647 + 32 cannot be represented in type 'int'
Fixes: 49014/clusterfuzz-testcase-minimized-ffmpeg_dem_ASF_fuzzer-6314973315334144

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:27:32 +02:00
Michael Niedermayer
614a4d1476 avcodec/exr: Check x/ysize
Fixes: OOM
Fixes: 48911/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_EXR_fuzzer-6352002510094336

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 19:27:27 +02:00
Michael Niedermayer
f7d510b33f avcodec/ffv1dec: Fix AC_GOLOMB_RICE min size check
Found-by: mkver

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-21 08:54:22 +02:00
Michael Niedermayer
15785e044e avcodec/ffv1dec: consider run increase in minimal golomb frame size
Fixes: Timeout
Fixes: 49160/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-5672826144686080

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-20 16:13:20 +02:00
Michael Niedermayer
3592b05c84 tools/target_dec_fuzzer: Adjust threshold for MMVIDEO
Fixes: Timeout
Fixes: 49003/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MMVIDEO_fuzzer-5550368423018496

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-20 16:13:20 +02:00
Michael Niedermayer
282589771a avcodec/mpeg4videoenc: fix encoding long frames
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-20 16:13:20 +02:00
Michael Niedermayer
3c43a7a354 avcodec/hdrdec: lines can be empty
Fixes: infinite loop
Fixes: 49223/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HDR_fuzzer-6603308596330496

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-07-20 16:12:08 +02:00
Wenbin Chen
636a629ff6 libavfilter/vf_overlay_qsv: Use format of first input to set output format for overlay_qsv
overlay_qsv hard coded to use nv12 as output format. Now use the format
of the first input to set output format.

For detailed information of supported format on different platform,
please see the "composition" rows in "Video Processing Features" at
below link:
https://www.intel.com/content/www/us/en/develop/documentation/media-capabilities-of-intel-hardware/top.html

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-07-20 12:35:23 +08:00
Wenbin Chen
52ad617af5 libavcodec/qsvenc: Use parameter from AVCodecContext to reset qsv codec
Using parameter from AVCodecContext to reset qsv codec is more suitable
for MFXVideoENCODE_Reset()'s usage. Per-frame metadata is more suitable
for the usage of mfxEncodeCtrl being passed to
MFXVideoENCODE_EncodeFrameAsync(). Now change it to use the value
from AVCodecContext.
Because q->param is passed to both "in" and "out" parameters when call
MFXVideoENCODE_Query(), the value in q->param may be changed. New
variables are added to store old configuration, so that we can detect
real parameter change.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-07-20 12:35:23 +08:00
Wenbin Chen
8b82c9cdc7 libavcodec/qsvenc: Change the parameter log to be thread safe
Dividing one line log into several av_log() call is not thread safe. Now
merge these strings into one av_log() call.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-07-20 12:35:23 +08:00
Timo Rothenpieler
926f355aff avfilter/vsrc_ddagrab: check for existence of DPI_AWARENESS_CONTEXT
Apparently some (broken?) Windows SDK versions define IDXGIOutput5
but not DPI_AWARENESS_CONTEXT. So we need to explicitly check for its
existence.
2022-07-19 13:57:38 +02:00
Anton Khirnov
ecd0a7c5bd lavfi/vf_showinfo: print frame durations 2022-07-19 12:27:18 +02:00