Commit Graph

982 Commits

Author SHA1 Message Date
Anton Khirnov
163e3a299e fftools/sync_queue: make sure non-limiting streams are not used as queue head
A non-limiting stream could mistakenly end up being the queue head,
which would then produce incorrect synchronization, seen e.g. in
fate-matroska-flac-extradata-update for certain number of frame threads
(e.g. 5).

Found-By: James Almer
2023-05-28 10:47:59 +02:00
Anton Khirnov
e9a868e9ee fftools/sync_queue: add debug logging 2023-05-28 10:47:59 +02:00
Anton Khirnov
4e96a71626 fftools/ffmpeg_demux: log discontinuity warnings to stream context
Allows simplifying the log message.
2023-05-28 10:47:59 +02:00
Anton Khirnov
6abb4a28ef fftools/ffmpeg: add InputStream.index
This allows to avoid access to the underlying AVStream in many places.
2023-05-28 10:47:59 +02:00
Anton Khirnov
cad59cccaf fftools/ffmpeg_dec: move timestamp estimation state to Decoder
It is purely internal to decoding.
2023-05-28 10:47:59 +02:00
Anton Khirnov
5b05e9e32a fftools/ffmpeg_dec: move InputStream.pkt to Decoder
It is purely internal to decoding.
2023-05-28 10:47:59 +02:00
Anton Khirnov
dadeb28e25 fftools/ffmpeg_dec: add decoder private data
Move InputStream.decoded_frame to it.

Analogous to what has been previously done for all the other major
components.
2023-05-28 10:47:59 +02:00
Anton Khirnov
335688a3d3 fftools/ffmpeg_demux: skip unused/attachment streams in final stats
No useful information can be printed for them.
2023-05-28 10:47:59 +02:00
Anton Khirnov
d43ae45de0 fftools/ffmpeg_demux: initialize nb_streams_warn
Fixes spurious new-stream warnings for unused streams after
9429624a76
2023-05-28 10:47:59 +02:00
Anton Khirnov
6ee57fd2b6 fftools/ffmpeg_demux: only print demuxing stats if demuxing actually started
If the transcoding process never got to reading any packets from this
input then printing stats is just pointless noise.
2023-05-28 10:47:59 +02:00
Anton Khirnov
d9bcbf9200 fftools/ffmpeg: drop outdated comments 2023-05-28 10:47:59 +02:00
Anton Khirnov
ec75b79fe1 fftools/ffmpeg: fail earlier on text/bitmap subtitles mismatch
Checking whether the user requested an unsupported conversion between
text and bitmap subtitles can be done immediately when creating the
output stream.
2023-05-28 10:47:59 +02:00
Anton Khirnov
2b3905254e fftools/ffmpeg_enc: use AVFrame.hw_frames_ctx for encoder hw setup
It should be the same as the one that can be extracted from the filter
and does not require access to outside data.
2023-05-28 10:47:59 +02:00
Anton Khirnov
f15b206286 fftools/ffmpeg_hw: move hw_device_setup_for_encode() to ffmpeg_enc
This function is entangled with encoder setup, so it is more encoding
code rather than ffmpeg_hw code. This will allow making more encoder
state private in the future.
2023-05-28 10:47:59 +02:00
Anton Khirnov
760a9bd306 fftools/ffmpeg_hw: move hw_device_setup_for_decode() to ffmpeg_dec
This function is entangled with decoder setup, so it is more decoding
code rather than ffmpeg_hw code. This will allow making more decoder
state private in the future.
2023-05-28 10:47:59 +02:00
James Almer
e86e2d5921 fftools/ffmpeg_dec: abort if avcodec_send_packet() returns EAGAIN
As the comment in the code mentions, EAGAIN is not an expected value here
because we call avcodec_receive_frame() until all frames have been returned.
avcodec_send_packet() returning EAGAIN means a packet is still buffered, which
hints that the underlying decoder is buggy and not fetching packets as it
should.

An example of this behavior was in the libdav1d wrapper before f209614290,
where feeding it split frames (or individual OBUs) would result in the CLI
eventually printing the confusing "Error submitting packet to decoder: Resource
temporarily unavailable" error message, and just keep going until EOF without
returning new frames.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-05-26 19:47:54 -03:00
Anton Khirnov
c894f85f72 fftools/ffmpeg_dec: rename decode_video() to video_frame_process()
This function does not do any decoding anymore.
2023-05-22 17:10:44 +02:00
Anton Khirnov
909f5dfae1 fftools/ffmpeg_dec: inline decode_audio() into dec_packet()
The former function is now trivial - it has 3 lines and cannot fail.
2023-05-22 17:10:44 +02:00
Anton Khirnov
959a5decf2 fftools/ffmpeg_dec: deduplicate code in decode_audio/video() 2023-05-22 17:10:44 +02:00
Anton Khirnov
ab3493006f fftools/ffmpeg_dec: merge check_decode_result() into its callers
Not only is this easier to read, this also makes the code shorter.
2023-05-22 17:10:44 +02:00
Anton Khirnov
c08717adae fftools/ffmpeg: reindent after previous commit 2023-05-22 17:10:44 +02:00
Anton Khirnov
748f2999ee fftools/ffmpeg_dec: restructure audio/video decoding loop
It currently emulates the long-removed
avcodec_decode_audio4/avcodec_decode_video2 APIs, which obfuscates the
actual decoding flow. Restructure the decoding calls so that they
naturally follow the new avcodec_send_packet()/avcodec_receive_frame()
design.

This is not only significantly easier to read, but also shorter.
2023-05-22 17:10:44 +02:00
Anton Khirnov
172f901e35 fftools/ffmpeg_dec: deobfuscate subtitle decoding
It is currently handled in the same loop as audio and video, but this
obscures the actual flow, because only one iteration is ever performed
for subtitles.

Also, avoid a pointless packet reference.
2023-05-22 17:10:44 +02:00
Anton Khirnov
dbf1c6f5f1 fftools/ffmpeg: move decoding code to ffmpeg_dec 2023-05-22 17:10:44 +02:00
Anton Khirnov
79c1dde5c3 fftools/ffmpeg: split decoding loop out of process_input_packet()
process_input_packet() contains two non-interacting pieces of nontrivial
size and complexity - decoding and streamcopy. Separating them makes the
code easier to read.
2023-05-22 17:10:44 +02:00
Anton Khirnov
b5beff3f15 fftools/ffmpeg: move a block to a more appropriate place
New placement requires fewer explicit conditions and is easier to
understand.
The logic should be exactly equivalent, since this is the only place
where eof_reached is set for decoding.
2023-05-22 17:10:44 +02:00
Anton Khirnov
4cec5ffc45 fftools/ffmpeg: rework handling -max_error_rate
Replace the decode_error_stat global with a per-input-stream variable.
Also, print an error message when the error rate is exceeded.
2023-05-22 17:10:44 +02:00
Anton Khirnov
d064c9ded5 fftools/ffmpeg: deobfuscate check_decode_result() call
Passing ist=NULL is currently used to identify stream types that do not
decode into AVFrames, i.e. subtitles. That is highly non-obvious -
always pass a non-NULL InputStream and just check the type explicitly.
2023-05-22 17:10:44 +02:00
Anton Khirnov
4fbc699ac3 fftools/ffmpeg: replace an unreachable return with av_assert0(0)
This cannot be reached, because initialization will fail if decoding is
requested for a stream but no decoder can be found.
2023-05-22 17:10:44 +02:00
Anton Khirnov
4a59dde0c7 fftools/ffmpeg: eliminate InputStream.got_output
It tracks whether the decoder for this stream ever produced any frames
and its only use is for checking whether a filter input ever received a
frame - those that did not are prioritized by the scheduler.

This is awkward and unnecessarily complicated - checking whether the
filtergraph input format is valid works just as well and does not
require maintaining an extra variable.
2023-05-22 17:10:44 +02:00
Anton Khirnov
5fa00b38e6 fftools/ffmpeg: drop an obsolete hack
This special handling for decoder flushing has not been needed since
af1761f7b5, as the filtergraph actually is drained after that commit.
2023-05-22 17:10:44 +02:00
Anton Khirnov
37fcbe121d fftools/cmdutils: constify the argument of get_rotation() 2023-05-22 17:10:44 +02:00
Anton Khirnov
9effea016c fftools/ffmpeg_filter: embed displaymatrix into private context
It has a small fixed size, so it is better to embed it rather than deal
with dynamic allocation.
2023-05-22 17:10:44 +02:00
Anton Khirnov
dcfbfb417c fftools/ffmpeg_filter: keep track of the real filter input type
Avoid extracting it from various remote sources.
2023-05-22 17:10:44 +02:00
Anton Khirnov
f980df2c04 fftools/ffmpeg_filter: move InputFilter.type to private data
It is not accessed outside of ffmpeg_filter.
2023-05-22 17:10:44 +02:00
Anton Khirnov
c4a3f7edb8 fftools/ffmpeg_filter: move InputFilter.ist to private data
It is not accessed outside of ffmpeg_filter.
2023-05-22 17:10:44 +02:00
Anton Khirnov
0f501b2ad9 fftools/ffmpeg_filter: drop a redundant error message
In case no decoder is available, dec_open() called from ist_use() will
fail with 'Decoding requested, but no decoder found', so this check is
redundant.
2023-05-22 17:10:44 +02:00
Anton Khirnov
89b37ae70a fftools/ffmpeg_filter: make input filter configured parameters private
They are not used outside of ffmpeg_filter.
2023-05-22 17:10:44 +02:00
Anton Khirnov
82c75ddfad fftools/ffmpeg: move ifilter_has_all_input_formats() to ffmpeg_filter
That is a more appropriate place for that function.
2023-05-22 17:10:44 +02:00
Anton Khirnov
2628c7049e fftools/ffmpeg_filter: try configuring graphs from input EOF
When a filtergraph input receives EOF but never saw any input frames, we
use the fallback parameters. Currently an attempt to actually configure
the filtergraph will happen elsewhere, but there is no reason to
postpone this.
2023-05-22 17:10:44 +02:00
Anton Khirnov
a16d7171d1 fftools/ffmpeg_filter: only use fallback parameters when necessary
With complex filtergraphs it can happen that the filtergraph is
unconfigured because some other filter than the one we just got EOF on
is missing parameters.

Make sure that the fallback parametes for a given input are only used
when that input is unconfigured.
2023-05-22 17:10:44 +02:00
Anton Khirnov
65f3d042a6 fftools/ffmpeg_demux: disallow using disabled input streams
This is less ad-hoc than checking explicitly in every place that binds
an input stream to a filter or output.
2023-05-22 17:10:44 +02:00
Anton Khirnov
dfa29ba955 fftools/ffmpeg: return error codes from ist_*_add()
Will be useful in future commits.
2023-05-22 17:10:44 +02:00
Anton Khirnov
ede6794d6a fftools/ffmpeg_filter: split finding an unused stream into a function
Avoids filtering code from digging in demuxer internals.
2023-05-22 17:10:44 +02:00
Anton Khirnov
30a3fee24f fftools/ffmpeg: rework applying input -r
Do not use a separate counter for CFR timestamps forced with -r used as
an input option. Set durations properly and let estimation code do the
rest.
2023-05-22 17:10:44 +02:00
Anton Khirnov
1132507327 fftools/ffmpeg_filter: make sure pkt_duration matches duration
Otherwise the two values might get desynchronized and lavfi can prefer
the wrong one.
2023-05-22 17:10:44 +02:00
Anton Khirnov
14b9946967 fftools/ffmpeg_filter: convert input frame timestamps
Decoder timebase does not always have to match filter timebase.
2023-05-22 17:10:44 +02:00
Anton Khirnov
7b41785eb6 fftools/ffmpeg: replace stream timebase with decoded frame one
They are the same for now, but this may change in the future.
2023-05-22 17:10:44 +02:00
Anton Khirnov
1372e81aaa fftools/ffmpeg: drop a useless local variable
Store decoded frame timestamp directly in AVFrame.pts, there is no
advantage to using a separate local variable for it.
2023-05-22 17:10:44 +02:00
Anton Khirnov
94a9647195 fftools/ffmpeg: shorten a variable name
There is only one frame used in decode_video() -- the one output by the
decoder. So there is no point in explicitly calling it the _decoded_
frame.
2023-05-22 17:10:44 +02:00