Commit Graph

1049 Commits

Author SHA1 Message Date
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
QiTong Li 79f41a0760 fftools/ffplay: fix typo in frame_queue_destory
Not sure if the function naming frame_queue_destory is intended because
"destory" is not really a word. Changing it to "destroy" makes more sense.

Signed-off-by: QiTong Li <liqitong@163.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-07-06 21:24:47 +02:00
James Almer 50f34172e0 fftools/ffplay: remove usage of internal AVInputFormat.read_seek field
It's an internal field, so it should not be touched.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-07-02 19:04:25 -03:00
Anton Khirnov 1617d1a752 fftools/ffmpeg: pass subtitle decoder dimensions to sub2video
Restores behavior from before 20cacfe493.
Eventually this should be handled similarly to audio/video - with a
filtergraph reset or a manual scaler.
2023-06-19 09:48:56 +02:00
Anton Khirnov 88f80977eb fftools/ffmpeg: use AVFrame to pass subtitles from decoders to filters
Allows to use the same buffering code for all media types. Will also be
important for the following commit.
2023-06-19 09:48:56 +02:00
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