diff --git a/README.md b/README.md index 4b898d26..81371b92 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ preserved. That way, a device in 1920×1080 will be mirrored at 1024×576. The default bit-rate is 8 Mbps. To change the video bitrate (e.g. to 2 Mbps): ```bash -scrcpy --bit-rate=2M +scrcpy --video-bit-rate=2M scrcpy -b 2M # short version ``` @@ -444,7 +444,7 @@ none found, try running `adb disconnect`, and then run those two commands again. It may be useful to decrease the bit-rate and the resolution: ```bash -scrcpy --bit-rate=2M --max-size=800 +scrcpy --video-bit-rate=2M --max-size=800 scrcpy -b2M -m800 # short version ``` diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy index d92cf009..1fe79765 100644 --- a/app/data/bash-completion/scrcpy +++ b/app/data/bash-completion/scrcpy @@ -2,7 +2,7 @@ _scrcpy() { local cur prev words cword local opts=" --always-on-top - -b --bit-rate= + -b --video-bit-rate= --codec-options= --crop= -d --select-usb @@ -104,7 +104,7 @@ _scrcpy() { COMPREPLY=($(compgen -W "$("${ADB:-adb}" devices | awk '$2 == "device" {print $1}')" -- ${cur})) return ;; - -b|--bit-rate \ + -b|--video-bit-rate \ |--codec-options \ |--crop \ |--display \ diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy index b9c94e1e..ac3ec023 100644 --- a/app/data/zsh-completion/_scrcpy +++ b/app/data/zsh-completion/_scrcpy @@ -9,7 +9,7 @@ local arguments arguments=( '--always-on-top[Make scrcpy window always on top \(above other windows\)]' - {-b,--bit-rate=}'[Encode the video at the given bit-rate]' + {-b,--video-bit-rate=}'[Encode the video at the given bit-rate]' '--codec-options=[Set a list of comma-separated key\:type=value options for the device encoder]' '--crop=[\[width\:height\:x\:y\] Crop the device screen on the server]' {-d,--select-usb}'[Use USB device]' diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 32bb8464..41ce28a4 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -20,7 +20,7 @@ provides display and control of Android devices connected on USB (or over TCP/IP Make scrcpy window always on top (above other windows). .TP -.BI "\-b, \-\-bit\-rate " value +.BI "\-b, \-\-video\-bit\-rate " value Encode the video at the given bit\-rate, expressed in bits/s. Unit suffixes are supported: '\fBK\fR' (x1000) and '\fBM\fR' (x1000000). Default is 8M (8000000). diff --git a/app/src/cli.c b/app/src/cli.c index 9163ba60..57e85aa4 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -19,6 +19,7 @@ enum { OPT_RENDER_EXPIRED_FRAMES = 1000, + OPT_BIT_RATE, OPT_WINDOW_TITLE, OPT_PUSH_TARGET, OPT_ALWAYS_ON_TOP, @@ -104,12 +105,18 @@ static const struct sc_option options[] = { }, { .shortopt = 'b', - .longopt = "bit-rate", + .longopt = "video-bit-rate", .argdesc = "value", .text = "Encode the video at the given bit-rate, expressed in bits/s. " "Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n" "Default is 8M (8000000).", }, + { + // deprecated + .longopt_id = OPT_BIT_RATE, + .longopt = "bit-rate", + .argdesc = "value", + }, { // Not really deprecated (--codec has never been released), but without // declaring an explicit --codec option, getopt_long() partial matching @@ -1432,8 +1439,11 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], int c; while ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) { switch (c) { + case OPT_BIT_RATE: + LOGW("--bit-rate is deprecated, use --video-bit-rate instead."); + // fall through case 'b': - if (!parse_bit_rate(optarg, &opts->bit_rate)) { + if (!parse_bit_rate(optarg, &opts->video_bit_rate)) { return false; } break; diff --git a/app/src/options.c b/app/src/options.c index 0368ffcc..a087f507 100644 --- a/app/src/options.c +++ b/app/src/options.c @@ -28,7 +28,7 @@ const struct scrcpy_options scrcpy_options_default = { .count = 2, }, .max_size = 0, - .bit_rate = 0, + .video_bit_rate = 0, .max_fps = 0, .lock_video_orientation = SC_LOCK_VIDEO_ORIENTATION_UNLOCKED, .rotation = 0, diff --git a/app/src/options.h b/app/src/options.h index f6ba324b..d22078e4 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -108,7 +108,7 @@ struct scrcpy_options { uint16_t tunnel_port; struct sc_shortcut_mods shortcut_mods; uint16_t max_size; - uint32_t bit_rate; + uint32_t video_bit_rate; uint16_t max_fps; enum sc_lock_video_orientation lock_video_orientation; uint8_t rotation; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 35b999a8..b09de541 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -320,7 +320,7 @@ scrcpy(struct scrcpy_options *options) { .tunnel_host = options->tunnel_host, .tunnel_port = options->tunnel_port, .max_size = options->max_size, - .bit_rate = options->bit_rate, + .video_bit_rate = options->video_bit_rate, .max_fps = options->max_fps, .lock_video_orientation = options->lock_video_orientation, .control = options->control, diff --git a/app/src/server.c b/app/src/server.c index 20433ea0..7c8fba8d 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -216,8 +216,8 @@ execute_server(struct sc_server *server, ADD_PARAM("scid=%08x", params->scid); ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level)); - if (params->bit_rate) { - ADD_PARAM("bit_rate=%" PRIu32, params->bit_rate); + if (params->video_bit_rate) { + ADD_PARAM("video_bit_rate=%" PRIu32, params->video_bit_rate); } if (!params->audio) { ADD_PARAM("audio=false"); diff --git a/app/src/server.h b/app/src/server.h index 8914349f..d3019288 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -33,7 +33,7 @@ struct sc_server_params { uint32_t tunnel_host; uint16_t tunnel_port; uint16_t max_size; - uint32_t bit_rate; + uint32_t video_bit_rate; uint16_t max_fps; int8_t lock_video_orientation; bool control; diff --git a/app/tests/test_cli.c b/app/tests/test_cli.c index 5ea54b7f..3e9a248a 100644 --- a/app/tests/test_cli.c +++ b/app/tests/test_cli.c @@ -46,7 +46,7 @@ static void test_options(void) { char *argv[] = { "scrcpy", "--always-on-top", - "--bit-rate", "5M", + "--video-bit-rate", "5M", "--crop", "100:200:300:400", "--fullscreen", "--max-fps", "30", @@ -75,7 +75,7 @@ static void test_options(void) { const struct scrcpy_options *opts = &args.opts; assert(opts->always_on_top); - assert(opts->bit_rate == 5000000); + assert(opts->video_bit_rate == 5000000); assert(!strcmp(opts->crop, "100:200:300:400")); assert(opts->fullscreen); assert(opts->max_fps == 30); diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index 73a303d8..53257cf3 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -11,7 +11,7 @@ public class Options { private boolean audio = true; private int maxSize; private VideoCodec videoCodec = VideoCodec.H264; - private int bitRate = 8000000; + private int videoBitRate = 8000000; private int maxFps; private int lockVideoOrientation = -1; private boolean tunnelForward; @@ -74,12 +74,12 @@ public class Options { this.videoCodec = videoCodec; } - public int getBitRate() { - return bitRate; + public int getVideoBitRate() { + return videoBitRate; } - public void setBitRate(int bitRate) { - this.bitRate = bitRate; + public void setVideoBitRate(int videoBitRate) { + this.videoBitRate = videoBitRate; } public int getMaxFps() { diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java index 30e988f0..d646995b 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -35,18 +35,18 @@ public class ScreenEncoder implements Device.RotationListener { private final Streamer streamer; private final String encoderName; private final List codecOptions; - private final int bitRate; + private final int videoBitRate; private final int maxFps; private final boolean downsizeOnError; private boolean firstFrameSent; private int consecutiveErrors; - public ScreenEncoder(Device device, Streamer streamer, int bitRate, int maxFps, List codecOptions, String encoderName, + public ScreenEncoder(Device device, Streamer streamer, int videoBitRate, int maxFps, List codecOptions, String encoderName, boolean downsizeOnError) { this.device = device; this.streamer = streamer; - this.bitRate = bitRate; + this.videoBitRate = videoBitRate; this.maxFps = maxFps; this.codecOptions = codecOptions; this.encoderName = encoderName; @@ -65,7 +65,7 @@ public class ScreenEncoder implements Device.RotationListener { public void streamScreen() throws IOException, ConfigurationException { Codec codec = streamer.getCodec(); MediaCodec mediaCodec = createMediaCodec(codec, encoderName); - MediaFormat format = createFormat(codec.getMimeType(), bitRate, maxFps, codecOptions); + MediaFormat format = createFormat(codec.getMimeType(), videoBitRate, maxFps, codecOptions); IBinder display = createDisplay(); device.setRotationListener(this); diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index a926f443..f764804c 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -117,7 +117,7 @@ public final class Server { Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecId(), options.getSendFrameMeta()); - ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getBitRate(), options.getMaxFps(), codecOptions, + ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getVideoBitRate(), options.getMaxFps(), codecOptions, options.getEncoderName(), options.getDownsizeOnError()); try { // synchronous @@ -206,9 +206,9 @@ public final class Server { int maxSize = Integer.parseInt(value) & ~7; // multiple of 8 options.setMaxSize(maxSize); break; - case "bit_rate": - int bitRate = Integer.parseInt(value); - options.setBitRate(bitRate); + case "video_bit_rate": + int videoBitRate = Integer.parseInt(value); + options.setVideoBitRate(videoBitRate); break; case "max_fps": int maxFps = Integer.parseInt(value);