mirror of
https://github.com/Genymobile/scrcpy
synced 2025-08-30 22:05:12 +00:00
Accept float values for --max-fps
Android accepts a float value, there is no reason to limit the option to be an integer. In particular, it allows to capture at a rate lower than 1 fps. For example, to capture 1 frame every 5 seconds: scrcpy --video-source=camera --max-fps=0.2 It was already possible to pass a float manually: scrcpy --video-source=camera \ --video-codec-options=max-fps-to-encoder:float=0.2 But accepting a float directly for --max-fps is more convenient. Refs <https://developer.android.com/reference/android/media/MediaFormat#KEY_MAX_FPS_TO_ENCODER>
This commit is contained in:
@@ -1447,6 +1447,26 @@ parse_integers_arg(const char *s, const char sep, size_t max_items, long *out,
|
||||
return count;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_float_arg(const char *s, float *out, float min, float max,
|
||||
const char *name) {
|
||||
float value;
|
||||
bool ok = sc_str_parse_float(s, &value);
|
||||
if (!ok) {
|
||||
LOGE("Could not parse %s: %s", name, s);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value < min || value > max) {
|
||||
LOGE("Could not parse %s: value (%f) out-of-range (%f; %f)",
|
||||
name, value, min, max);
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_bit_rate(const char *s, uint32_t *bit_rate) {
|
||||
long value;
|
||||
@@ -1474,14 +1494,14 @@ parse_max_size(const char *s, uint16_t *max_size) {
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_max_fps(const char *s, uint16_t *max_fps) {
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "max fps");
|
||||
parse_max_fps(const char *s, float *max_fps) {
|
||||
float value;
|
||||
bool ok = parse_float_arg(s, &value, 0, (float) (1 << 16), "max fps");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*max_fps = (uint16_t) value;
|
||||
*max_fps = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user