[FFmpeg-devel] [RFC/PATCH] ffmpeg CLI multithreading
Anton Khirnov
anton at khirnov.net
Tue Sep 19 22:10:27 EEST 2023
Hi,
as some of you might know, I have been working on multithreading for the
ffmpeg CLI (as opposed to the libraries) for quite a while now. That
work is now finally entering the vicinity of being usable, so I've
decided to air it on the ML for comments on the big picture.
Do note that many things still do not work at all, notably
* subtitles
* bitstream filters
* streamloop
* filtergraphs with no inputs
Many others are probably broken to a larger or smaller extent.
I can, however, get some interesting results - e.g. significant
wallclock speedup in cases where singlethreaded codecs/filters can now
be run in parallel. I am also seeing 10-20% overall clock cycle increase
in my tests - for now that is a known bug that will hopefully be
addressed later.
One of the main themes of this work is separating various bits of
functionality in the code - that typically grew organically over years
(often in rather random places) - into clearly defined objects with
clearly defined responsibilities. At the core of the new world order is
the new scheduler object, living in ffmpeg_sched.[ch]. It handles all
interactions between the various ffmpeg components, inter-thread
synchronization, etc., so the individual components themselves do not
need to know anything about threading/synchronization/the rest of the
transcoding pipeline.
The patches are roughly grouped as follows:
* 01-13 Preparatory cleanup.
The big thing here is moving fps conversion from video encoding to
filtering (see commit message for 20/27 for details)
* 14-20 "Fake" threading for encoders/filters.
This moves the last two unthreaded components - encoders and filters -
into threads. As previously for decoders, this is merely preparatory,
since the main thread waits while the encoder/filter thread does its
work. The filter patch is unfortunately especially large, because
filtering has multiple entrypoints and they all need to be wrapped and
unwrapped for communication with the filtering thread.
Some features that conflict with threading are also disabled in
these patches. That will hopefully change later (though currently
I don't see how subtitle heartbeat can work in its current form).
* 21 The scheduler itself, merely added without being used
* 22-27 Actually using the scheduler.
This is split into multiple patches for clarity, but will be squashed
in the final form.
You can fetch the code from the 'ffmpeg_threading' branch in
git://git.khirnov.net/libav. I will also present a short talk about this
work at VDD. Comments, questions, suggestions, etc. are very much
welcome, both here and there.
Cheers,
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list