Commit Graph

451 Commits

Author SHA1 Message Date
Anton Khirnov 99d2fa38ad fftools/ffmpeg: make sure FrameData is writable when we modify it
Also, add a function that returns const FrameData* for cases that only
read from it.
2023-12-06 10:30:28 +01:00
Anton Khirnov 7c97a0c63f fftools/ffmpeg: move a few inline function into a new header
Will allow to use them in future commits without including the whole
ffmpeg.h.
2023-11-14 18:18:26 +01:00
Martin Storsjö ff5a3575fe fftools: Check HAVE_GETSTDHANDLE before using GetStdHandle
GetStdHandle is unavailable outside of the desktop API subset.

This didn't use to be a problem with earlier WinSDKs, as kbhit also
used to be available only for desktop apps, and this whole section is
wrapped in #if HAVE_KBHIT. With newer WinSDKs, kbhit() is available also
for non-desktop apps, while GetStdHandle still isn't.

Signed-off-by: Martin Storsjö <martin@martin.st>
2023-10-23 13:08:39 +03:00
Anton Khirnov 9196be2fb1 fftools/ffmpeg_enc: move fps conversion code to ffmpeg_filter
Its function is analogous to that of the fps filter, so filtering is a
more appropriate place for this.

The main practical reason for this move is that it places the encoding
sync queue right at the boundary between filters and encoders. This will
be important when switching to threaded scheduling, as the sync queue
involves multiple streams and will thus need to do nontrivial
inter-thread synchronization.

In addition to framerate conversion, the closely-related
* encoder timebase selection
* applying the start_time offset
are also moved to filtering.
2023-10-10 12:41:31 +02:00
Anton Khirnov 61777c62d7 fftools/ffmpeg: stop accessing OutputStream.last_dropped in print_report()
That field is used by the framerate code to track whether any output has
been generated for the last input frame(*). Its use in the last
invocation of print_report() is meant to account for the very last
filtered frame being dropped in the number of dropped frames printed in
the log. However, that is a highly inappropriate place to do so, as it
makes assumptions about vsync logic in completely unrelated code. Move
the increment to encoder flush instead.

(*) the name is misleading, as the input frame has not yet been dropped
    and may still be output in the future
2023-10-10 12:41:31 +02:00
Anton Khirnov e35d36eb72 ffools/ffmpeg_filter: stop trying to handle an unreachable state
ifilter_send_eof() will fail if the input has no real or fallback
parameters, so there is no need to handle the case of some inputs being
in EOF state yet having no parameters.
2023-10-10 12:41:31 +02:00
Anton Khirnov ced62a0c01 fftools/ffmpeg: do not fail on AVERROR(EAGAIN) from choose_output()
This is not an error condition, but would be treated like one if the
program terminates on the next transcode loop iteration because of a
signal or keyboard input.

Fixes #10504
Tested-by: https://github.com/0Ky
2023-09-14 10:44:05 +02:00
Anton Khirnov 3c397a1d46 fftools/ffmpeg: move sending filtergraph commands to a separate function
Stop accessing filtergraph internals from keyboard reading code.
2023-08-30 11:53:50 +02:00
Anton Khirnov bff48e8d69 fftools/ffmpeg_mux: rename of_close() to of_free()
This function is primarily a destructor for OutputFile, the underlying
AVIOContext is normally closed earlier (right after writing the
trailer).
2023-08-30 11:53:50 +02:00
Anton Khirnov b39b6b7456 fftools/ffmpeg: simplify handling input -t for streamcopy
Output stream will be closed implicitly after a NULL packet is sent to
it, there is no need to explicitly call close_output_stream().
2023-08-30 11:51:42 +02:00
Anton Khirnov 8f2e7e9dcf fftools/ffmpeg: stop explicitly closing output streams on input EOF
Sending an empty packet already does that implicitly.
2023-08-30 11:51:42 +02:00
Anton Khirnov ccc6849932 fftools/ffmpeg: stop calling exit_program()
Remove exit_program() and register_exit(), as they are no longer used.
2023-07-20 20:47:46 +02:00
Anton Khirnov 2f155b18a1 fftools/ffmpeg: return an error from assert_avoptions() instead of aborting
Rename it to check_avoptions().
2023-07-20 20:47:46 +02:00
Anton Khirnov eda1fac27a fftools/cmdutils: return AVERROR_EXIT for OPT_EXIT options instead of aborting() 2023-07-20 20:47:46 +02:00
Anton Khirnov 8173623e39 fftools/ffmpeg: consolidate exiting from main() on error 2023-07-20 20:47:46 +02:00
Anton Khirnov 518b49a735 fftools/ffmpeg_dec: return error codes from dec_packet() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov e0f4259689 fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov 43bcf631d0 fftools/ffmpeg_enc: return errors from enc_flush() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov 3a89e6d352 fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph
This is more natural, as all except one of its callers require
processing only one filtergraph.
2023-07-20 20:30:13 +02:00
Anton Khirnov 4d06742b93 fftools/ffmpeg: add more structure to FrameData
It now contains data from multiple sources, so group those items that
always come from the decoder. Also, initialize them to invalid values,
so that frames that did not originate from a decoder can be
distinguished.
2023-07-15 11:02:11 +02:00
Anton Khirnov 2e742a2c3c fftools/ffmpeg_mux: return errors from of_streamcopy() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 464a5e8e76 fftools/ffmpeg: handle error codes from process_input_packet()
None are returned for now, but that will change in future commits.
2023-07-15 11:02:11 +02:00
Anton Khirnov 5fe3914c39 fftools/ffmpeg: return an error instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 6a9d3f46c7 fftools/ffmpeg: drop an obsolete debug log
The value it prints has not been cur_dts from lavf for a very long time,
so it's misleading.
2023-07-11 19:28:18 +02:00
Marton Balint 7357012bb5 fftools/ffmpeg: fix negative timestamps at the beginning of the encoding
Also fix a couple of possible overflows while at it.

Fixes the negative initial timestamps in ticket #10358.

Signed-off-by: Marton Balint <cus@passwd.hu>
2023-07-09 19:50:15 +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 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 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 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 ba1141d8a9 fftools/ffmpeg_enc: move nb_frames{dup,drop} globals into OutputStream 2023-06-05 16:15:04 +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 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 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 d9bcbf9200 fftools/ffmpeg: drop outdated comments 2023-05-28 10:47:59 +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 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 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 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