diff --git a/docs/source/about/advanced_usage.rst b/docs/source/about/advanced_usage.rst index aa6c3814bb6..95025b91358 100644 --- a/docs/source/about/advanced_usage.rst +++ b/docs/source/about/advanced_usage.rst @@ -697,6 +697,26 @@ keybindings fps = [10, 30, 60, 90, 120] +min_fps_factor `__ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +**Description** + Sunshine will use this factor to calculate the minimum time between frames. Increasing this value may help when + streaming mostly static content. + + .. Warning:: Higher values will consume more bandwidth. + +**Default** + ``1`` + +**Range** + ``1-3`` + +**Example** + .. code-block:: text + + min_fps_factor = 1 + `Network `__ ----------------------------------------------------- diff --git a/src/config.cpp b/src/config.cpp index 8ee20d52e06..a466eb12a62 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -331,6 +331,7 @@ namespace config { 0, // hevc_mode 0, // av1_mode + 1, // min_fps_factor 2, // min_threads { "superfast"s, // preset @@ -1030,6 +1031,7 @@ namespace config { string_f(vars, "encoder", video.encoder); string_f(vars, "adapter_name", video.adapter_name); string_f(vars, "output_name", video.output_name); + int_between_f(vars, "min_fps_factor", video.min_fps_factor, { 1, 3 }); path_f(vars, "pkey", nvhttp.pkey); path_f(vars, "cert", nvhttp.cert); diff --git a/src/config.h b/src/config.h index 80ff698aaee..308c774eadb 100644 --- a/src/config.h +++ b/src/config.h @@ -21,6 +21,7 @@ namespace config { int hevc_mode; int av1_mode; + int min_fps_factor; // Minimum fps target, determines minimum frame time int min_threads; // Minimum number of threads/slices for CPU encoding struct { std::string sw_preset; diff --git a/src/video.cpp b/src/video.cpp index 394e7d46fdf..95783dc725b 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -1771,6 +1771,10 @@ namespace video { return; } + // set minimum frame time, avoiding violation of client-requested target framerate + auto minimum_frame_time = std::chrono::milliseconds(1000 / std::min(config.framerate, (config::video.min_fps_factor * 10))); + BOOST_LOG(debug) << "Minimum frame time set to "sv << minimum_frame_time.count() << "ms, based on min fps factor of "sv << config::video.min_fps_factor << "."sv; + auto shutdown_event = mail->event(mail::shutdown); auto packets = mail::man->queue(mail::video_packets); auto idr_events = mail->event(mail::idr); @@ -1811,9 +1815,9 @@ namespace video { std::optional frame_timestamp; - // Encode at a minimum of 10 FPS to avoid image quality issues with static content + // Encode at a minimum FPS to avoid image quality issues with static content if (!requested_idr_frame || images->peek()) { - if (auto img = images->pop(100ms)) { + if (auto img = images->pop(minimum_frame_time)) { frame_timestamp = img->frame_timestamp; if (session->convert(*img)) { BOOST_LOG(error) << "Could not convert image"sv; diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index 7df3880ceb4..8c2bce2b32f 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -176,6 +176,7 @@

{{ $t('config.configuration') }}

"output_name": "", "resolutions": "[352x240,480x360,858x480,1280x720,1920x1080,2560x1080,2560x1440,3440x1440,1920x1200,3840x2160,3840x1600]", "fps": "[10,30,60,90,120]", + "min_fps_factor": 1, }, }, { diff --git a/src_assets/common/assets/web/configs/tabs/AudioVideo.vue b/src_assets/common/assets/web/configs/tabs/AudioVideo.vue index 58695ba1d2a..1a5b63c07ec 100644 --- a/src_assets/common/assets/web/configs/tabs/AudioVideo.vue +++ b/src_assets/common/assets/web/configs/tabs/AudioVideo.vue @@ -13,6 +13,7 @@ const props = defineProps([ 'config', 'resolutions', 'fps', + 'min_fps_factor', ]) const config = ref(props.config) @@ -83,6 +84,7 @@ const config = ref(props.config) :config="config" :resolutions="resolutions" :fps="fps" + :min_fps_factor="min_fps_factor" /> diff --git a/src_assets/common/assets/web/configs/tabs/audiovideo/DisplayModesSettings.vue b/src_assets/common/assets/web/configs/tabs/audiovideo/DisplayModesSettings.vue index 7fb5ca3b0f9..2f2509dcfe5 100644 --- a/src_assets/common/assets/web/configs/tabs/audiovideo/DisplayModesSettings.vue +++ b/src_assets/common/assets/web/configs/tabs/audiovideo/DisplayModesSettings.vue @@ -8,6 +8,7 @@ const props = defineProps([ 'config', 'resolutions', 'fps', + 'min_fps_factor', ]) const config = ref(props.config) @@ -63,6 +64,14 @@ const fpsIn = ref("")
{{ $t('config.res_fps_desc') }}
+ + +
+ + +
{{ $t('config.min_fps_factor_desc') }}
+
+ diff --git a/src_assets/common/assets/web/public/assets/locale/en.json b/src_assets/common/assets/web/public/assets/locale/en.json index 135f3c83f01..cc5a863a5e9 100644 --- a/src_assets/common/assets/web/public/assets/locale/en.json +++ b/src_assets/common/assets/web/public/assets/locale/en.json @@ -211,6 +211,8 @@ "log_level_desc": "The minimum log level printed to standard out", "log_path": "Logfile Path", "log_path_desc": "The file where the current logs of Sunshine are stored.", + "min_fps_factor": "Minimum FPS Factor", + "min_fps_factor_desc": "Sunshine will use this factor to calculate the minimum time between frames. Increasing this value slightly may help when streaming mostly static content. Higher values will consume more bandwidth.", "min_threads": "Minimum CPU Thread Count", "min_threads_desc": "Increasing the value slightly reduces encoding efficiency, but the tradeoff is usually worth it to gain the use of more CPU cores for encoding. The ideal value is the lowest value that can reliably encode at your desired streaming settings on your hardware.", "misc": "Miscellaneous options",