[FFmpeg-devel] [RFC] ffmpeg: default to single thread when hwaccel is active
Dennis Mungai
dmngaie at gmail.com
Wed Sep 29 20:17:39 EEST 2021
On Wed, 29 Sept 2021 at 20:02, Timo Rothenpieler <timo at rothenpieler.org>
wrote:
> ---
> fftools/ffmpeg.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> Not sure if there is any downside to this.
> Threading for hwaccel does not make a whole lot of sense, and at least
> in case of nvdec wastes a lot of VRAM for no performance gain, and
> specially on high core count systems by default can even exhaust the
> maximum frame pool size.
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 98c2421938..d007d55173 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2995,12 +2995,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
> * audio, and video decoders such as cuvid or mediacodec */
> ist->dec_ctx->pkt_timebase = ist->st->time_base;
>
> - if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
> - av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
> - /* Attached pics are sparse, therefore we would not want to delay
> their decoding till EOF. */
> - if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
> - av_dict_set(&ist->decoder_opts, "threads", "1", 0);
> -
> ret = hw_device_setup_for_decode(ist);
> if (ret < 0) {
> snprintf(error, error_len, "Device setup failed for "
> @@ -3009,6 +3003,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
> return ret;
> }
>
> + if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) {
> + if (ist->dec_ctx->hw_device_ctx)
> + av_dict_set(&ist->decoder_opts, "threads", "1", 0);
> + else
> + av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
> + }
> + /* Attached pics are sparse, therefore we would not want to delay
> their decoding till EOF. */
> + if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
> + av_dict_set(&ist->decoder_opts, "threads", "1", 0);
> +
> if ((ret = avcodec_open2(ist->dec_ctx, codec,
> &ist->decoder_opts)) < 0) {
> if (ret == AVERROR_EXPERIMENTAL)
> abort_codec_experimental(codec, 0);
> --
> 2.25.1
>
>
>
A potential downside to this would be on QSV's side, which needs at least
2 threads to prevent dead-locking, see
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/_studio/mfx_lib/scheduler/linux/src/mfx_scheduler_core_ischeduler.cpp#L90-L93
Regards,
Dennis.
More information about the ffmpeg-devel
mailing list