Commit Graph

1144 Commits

Author SHA1 Message Date
Anton Khirnov fa717baaa5 fftools/ffmpeg_enc: constify the subtitle passed to enc_subtitle() 2023-06-19 09:48:56 +02:00
Anton Khirnov e89a6d1089 fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder
It does not need to be visible outside of decoding code.
2023-06-19 09:48:56 +02:00
Anton Khirnov a45b9d35b9 fftools/ffmpeg: move fix_sub_duration_heartbeat() to ffmpeg_dec
This way ffmpeg.c does not need to access InputStream.prev_sub and it
can be made private.
2023-06-19 09:48:55 +02:00
Anton Khirnov 01897c1788 fftools/ffmpeg_dec: move decoding to a separate thread
This is only a preparatory step to a fully threaded architecture and
does not yet make decoding truly parallel - the main thread will
currently submit a packet and wait until it has been fully processed by
the decoding thread before moving on. Decoder behavior as observed by
the rest of the program should remain unchanged. That will change in
future commits after encoders and filters are moved to threads and a
thread-aware scheduler is added.
2023-06-19 09:48:55 +02:00
Anton Khirnov 5293adb1a7 fftools/ffmpeg: attach bits_per_raw_sample information to frames
This way avoids encoders reaching into filters or decoders for this
information.
2023-06-19 09:48:55 +02:00
Anton Khirnov 7d4e00ccf0 fftools/ffmpeg_dec: stop using Decoder.pkt
It is only used for flushing the subtitle decoder, so allocate a
dedicated packet for that.

Keep Decoder.pkt unused for now, it will be repurposed in future
commits.
2023-06-19 09:48:55 +02:00
Anton Khirnov 1bdd53e2f9 fftools/ffmpeg_filter: make configure_filtergraph() static
It is no longer used outside of ffmpeg_filter.
2023-06-19 09:48:55 +02:00
Anton Khirnov b1a213ab5d fftools/ffmpeg_filter: reject filtergraphs with zero outputs
Nothing useful can be done with them currently.
2023-06-19 09:48:55 +02:00
Anton Khirnov a7aa05c599 fftools/ffmpeg_filter: add an AVClass to FilterGraph
Use it for logging.
2023-06-19 09:48:55 +02:00
Anton Khirnov a934392db0 fftools/ffmpeg_enc: move dup_warning global variable to Encoder 2023-06-19 09:48:55 +02:00
Anton Khirnov 1adad44fc7 fftools/ffmpeg_dec: move InputStream.hwaccel_pix_fmt to Decoder
It is purely decoder-internal state.
2023-06-19 09:48:55 +02:00
Anton Khirnov 174cb3accf fftools/ffmpeg_dec: remove pointless InputStream.hwaccel_retrieve_data
It is always set to hwaccel_retrieve_data() from ffmpeg_hw.c, so that
function can just be called directly instead.
2023-06-19 09:48:55 +02:00
Anton Khirnov 25d96ab6c0 fftools/ffmpeg_hw: inline hwaccel_decode_init() into its caller
The function is now trivial and cannot fail, so all error handling in
its caller can be removed.
2023-06-19 09:48:55 +02:00
Anton Khirnov 6c9cbf7507 fftools/ffmpeg_demux: reindent after previous commit 2023-06-19 09:48:55 +02:00
Anton Khirnov 98766dbbd7 fftools/ffmpeg_demux: move the loop out of add_input_streams()
Make the function process just one input stream at a time and save an
indentation level. Also rename it to ist_add() to be consistent with an
analogous function in ffmpeg_mux_init.
2023-06-19 09:48:55 +02:00
Anton Khirnov df81fb46ee fftools/ffmpeg_dec: simplify process_subtitle()
Its got_output argument always points to 1.
2023-06-19 09:48:55 +02:00
Anton Khirnov e9eb44ed88 fftools/ffmpeg_dec: drop always-0 InputStream.prev_sub.ret 2023-06-19 09:48:55 +02:00
Anton Khirnov 141d11cb3c fftools/ffmpeg_mux: make OutputStream.pkt private
It is no longer used outside of muxing code.
2023-06-05 16:16:13 +02:00
Anton Khirnov 730a2221af fftools/ffmpeg_enc: use a private AVPacket instance for encoding
The code currently uses OutputStream.pkt, which complicates its
ownership semantics.
2023-06-05 16:16:12 +02:00
Anton Khirnov f94957e8f4 fftools/ffmpeg_mux: simplify calling of_output_packet()
Use NULL packets to signal EOF instead of a separate variable. This is
made possible by the previous commit.
2023-06-05 16:16:12 +02:00
Anton Khirnov 96e1325d91 fftools/ffmpeg_mux: use a dedicated packet for BSF output
Currently of_output_packet() reuses the input packet, which requires its
callers to submit blank packets even on EOF, which makes the code more
complex.
2023-06-05 16:16:12 +02:00
Anton Khirnov c803b36b8f fftools/ffmpeg_enc: stop using OutputStream.initialized
It is set by the muxing code, which will not be synchronized with
encoding code after upcoming threading changes. Use an encoder-private
variable instead.
2023-06-05 16:15:04 +02:00
Anton Khirnov 568d414074 fftools/ffmpeg: attach filter framerate to frames
This way the encoder does not need to reach backward into the filter.
2023-06-05 16:15:04 +02:00
Anton Khirnov 9630341073 fftools/ffmpeg: factor out attaching FrameData to a frame
Will be useful in following commits.
2023-06-05 16:15:04 +02:00
Anton Khirnov d7781cfb95 fftools/ffmpeg: convert timestamps inside the muxer
Packets submitted to the muxer now have their timebase attached to them,
so the muxer can do conversion to muxing timebase and avoid exposing it
to callers.
2023-06-05 16:15:04 +02:00
Anton Khirnov cf121592c5 fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding
The values currently written into it are not used after
enc_open(), so it is better to confine them to that function.
2023-06-05 16:15:04 +02:00
Anton Khirnov 5bea8daa78 fftools/ffmpeg_enc: do not guess frame durations from output framerate
There is no reason to expect input frame durations to match output
framerate.
2023-06-05 16:15:04 +02:00
Anton Khirnov 2f92650c5d fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers
The function now reduces to a ternary operator, so it is shorter and
clearer to eliminate it.
2023-06-05 16:15:04 +02:00
Anton Khirnov 93e26a4db7 fftools/ffmpeg: handle -enc_time_base -1 during stream creation
There is no reason to postpone it until opening the encoder. Also, abort
when the input stream is unknown, rather than disregard an explicit
request from the user.
2023-06-05 16:15:04 +02:00
Anton Khirnov 58a64e3d54 fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded
It has no effect otherwise.
2023-06-05 16:15:04 +02:00
Anton Khirnov 2baae6434b fftools/ffmpeg_enc: merge two adjacent video-specific blocks
There is no meaningful reason for them to be separated.
2023-06-05 16:15:04 +02:00
Anton Khirnov c8a85d1b2f fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy
The values currently written into it are not used after
streamcopy_init(), so it is better to confine them to that function.
2023-06-05 16:15:04 +02:00
Anton Khirnov ccf219e361 fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code
The code will currently add a small offset to avoid exact midpoints, but
this can cause inexact results when a float timestamp is exactly
representable as an integer.

Fixes off-by-one in the first frame duration in multiple FATE tests.
2023-06-05 16:15:04 +02:00
Anton Khirnov c7a05ac117 fftools/ffmpeg_demux: do not set AVCodecContext.framerate
For decoding, this field is used by the decoder to export information
to the caller; it does not make sense for the caller to set it.
2023-06-05 16:15:04 +02:00
Anton Khirnov d8c61ba723 fftools/ffmpeg_filter: drop a block disabled since 2012 2023-06-05 16:15:04 +02:00
Anton Khirnov ad14bdbcfd fftools/ffmpeg_filter: drop a write-only variable 2023-06-05 16:15:04 +02:00
Anton Khirnov 57021a68d9 fftools/ffmpeg_mux: set stream duration after the timebase is certainly known
Stop assuming the encoder knows the muxing timebase, which does not
always have to hold (e.g. due to bitstream filters).
2023-06-05 16:15:04 +02:00
Anton Khirnov ba1141d8a9 fftools/ffmpeg_enc: move nb_frames{dup,drop} globals into OutputStream 2023-06-05 16:15:04 +02:00
Anton Khirnov ba2c791627 fftools/ffmpeg_filter: do not flush encoders on parameter change
It makes no sense to do so.
2023-05-31 16:20:19 +02:00
Anton Khirnov 106167374c fftools/ffmpeg_mux: flush bsfs immediately on exceeding recoding time
Current code marks the output stream as finished and waits for a flush
packet, but that is both unnecessary and suspect, as in theory nothing
should be sent to a finished stream - not even flush packets.
2023-05-31 16:20:19 +02:00
Anton Khirnov 2674532eee fftools/ffmpeg_filter: constify the argument of filtergraph_is_simple() 2023-05-31 16:20:19 +02:00
Anton Khirnov 3bfc2c589a fftools/ffmpeg_filter: make InputStream.filter private
It is no longer accessed outside of ffmpeg_filter.
2023-05-31 16:20:19 +02:00
Anton Khirnov 5924b70075 fftools/ffmpeg_filter: make ifilter_has_all_input_formats() static
It is no longer used outside ffmpeg_filter.
2023-05-31 16:20:19 +02:00
Anton Khirnov 2262df5e8a fftools/ffmpeg_filter: drop unreachable code
Filtergraphs with no inputs are initialized as soon as all their outputs
are bound, so this code should not be reachable.
2023-05-31 16:20:19 +02:00
Anton Khirnov f3e0a83e8e fftools/ffmpeg_enc: stop configuring filters from encoder flush
There is no way for a filtergraph to have all input parameters, yet not
be configured, so this code should not be reachable.
2023-05-31 16:20:19 +02:00
Anton Khirnov f8abab673c fftools/ffmpeg: move sub2video handling to ffmpeg_filter
Make all relevant state per-filtergraph input, rather than per-input
stream. Refactor the code to make it work and avoid leaking memory when
a single subtitle stream is sent to multiple filters.
2023-05-31 16:20:19 +02:00
Anton Khirnov 20cacfe493 fftools/ffmpeg: rework setting sub2video parameters
Set them in ifilter_parameters_from_dec(), similarly to audio/video
streams. This reduces the extent to which sub2video filters need to be
treated specially.
2023-05-31 16:20:19 +02:00
Anton Khirnov ea5c39cef6 fftools/ffmpeg: tweak sub2video_heartbeat() arguments
This function should not take an InputStream, as it only uses it to get
the InputFile and the timebase. Pass those directly instead and avoid
confusion over dealing with multiple InputStreams.
2023-05-31 16:20:19 +02:00
Anton Khirnov a6d67b11f5 fftools/ffmpeg_filter: move sub2video subtitle queue to InputFilterPriv
This queue should be associated with a specific filtergraph input - if
a subtitle stream is sent to multiple filters then each should have its
own queue.
2023-05-31 16:20:19 +02:00
Anton Khirnov 5d530e3a72 fftools/ffmpeg_dec: move sub2video submission to ffmpeg_filter
This code is a sub2video analogue of ifilter_send_frame(), so it
properly belongs to the filtering code.

Note that using sub2video with more than one target for a given input
subtitle stream is currently broken and this commit does not change
that. It will be addressed in following commits.
2023-05-31 16:19:49 +02:00
Anton Khirnov 3d35b73b2a fftools/ffmpeg: constify AVSubtitle parameters as appropriate 2023-05-31 16:15:47 +02:00
Anton Khirnov ad4efb9158 fftools/ffmpeg_filter: try to configure filtergraphs earlier
When the filtergraph has no inputs, it can be configured immediately
when all its outputs are bound to output streams. This will simplify
treating some corner cases.
2023-05-31 16:15:47 +02:00
Anton Khirnov 7520cd9f07 fftools/ffmpeg_mux_init: move OutputFilter setup code to ffmpeg_filter
That is a more appropriate place for it.
2023-05-31 16:15:47 +02:00
Anton Khirnov 87b576135e fftools/ffmpeg_filter: factor out binding an output stream to OutputFilter
While the new function is trivial for now, it will become more useful in
future commits.
2023-05-31 16:15:47 +02:00
Anton Khirnov dc5864a00c fftools/ffmpeg_filter: create Input/OutputFilters together with FilterGraph
This way the list of filtergraph inputs/outputs is always known after
FilterGraph creation. This will allow treating simple and complex
filtergraphs in a more uniform manner.
2023-05-31 16:15:47 +02:00
Anton Khirnov a1061d4bdc fftools/ffmpeg_filter: move some functions higher up
Needed by the following commit.
2023-05-31 16:15:47 +02:00
Anton Khirnov 00183880aa fftools/ffmpeg_filter: decouple allocating InputFilter and binding it to InputStream
Will be useful in future commits.
2023-05-31 16:15:47 +02:00
Anton Khirnov 7ea10bfef3 fftools/ffmpeg_filter: store just the link label in OutputFilter
Not the entire AVFilterInOut. This is simpler.
2023-05-31 16:15:47 +02:00
Anton Khirnov da7ae627e1 fftools/ffmpeg_filter: always pass graph description to fg_create()
Currently NULL would be passed for simple filtergraphs, which would
make the filter code extract the graph description from the output
stream when needed. This is unnecessarily convoluted.
2023-05-31 16:15:47 +02:00
Anton Khirnov badf959ed6 fftools/ffmpeg_filter: use a dedicated variable for marking simple filtergraphs
Do not use an unrelated graph property, which will change in future
commits.
2023-05-31 16:15:47 +02:00
Anton Khirnov b56db2956b fftools/ffmpeg: add logging for creating output streams 2023-05-31 16:15:47 +02:00
Anton Khirnov eeb7d92ac7 fftools/ffmpeg_mux_init: merge ost_add_from_filter() to ost_add()
This way ost_add() knows about the complex filtergraph it is fed from,
which will become useful in future commits.
2023-05-31 16:15:47 +02:00
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
Anton Khirnov 7be945a011 fftools/ffmpeg: rename transcode_init()
It does no initialization anymore, except for setting
transcode_init_done - the bulk of the function is printing the
input/output maps. It also cannot fail anymore, so remove the useless
return value.
2023-05-15 13:32:02 +02:00
Anton Khirnov de6d60117e fftools/ffmpeg_demux: stop logging to demuxer context
Only the demuxer itself should do that.
2023-05-15 13:32:02 +02:00
Anton Khirnov c5d77dcbf1 fftools/ffmpeg_demux: move InputFile.ts_offset_discont,last_ts to private data
They are no longer used outside of ffmpeg_demux.
2023-05-15 13:32:02 +02:00
Anton Khirnov ab223a4d8c fftools/ffmpeg: stop accessing input format from decoding code
Export the corresponding flag in InputFile instead. This will allow
making the demuxer AVFormatContext private in future commits, similarly
to what was previously done for muxers.
2023-05-15 13:32:02 +02:00
Anton Khirnov 2ab9f247f7 fftools/ffmpeg: log corrupt-frame errors to the appropriate context 2023-05-15 13:32:02 +02:00
Anton Khirnov a1002bc39c fftools/ffmpeg: replace print_error() by more meaningful messages 2023-05-15 13:32:01 +02:00
Anton Khirnov fd980b2615 fftools/ffmpeg_demux: reindent after previous commit 2023-05-15 13:32:01 +02:00
Anton Khirnov 9429624a76 fftools/ffmpeg: move discarding unused programs to ffmpeg_demux
This is a more appropriate place for this code.
2023-05-15 13:32:01 +02:00
Anton Khirnov f9657b7443 fftools/ffmpeg: simplify tracking -readrate start time
There is no point in having a per-stream wallclock start time, since
they are all computed at the same instant. Keep a per-file start time
instead, initialized when the demuxer thread starts.
2023-05-15 13:32:01 +02:00
Anton Khirnov 6b0c984f0d fftools/ffmpeg_demux: move InputStream.streamcopy_needed to private data
It is no longer used outside of ffmpeg_demux.
2023-05-15 13:32:01 +02:00
Anton Khirnov 7df3253c5a fftools/ffmpeg_demux: move InputStream.wrap_correction_done to private data
It is no longer used outside of ffmpeg_demux.
2023-05-15 13:32:01 +02:00
Anton Khirnov df25e21ce7 fftools/ffmpeg_demux: move InputStream.[next_]dts to private data
They are no longer used outside of ffmpeg_demux.
2023-05-15 13:32:01 +02:00
Anton Khirnov 6d7b43ed44 fftools/ffmpeg_demux: move InputStream.[saw_]first_d?ts to private data
They are no longer used outside of ffmpeg_demux.
2023-05-15 13:32:01 +02:00
Anton Khirnov 57a2b2f886 fftools/ffmpeg_demux: move InputStream.{nb_packets,data_size} to private data
They are no longer used outside of ffmpeg_demux.
2023-05-15 13:32:01 +02:00
Anton Khirnov 6fcfe4307c fftools/ffmpeg: drop unused decode_video() parameter 2023-05-15 13:32:01 +02:00
Anton Khirnov bfd5e7ef5d fftools/ffmpeg_demux: reindent after previous commit 2023-05-15 13:32:01 +02:00
Anton Khirnov 2b99c6bfd5 fftools/ffmpeg: move post-demux packet processing to ffmpeg_demux
That is a more appropriate place for this code and will allow hiding
more of InputStream.

The value of repeat_pict extracted from libavformat internal parser no
longer needs to be trasmitted outside of the demuxing thread.

Move readrate handling to the demuxer thread. This has to be done in the
same commit, since it reads InputStream.dts,nb_packets, which are now
set in the demuxer thread.
2023-05-15 11:03:15 +02:00
Anton Khirnov 09c686788e fftools/ffmpeg: attach InputStream.dts to demuxed packets when needed
This way computing it and using it for streamcopy does not need to
happen in sync. Will be useful in following commits, where updating
InputStream.dts will be moved to the demuxing thread.
2023-05-15 10:57:19 +02:00
Anton Khirnov abf9532bda fftools/ffmpeg_demux: move preparing DemuxMsg to separate function
Will be useful in following commits, which will move more code into this
function.
2023-05-15 10:57:19 +02:00
Anton Khirnov 989e87b03c fftools/ffmpeg: stop using decoder properties in ist_dts_update()
This code runs post-demuxing and is not synchronized with the decoder
output (which may be delayed with respect to its input by arbitrary and
unknowable amounts), so accessing any decoder properties is incorrect.
2023-05-15 10:57:19 +02:00
Anton Khirnov 0d25b404d4 fftools/ffmpeg: reindent after previous commit 2023-05-15 10:57:19 +02:00
Anton Khirnov 702ff2d281 fftools/ffmpeg: consolidate InputStream.[next_]dts updates
Move them to a separate function called right after timestamp
discontinuity processing. This is now possible, since these values have
no interaction with decoding anymore.
2023-05-15 10:57:19 +02:00
Anton Khirnov a238ba9c3c fftools/ffmpeg: stop using deprecated ticks_per_frame 2023-05-15 10:56:48 +02:00
Anton Khirnov 78e84c054a fftools/ffmpeg: fix computing video frame duration from repeat_pict
This field contains the number of _field_ durations by which the
standard frame duration should be extended.
2023-05-15 10:31:55 +02:00
Anton Khirnov 02823210d7 fftools/opt_common: stop printing deprecated AV_CODEC_CAP_SUBFRAMES 2023-05-15 10:24:54 +02:00
James Almer 63d7ea38c7 fftools/ffprobe: print exported stream AVOptions
Similar to the decoder AVOptions, this is useful to show values from options
exported by the demuxer.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-05-08 11:04:37 -03:00
Anton Khirnov 2d43c23b81 fftools/ffmpeg: discard packets for unused streams in demuxing thread
Avoids the pointless overhead of transferring them to the main thread.
2023-05-08 10:38:59 +02:00
Anton Khirnov a0174a235b fftools/ffmpeg_filter: use InputFilterPriv.eof instead of InputFile.eof_reached
The two checks using eof_reached are testing whether more input can
possibly appear on this filtergraph input. InputFilterPriv.eof is the
more authoritative source for this information.
2023-05-08 10:38:59 +02:00
Anton Khirnov dd1c67d539 fftools/ffmpeg: move unconfigured graph handling to ffmpeg_filter
This code more properly belongs there.
2023-05-08 10:38:59 +02:00
Anton Khirnov c26a6c5a52 fftools/ffmpeg_filter: use av_buffer_replace() to improve code
It is shorter and more efficient.
2023-05-08 10:38:59 +02:00
Anton Khirnov 5356f5ed23 fftools/ffmpeg_filter: move InputFilter.hw_frames_ctx to private data
It is not used outside of ffmpeg_filter.
2023-05-08 10:38:59 +02:00
Anton Khirnov 71d7e9bbec fftools/ffmpeg_filter: move InputFilter.displaymatrix to private data
It is not used outside of ffmpeg_filter.
2023-05-08 10:38:59 +02:00
Anton Khirnov e8df737cb2 fftools/ffmpeg_filter: move InputFilter.eof to private data
It is not used outside of ffmpeg_filter.
2023-05-08 10:38:59 +02:00
Anton Khirnov c7c73a3250 fftools/ffmpeg_filter: take fallback parameters from decoder, not demuxer
When an input stream terminates and no frames were successfully decoded,
filtering code will currently configure the filtergraph using demuxer
stream parameters. Use decoder parameters instead, which should be more
reliable. Also, initialize them immediately when an input stream is
bound to a filtergraph input, so that these parameters are always
available (if at all) and filtering code does not need to reach into the
decoder at some arbitrary later point.
2023-05-08 10:38:59 +02:00
Anton Khirnov 48d8d3549a fftools/ffmpeg_enc: stop configuring filter inputs from encoder flush
When no frames are ever seen by an encoder, encoder flush will do a
last-ditch attempt to configure its source filtergraph in order to at
least get the stream parameters. This involves extracting demuxer
parameters from filtergraph source inputs, which is
* a bad layering violation
* probably unreachable, because decoders are flushed before encoders,
  which should call ifilter_send_eof(), which will also set these
  parameters; however due to complex control flow it is hard to be
  entirely sure this code can never be triggered

Even if this code can actually be reached, it is probably better to
return an error as the comment above it says.
2023-05-08 10:38:59 +02:00
Anton Khirnov f5cfb2c5df fftools/ffmpeg: eliminate need_output()
Replace it by simply calling choose_output() earlier.
2023-05-08 10:38:58 +02:00
Anton Khirnov 5673da4797 fftools/ffmpeg: merge choose_output() and got_eagain()
These two functions are a part of a single logical action - determining
which, if any, output stream needs to be processed next. Keeping them
separate is a historical artifact that obscures what is actually being
done.
2023-05-08 10:38:58 +02:00
Anton Khirnov 0e00d23510 fftools/ffmpeg: reduce -re to -readrate 1
They are exactly equivalent, so there is no point in maintaining a
separate flag for -re.
2023-05-07 15:49:27 +02:00