mirror of
https://github.com/Genymobile/scrcpy
synced 2025-08-31 22:35:37 +00:00
Support camera size selection using -m/--camera-ar
In addition to --camera-size to specify an explicit size, make it possible to select the camera size automatically, respecting the maximum size (already used for display mirroring) and an aspect ratio. For example, "scrcpy --video-source=camera" followed by: - (no additional arguments) : mirrors at the maximum size, any a-r - -m1920 : only consider valid sizes having both dimensions not above 1920 - --camera-ar=4:3 : only consider valid sizes having an aspect ratio of 4:3 (+/- 10%) - -m2048 --camera-ar=1.6 : only consider valid sizes having both dimensions not above 2048 and an aspect ratio of 1.6 (+/- 10%) PR #4213 <https://github.com/Genymobile/scrcpy/pull/4213> Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
This commit is contained in:
@@ -87,6 +87,7 @@ enum {
|
||||
OPT_CAMERA_ID,
|
||||
OPT_CAMERA_SIZE,
|
||||
OPT_CAMERA_FACING,
|
||||
OPT_CAMERA_AR,
|
||||
};
|
||||
|
||||
struct sc_option {
|
||||
@@ -203,6 +204,15 @@ static const struct sc_option options[] = {
|
||||
.longopt = "bit-rate",
|
||||
.argdesc = "value",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_CAMERA_AR,
|
||||
.longopt = "camera-ar",
|
||||
.argdesc = "ar",
|
||||
.text = "Select the camera size by its aspect ratio (+/- 10%).\n"
|
||||
"Possible values are \"sensor\" (use the camera sensor aspect "
|
||||
"ratio), \"<num>:<den>\" (e.g. \"4:3\") or \"<value>\" (e.g. "
|
||||
"\"1.6\")."
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_CAMERA_ID,
|
||||
.longopt = "camera-id",
|
||||
@@ -2130,6 +2140,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_CAMERA_AR:
|
||||
opts->camera_ar = optarg;
|
||||
break;
|
||||
case OPT_CAMERA_ID:
|
||||
opts->camera_id = optarg;
|
||||
break;
|
||||
@@ -2245,9 +2258,16 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!opts->camera_size) {
|
||||
LOGE("Camera size must be specified by --camera-size");
|
||||
return false;
|
||||
if (opts->camera_size) {
|
||||
if (opts->max_size) {
|
||||
LOGE("Could not specify both --camera-size and -m/--max-size");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->camera_ar) {
|
||||
LOGE("Could not specify both --camera-size and --camera-ar");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (opts->control) {
|
||||
@@ -2255,6 +2275,7 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
opts->control = false;
|
||||
}
|
||||
} else if (opts->camera_id
|
||||
|| opts->camera_ar
|
||||
|| opts->camera_facing != SC_CAMERA_FACING_ANY
|
||||
|| opts->camera_size) {
|
||||
LOGE("Camera options are only available with --video-source=camera");
|
||||
|
Reference in New Issue
Block a user