Skip to content

Commit 29e47bd

Browse files
committed
Add --audio-codec=raw option
Add support for raw (PCM S16 LE) audio codec (a decoder is included in FFmpeg). Even if it consumes more bandwidth, it provides a lower latency. PR #3757 <#3757>
1 parent 73cd59a commit 29e47bd

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

app/data/bash-completion/scrcpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ _scrcpy() {
7878
return
7979
;;
8080
--audio-codec)
81-
COMPREPLY=($(compgen -W 'opus aac' -- "$cur"))
81+
COMPREPLY=($(compgen -W 'raw opus aac' -- "$cur"))
8282
return
8383
;;
8484
--lock-video-orientation)

app/data/zsh-completion/_scrcpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local arguments
1010
arguments=(
1111
'--always-on-top[Make scrcpy window always on top \(above other windows\)]'
1212
'--audio-bit-rate=[Encode the audio at the given bit-rate]'
13-
'--audio-codec=[Select the audio codec]:codec:(opus aac)'
13+
'--audio-codec=[Select the audio codec]:codec:(raw opus aac)'
1414
'--audio-codec-options=[Set a list of comma-separated key\:type=value options for the device audio encoder]'
1515
'--audio-encoder=[Use a specific MediaCodec audio encoder]'
1616
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'

app/scrcpy.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Default is 0 (no buffering).
3333

3434
.TP
3535
.BI "\-\-audio\-codec " name
36-
Select an audio codec (opus or aac).
36+
Select an audio codec (raw, opus or aac).
3737

3838
Default is opus.
3939

app/src/cli.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static const struct sc_option options[] = {
132132
.longopt_id = OPT_AUDIO_CODEC,
133133
.longopt = "audio-codec",
134134
.argdesc = "name",
135-
.text = "Select an audio codec (opus or aac).\n"
135+
.text = "Select an audio codec (raw, opus or aac).\n"
136136
"Default is opus.",
137137
},
138138
{
@@ -1506,6 +1506,10 @@ parse_video_codec(const char *optarg, enum sc_codec *codec) {
15061506

15071507
static bool
15081508
parse_audio_codec(const char *optarg, enum sc_codec *codec) {
1509+
if (!strcmp(optarg, "raw")) {
1510+
*codec = SC_CODEC_RAW;
1511+
return true;
1512+
}
15091513
if (!strcmp(optarg, "opus")) {
15101514
*codec = SC_CODEC_OPUS;
15111515
return true;
@@ -1514,7 +1518,7 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) {
15141518
*codec = SC_CODEC_AAC;
15151519
return true;
15161520
}
1517-
LOGE("Unsupported audio codec: %s (expected opus or aac)", optarg);
1521+
LOGE("Unsupported audio codec: %s (expected raw, opus or aac)", optarg);
15181522
return false;
15191523
}
15201524

@@ -1912,6 +1916,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
19121916
}
19131917
}
19141918

1919+
if (opts->record_filename && opts->audio_codec == SC_CODEC_RAW) {
1920+
LOGW("Recording does not support RAW audio codec, automatically "
1921+
"switching to --audio-codec=opus");
1922+
opts->audio_codec = SC_CODEC_OPUS;
1923+
}
1924+
19151925
if (!opts->control) {
19161926
if (opts->turn_screen_off) {
19171927
LOGE("Could not request to turn screen off if control is disabled");

app/src/demuxer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
2323
#define SC_CODEC_ID_H264 UINT32_C(0x68323634) // "h264" in ASCII
2424
#define SC_CODEC_ID_H265 UINT32_C(0x68323635) // "h265" in ASCII
2525
#define SC_CODEC_ID_AV1 UINT32_C(0x00617631) // "av1" in ASCII
26+
#define SC_CODEC_ID_RAW UINT32_C(0x00726177) // "raw" in ASCII
2627
#define SC_CODEC_ID_OPUS UINT32_C(0x6f707573) // "opus" in ASCII
2728
#define SC_CODEC_ID_AAC UINT32_C(0x00616163) // "aac in ASCII"
2829
switch (codec_id) {
@@ -32,6 +33,8 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
3233
return AV_CODEC_ID_HEVC;
3334
case SC_CODEC_ID_AV1:
3435
return AV_CODEC_ID_AV1;
36+
case SC_CODEC_ID_RAW:
37+
return AV_CODEC_ID_PCM_S16LE;
3538
case SC_CODEC_ID_OPUS:
3639
return AV_CODEC_ID_OPUS;
3740
case SC_CODEC_ID_AAC:

app/src/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum sc_codec {
2727
SC_CODEC_H264,
2828
SC_CODEC_H265,
2929
SC_CODEC_AV1,
30+
SC_CODEC_RAW,
3031
SC_CODEC_OPUS,
3132
SC_CODEC_AAC,
3233
};

app/src/server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ sc_server_get_codec_name(enum sc_codec codec) {
169169
return "h265";
170170
case SC_CODEC_AV1:
171171
return "av1";
172+
case SC_CODEC_RAW:
173+
return "raw";
172174
case SC_CODEC_OPUS:
173175
return "opus";
174176
case SC_CODEC_AAC:

0 commit comments

Comments
 (0)