feat: add min_fps_target setting (#1043)

This commit is contained in:
ReenigneArcher 2024-06-18 20:09:23 -04:00 committed by GitHub
parent d6dd1ab42b
commit 722e5600c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 3 deletions

View File

@ -697,6 +697,26 @@ keybindings
fps = [10, 30, 60, 90, 120]
min_fps_factor <https://localhost:47990/config/#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 <https://localhost:47990/config/#network>`__
-----------------------------------------------------

View File

@ -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);

View File

@ -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;

View File

@ -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<bool>(mail::shutdown);
auto packets = mail::man->queue<packet_t>(mail::video_packets);
auto idr_events = mail->event<bool>(mail::idr);
@ -1811,9 +1815,9 @@ namespace video {
std::optional<std::chrono::steady_clock::time_point> 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;

View File

@ -176,6 +176,7 @@
"output_name": "",
"resolutions": "[352x240,480x360,858x480,1280x720,1920x1080,2560x1080,2560x1440,3440x1440,1920x1200,3840x2160,3840x1600]",
"fps": "[10,30,60,90,120]",
"min_fps_factor": 1,
},
},
{

View File

@ -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"
/>
</div>

View File

@ -8,6 +8,7 @@ const props = defineProps([
'config',
'resolutions',
'fps',
'min_fps_factor',
])
const config = ref(props.config)
@ -62,7 +63,15 @@ const fpsIn = ref("")
</form>
</div>
<div class="form-text">{{ $t('config.res_fps_desc') }}</div>
<div class="form-text mb-3">{{ $t('config.res_fps_desc') }}</div>
<!--min_fps_factor-->
<div class="mb-3">
<label for="qp" class="form-label">{{ $t('config.min_fps_factor') }}</label>
<input type="number" min="1" max="3" class="form-control" id="min_fps_factor" placeholder="1" v-model="config.min_fps_factor" />
<div class="form-text">{{ $t('config.min_fps_factor_desc') }}</div>
</div>
</div>
</template>

View File

@ -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",