Commit Graph

131 Commits

Author SHA1 Message Date
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 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 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 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 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 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 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 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 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 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 5b3aeab1bd fftools/ffmpeg_filter: use correct timebase for filter EOF timestamp
It does not need to be equal to demuxer timebase.
2023-05-02 10:59:24 +02:00
Anton Khirnov 0aada80e73 fftools/ffmpeg_filter: keep track of filtergraph input timebase
Will be useful in following commits.
2023-05-02 10:59:24 +02:00
Anton Khirnov 04f0c40c74 fftools/ffmpeg_filter: add InputFilter private data
Move InputFilter.frame_queue to it, which is not accessed outside of
ffmpeg_filter.
2023-05-02 10:59:24 +02:00
Anton Khirnov 1dcae45ecb fftools/ffmpeg_filter: factorize allocating InputFilter 2023-05-02 10:59:24 +02:00
Anton Khirnov 87ced7aee0 fftools/ffmpeg_filter: make graph_desc private
It is not used outside of ffmpeg_filter.
2023-05-02 10:59:24 +02:00
Anton Khirnov 09dd9c5f41 fftools/ffmpeg_filter: add filtergraph private data
Start by moving OutputStream.filtered_frame to it, which really belongs
to the filtergraph rather than the output stream.
2023-05-02 10:59:24 +02:00
Anton Khirnov aee5b774bf fftools/ffmpeg_filter: make ifilter_parameters_from_frame() static
It is no longer used outside of this file.
2023-05-02 10:59:24 +02:00
James Almer 1b7c13e1a4 fftools/ffmpeg_filter: fix leak of AVIOContext in read_binary()
It was only being freed on failure.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-04-28 13:46:13 -03:00
Anton Khirnov 11872522b1 fftools/ffmpeg_filter: reindent after previous commit 2023-04-24 16:56:06 +02:00