Commit Graph

87 Commits

Author SHA1 Message Date
Anton Khirnov
ff55d1cc20 fftools/ffmpeg_dec: improve detection of lavf-guessed durations
Will be useful in following commit.
2024-07-09 11:14:08 +02:00
Andreas Rheinhardt
790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
Anton Khirnov
b1aaa1f585 fftools/ffmpeg_dec: apply cropping manually
lavfi does not require aligned buffers, so we can safely apply top/left
cropping by any amount, without passing any special flags to lavc.
Longer term, an even better solution would probably be auto-inserting
the crop filter (or its hwaccel versions) as needed.

Multiple FATE tests no longer need -flags unaligned.
2024-03-28 08:40:01 +01:00
Anton Khirnov
0edbd00ccf fftools/ffmpeg_{demux,dec}: pass -bitexact through DecoderFlags
Avoids abusing AV_DICT_MULTIKEY and relying on undocumented AVDictionary
ordering behaviour.
2024-03-28 08:40:01 +01:00
Anton Khirnov
372c78dd42 fftools/ffmpeg_dec: apply decoder options manually
Do not pass an options dictionary to avcodec_open2().

This should be equivalent to current behaviour, but will allow
overriding caller-supplied options in a cleaner and more robust manner.

We can now set the COPY_OPAQUE flag directly rather going through
dec_opts.
2024-03-28 08:40:01 +01:00
Mark Thompson
7f4b8d2f5e ffmpeg: set extra_hw_frames to account for frames held in queues
Since e0da916b8f the ffmpeg utility has
held multiple frames output by the decoder in internal queues without
telling the decoder that it is going to do so.  When the decoder has a
fixed-size pool of frames (common in some hardware APIs where the output
frames must be stored as an array texture) this could lead to the pool
being exhausted and the decoder getting stuck.  Fix this by telling the
decoder to allocate additional frames according to the queue size.
2024-03-19 22:56:56 +00:00
Anton Khirnov
a9193f7b7d fftools/ffmpeg: add loopback decoding
This allows to send an encoder's output back to decoding and feed the
result into a complex filtergraph.
2024-03-13 08:01:27 +01:00
Anton Khirnov
2ee9362419 fftools/ffmpeg: remove unncessary casts for *_thread() return values
These functions used to be passed directly to pthread_create(), which
required them to return void*. This is no longer the case, so they can
return a plain int.
2024-03-13 08:01:15 +01:00
Anton Khirnov
f5d03b972c fftools/ffmpeg: simplify propagating fallback parameters from decoders to filters
Current callstack looks like this:
* ifilter_bind_ist() (filter) calls ist_filter_add() (demuxer);
* ist_filter_add() opens the decoder, and then calls
  dec_add_filter() (decoder);
* dec_add_filter() calls ifilter_parameters_from_dec() (i.e. back into
  the filtering code) in order to give post-avcodec_open2() parameters
  to the filter.

This is unnecessarily complicated. Pass the parameters as follows
instead:
* dec_init() (which opens the decoder) returns post-avcodec_open2()
  parameters to its caller (i.e. the demuxer) in a parameter-only
  AVFrame
* the demuxer passes these parameters to the filter in
  InputFilterOptions, together with other filter options
2024-03-13 08:01:15 +01:00
Anton Khirnov
c4de5778bc fftools/ffmpeg_dec: factor opening the decoder out of dec_open()
Rename dec_open to dec_init(), as it is more descriptive of its new
purpose.

Will be useful in following commits, which will add a new path for
opening decoders.
2024-03-13 08:01:15 +01:00
Anton Khirnov
48c39a9c71 fftools/ffmpeg_dec: move scheduler registration from dec_open() to dec_alloc()
Will be useful in following commits where we will want to create a
decoder before having enough information to open it.
2024-03-13 08:01:15 +01:00
Anton Khirnov
a2fc86378a fftools/ffmpeg: declare loop indices inside loops 2024-02-24 11:51:41 +01:00
Anton Khirnov
a3f69cdec7 fftools/ffmpeg: cosmetics, vertically align structs 2024-02-21 10:33:20 +01:00
Anton Khirnov
6b6815b1c8 fftools/ffmpeg: move subtitle helpers to ffmpeg_dec, their only user 2024-02-21 10:31:27 +01:00
Anton Khirnov
0d00e2e2f7 fftools/ffmpeg_dec: eliminate all remaining InputStream uses
Previously, the demuxer would register decoder with the scheduler, using
InputStream as opaque, and pass the scheduling index to the decoder.

Now the registration is done by the decoder itself, using DecoderPriv as
opaque, and the scheduling index is returned to demuxer from dec_open().

decoder_thread() then no longer needs to be accessed from outside of
ffmpeg_dec and can be made static.
2024-01-30 09:52:00 +01:00
Anton Khirnov
fe3be6f78f fftools/ffmpeg_dec: stop passing InputStream to dec_open() 2024-01-30 09:52:00 +01:00
Anton Khirnov
a0ca99ccb7 fftools/ffmpeg_dec: remove unnecessary InputStream arguments 2024-01-30 09:52:00 +01:00
Anton Khirnov
1b2c539a0f fftools/ffmpeg_dec: pass AVCodecParameters through DecoderOpts
Do not retrieve it from InputStream directly.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
b3d1916ba0 fftools/ffmpeg_dec: pass AVCodec through DecoderOpts
Do not retrieve it from InputStream directly.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
d5f9ef766b fftools/ffmpeg_dec: eliminate InputStream use in hw_device_setup_for_decode()
The same information can also be obtained from the decoder itself.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
097f9ddbe9 fftools/ffmpeg_dec: pass decoder name through DecoderOpts
Do not build it from InputStream values.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
9ba4bc87e6 fftools/ffmpeg_dec: pass top_field_first through DecoderOpts
Do not read it from InputStream directly.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
9702817662 fftools/ffmpeg_dec: pass input timebase through DecoderOpts
Do not read it from AVStream directly.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
b27de18e4f fftools/ffmpeg_dec: move setting compute_edt to demuxer
It is done based on demuxer information, so that is the more appropriate
place for this code.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
052c83e356 fftools/ffmpeg_dec: pass forced/estimated framerate though DecoderOpts
Stop reading them from InputStream.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
e0a6cb07b2 fftools/ffmpeg_dec: move flags to DecoderOpts
Will be useful in the following commit.
2024-01-30 09:52:00 +01:00
Anton Khirnov
4bdffec814 fftools/ffmpeg_dec: pass hwaccel options to the decoder in a separate struct
Stop reading them from InputStream.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
a3a9c4ae66 fftools/ffmpeg: move hwaccel_retrieve_data() from ffmpeg_hw to ffmpeg_dec
This function is decoding-only and has no interaction with the rest of
ffmpeg_hw. It thus belongs more properly in ffmpeg_dec.
2024-01-30 09:52:00 +01:00
Anton Khirnov
ebb8a58c8f fftools/ffmpeg_dec: replace InputFile.format_nots with a decoder flag
Reduces the need to access InputFile from decoding.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
a938f47916 fftools/ffmpeg: refactor disabling decoder threading for attached pictures
* as this decision is based on demuxing information, move it from the
  decoder to the demuxer
* as the issue being addressed is latency added by frame threading, we
  only need to disable frame threading, not all threading
2024-01-30 09:52:00 +01:00
Anton Khirnov
474ca6c71e fftools/ffmpeg_dec: stop accesing InputStream.fix_sub_duration
Pass this information to dec_open() instead.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
924a6f3cc7 fftools/ffmpeg_dec: override video SAR with AVCodecParameters value
Rather than access the AVStream one.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
b2a0a2e6f5 fftools/ffmpeg: move decoder existence check to a more appropriate place 2024-01-30 09:52:00 +01:00
Anton Khirnov
217b8757db fftools/ffmpeg_dec: drop a useless log message 2024-01-30 09:52:00 +01:00
Anton Khirnov
27de2aacd1 fftools/ffmpeg_dec: drop useless and racy code
Setting demuxer's video_delay from the decoder cannot accomplish
anything meaningful and is racy, as they run in different threads.
2024-01-30 09:52:00 +01:00
Anton Khirnov
9be3f80527 fftools/ffmpeg_dec: move decoding counters from InputStream to Decoder
This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
5b0e4f945e fftools/ffmpeg_dec: pass decoder options as an argument to dec_open()
Rather than access the dictionary in InputStream.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
7ecd45587f fftools/ffmpeg_dec: add an AVClass to Decoder
Log decoder messages to the decoder rather than InputStream.

This is a step towards decoupling Decoder and InputStream.
2024-01-30 09:52:00 +01:00
Anton Khirnov
f2a2094c47 fftools/ffmpeg: make decoding AVCodecContext private to the decoder 2024-01-30 09:52:00 +01:00
Anton Khirnov
b43d4a0692 fftools/ffmpeg_dec: export subtitle_header in Decoder
This way the encoder does not need to access the decoder AVCodecContext,
which will allow to make it private in future commits.
2024-01-30 09:52:00 +01:00
Anton Khirnov
3b84140a1b fftools/ffmpeg_dec: split Decoder into a private and public part
Similar to what is currently done for other components, e.g. (de)muxers.
There is nothing in the public part currently, but that will change in
future commits.
2024-01-30 09:51:57 +01:00
Anton Khirnov
0fcea80b2a fftools/ffmpeg: replace InputStream.file_index by a pointer
Reduces the need to use the input_files global array.
2023-12-14 20:16:53 +01:00
Anton Khirnov
9d7000b1be fftools/ffmpeg: attach wallclock timing information to packets and frames
Will become useful in following commits.
2023-12-14 08:11:05 +01:00
Anton Khirnov
d119ae2fd8 fftools/ffmpeg: convert to a threaded architecture
Change the main loop and every component (demuxers, decoders, filters,
encoders, muxers) to use the previously added transcode scheduler. Every
instance of every such component was already running in a separate
thread, but now they can actually run in parallel.

Changes the results of ffmpeg-fix_sub_duration_heartbeat - tested by
JEEB to be more correct and deterministic.
2023-12-12 08:24:18 +01:00
Anton Khirnov
9b8cc36ce0 fftools/ffmpeg: add thread-aware transcode scheduling infrastructure
See the comment block at the top of fftools/ffmpeg_sched.h for more
details on what this scheduler is for.

This commit adds the scheduling code itself, along with minimal
integration with the rest of the program:
* allocating and freeing the scheduler
* passing it throughout the call stack in order to register the
  individual components (demuxers/decoders/filtergraphs/encoders/muxers)
  with the scheduler

The scheduler is not actually used as of this commit, so it should not
result in any change in behavior. That will change in future commits.
2023-12-12 08:24:18 +01:00
Anton Khirnov
d35c05cb9e fftools/ffmpeg_filter: move filtering to a separate thread
As previously for decoding, this is merely "scaffolding" for moving to a
fully threaded architecture and does not yet make filtering truly
parallel - the main thread will currently wait for the filtering thread
to finish its work before continuing. That will change in future commits
after encoders are also moved to threads and a thread-aware scheduler is
added.
2023-12-12 08:24:18 +01:00
Anton Khirnov
889a022cce fftools/ffmpeg: rework keeping track of file duration for -stream_loop
Current code tracks min/max pts for each stream separately; then when
the file ends it combines them with last frame's duration to compute the
total duration of each stream; finally it selects the longest of those
durations as the file duration.

This is incorrect - the total file duration is the largest timestamp
difference between any frames, regardless of the stream.

Also change the way the last frame information is reported from decoders
to the muxer - previously it would be just the last frame's duration,
now the end timestamp is sent, which is simpler.

Changes the result of the fate-ffmpeg-streamloop-transcode-av test,
where the timestamps are shifted slightly forward. Note that the
matroska demuxer does not return the first audio packet after seeking
(due to buggy interaction betwen the generic code and the demuxer), so
there is a gap in audio.
2023-11-14 18:18:26 +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
Anton Khirnov
303f10d4dd fftools/ffmpeg_dec: disregard demuxer timestamps for NOTIMESTAMPS formats
In this case any timestamps are guessed by compute_pkt_fields() in
libavformat. Since we are decoding the stream, we have more accurate
information from the decoder and do not need any guesses.

Eliminates spurious PTS gaps in a number of FATE tests.

Also avoids dropping the majority of frames in fate-dirac*
2023-10-03 16:57:02 +02:00
Anton Khirnov
5d58a35f98 fftools/ffmpeg: deprecate the -top option
It is badly named (should have been -top_field_first, or at least -tff),
underdocumented and underspecified, and (most importantly) entirely
redundant with the setfield filter.
2023-09-18 17:16:06 +02:00