Skip to content

Commit

Permalink
feat: add min_fps_factor setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Jun 18, 2024
1 parent d6dd1ab commit d3a4f39
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
20 changes: 20 additions & 0 deletions docs/source/about/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`__
-----------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ namespace config {
0, // hevc_mode
0, // av1_mode

1, // min_fps_factor
2, // min_threads
{
"superfast"s, // preset
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ <h1 class="my-4">{{ $t('config.configuration') }}</h1>
"output_name": "",
"resolutions": "[352x240,480x360,858x480,1280x720,1920x1080,2560x1080,2560x1440,3440x1440,1920x1200,3840x2160,3840x1600]",
"fps": "[10,30,60,90,120]",
"min_fps_factor": 1,
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions src_assets/common/assets/web/configs/tabs/AudioVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const props = defineProps([
'config',
'resolutions',
'fps',
'min_fps_factor',
])
const config = ref(props.config)
Expand Down Expand Up @@ -83,6 +84,7 @@ const config = ref(props.config)
:config="config"
:resolutions="resolutions"
:fps="fps"
:min_fps_factor="min_fps_factor"
/>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const props = defineProps([
'config',
'resolutions',
'fps',
'min_fps_factor',
])
const config = ref(props.config)
Expand Down Expand Up @@ -63,6 +64,14 @@ const fpsIn = ref("")
</div>

<div class="form-text">{{ $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" 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>

Expand Down
2 changes: 2 additions & 0 deletions src_assets/common/assets/web/public/assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d3a4f39

Please sign in to comment.