Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add min_fps_target setting #1043

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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>

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
Loading