Add option --max-fps
Add an option to limit the capture frame rate. It only works for devices with Android >= 10. Fixes <https://github.com/Genymobile/scrcpy/issues/488>
This commit is contained in:
@@ -50,6 +50,10 @@ static void usage(const char *arg0) {
|
||||
" -h, --help\n"
|
||||
" Print this help.\n"
|
||||
"\n"
|
||||
" --max-fps value\n"
|
||||
" Limit the frame rate of screen capture (only supported on\n"
|
||||
" devices with Android >= 10).\n"
|
||||
"\n"
|
||||
" -m, --max-size value\n"
|
||||
" Limit both the width and height of the video to value. The\n"
|
||||
" other dimension is computed so that the device aspect-ratio\n"
|
||||
@@ -269,6 +273,28 @@ parse_max_size(char *optarg, uint16_t *max_size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_max_fps(const char *optarg, uint16_t *max_fps) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Max FPS parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid max FPS: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
// in practice, it should not be higher than 60
|
||||
LOGE("Max FPS value is invalid: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*max_fps = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_position(char *optarg, int16_t *position) {
|
||||
char *endptr;
|
||||
@@ -374,6 +400,7 @@ guess_record_format(const char *filename) {
|
||||
#define OPT_WINDOW_WIDTH 1009
|
||||
#define OPT_WINDOW_HEIGHT 1010
|
||||
#define OPT_WINDOW_BORDERLESS 1011
|
||||
#define OPT_MAX_FPS 1012
|
||||
|
||||
static bool
|
||||
parse_args(struct args *args, int argc, char *argv[]) {
|
||||
@@ -383,6 +410,7 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||
{"crop", required_argument, NULL, OPT_CROP},
|
||||
{"fullscreen", no_argument, NULL, 'f'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"max-fps", required_argument, NULL, OPT_MAX_FPS},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"no-control", no_argument, NULL, 'n'},
|
||||
{"no-display", no_argument, NULL, 'N'},
|
||||
@@ -438,6 +466,11 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||
case 'h':
|
||||
args->help = true;
|
||||
break;
|
||||
case OPT_MAX_FPS:
|
||||
if (!parse_max_fps(optarg, &opts->max_fps)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
if (!parse_max_size(optarg, &opts->max_size)) {
|
||||
return false;
|
||||
|
||||
@@ -280,6 +280,7 @@ scrcpy(const struct scrcpy_options *options) {
|
||||
.local_port = options->port,
|
||||
.max_size = options->max_size,
|
||||
.bit_rate = options->bit_rate,
|
||||
.max_fps = options->max_fps,
|
||||
.control = options->control,
|
||||
};
|
||||
if (!server_start(&server, options->serial, ¶ms)) {
|
||||
|
||||
@@ -18,6 +18,7 @@ struct scrcpy_options {
|
||||
uint16_t port;
|
||||
uint16_t max_size;
|
||||
uint32_t bit_rate;
|
||||
uint16_t max_fps;
|
||||
int16_t window_x;
|
||||
int16_t window_y;
|
||||
uint16_t window_width;
|
||||
@@ -43,6 +44,7 @@ struct scrcpy_options {
|
||||
.port = DEFAULT_LOCAL_PORT, \
|
||||
.max_size = DEFAULT_LOCAL_PORT, \
|
||||
.bit_rate = DEFAULT_BIT_RATE, \
|
||||
.max_fps = 0, \
|
||||
.window_x = -1, \
|
||||
.window_y = -1, \
|
||||
.window_width = 0, \
|
||||
|
||||
@@ -118,8 +118,10 @@ static process_t
|
||||
execute_server(struct server *server, const struct server_params *params) {
|
||||
char max_size_string[6];
|
||||
char bit_rate_string[11];
|
||||
char max_fps_string[6];
|
||||
sprintf(max_size_string, "%"PRIu16, params->max_size);
|
||||
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
||||
sprintf(max_fps_string, "%"PRIu16, params->max_fps);
|
||||
const char *const cmd[] = {
|
||||
"shell",
|
||||
"CLASSPATH=/data/local/tmp/" SERVER_FILENAME,
|
||||
@@ -134,6 +136,7 @@ execute_server(struct server *server, const struct server_params *params) {
|
||||
SCRCPY_VERSION,
|
||||
max_size_string,
|
||||
bit_rate_string,
|
||||
max_fps_string,
|
||||
server->tunnel_forward ? "true" : "false",
|
||||
params->crop ? params->crop : "-",
|
||||
"true", // always send frame meta (packet boundaries + timestamp)
|
||||
|
||||
@@ -35,6 +35,7 @@ struct server_params {
|
||||
uint16_t local_port;
|
||||
uint16_t max_size;
|
||||
uint32_t bit_rate;
|
||||
uint16_t max_fps;
|
||||
bool control;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user