Add --audio-codec=raw option

Add support for raw (PCM S16 LE) audio codec (a raw decoder is included
in FFmpeg).

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
This commit is contained in:
Romain Vimont 2023-03-03 21:19:37 +01:00
parent 66b6c06443
commit d2952c7e93
7 changed files with 20 additions and 5 deletions

View file

@ -78,7 +78,7 @@ _scrcpy() {
return return
;; ;;
--audio-codec) --audio-codec)
COMPREPLY=($(compgen -W 'opus aac' -- "$cur")) COMPREPLY=($(compgen -W 'opus aac raw' -- "$cur"))
return return
;; ;;
--lock-video-orientation) --lock-video-orientation)

View file

@ -10,7 +10,7 @@ local arguments
arguments=( arguments=(
'--always-on-top[Make scrcpy window always on top \(above other windows\)]' '--always-on-top[Make scrcpy window always on top \(above other windows\)]'
'--audio-bit-rate=[Encode the audio at the given bit-rate]' '--audio-bit-rate=[Encode the audio at the given bit-rate]'
'--audio-codec=[Select the audio codec]:codec:(opus aac)' '--audio-codec=[Select the audio codec]:codec:(opus aac raw)'
'--audio-codec-options=[Set a list of comma-separated key\:type=value options for the device audio encoder]' '--audio-codec-options=[Set a list of comma-separated key\:type=value options for the device audio encoder]'
'--audio-encoder=[Use a specific MediaCodec audio encoder]' '--audio-encoder=[Use a specific MediaCodec audio encoder]'
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]' {-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'

View file

@ -35,7 +35,7 @@ Default is 50.
.TP .TP
.BI "\-\-audio\-codec " name .BI "\-\-audio\-codec " name
Select an audio codec (opus or aac). Select an audio codec (opus, aac or raw).
Default is opus. Default is opus.

View file

@ -134,7 +134,7 @@ static const struct sc_option options[] = {
.longopt_id = OPT_AUDIO_CODEC, .longopt_id = OPT_AUDIO_CODEC,
.longopt = "audio-codec", .longopt = "audio-codec",
.argdesc = "name", .argdesc = "name",
.text = "Select an audio codec (opus or aac).\n" .text = "Select an audio codec (opus, aac or raw).\n"
"Default is opus.", "Default is opus.",
}, },
{ {
@ -1522,7 +1522,11 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) {
*codec = SC_CODEC_AAC; *codec = SC_CODEC_AAC;
return true; return true;
} }
LOGE("Unsupported audio codec: %s (expected opus or aac)", optarg); if (!strcmp(optarg, "raw")) {
*codec = SC_CODEC_RAW;
return true;
}
LOGE("Unsupported audio codec: %s (expected opus, aac or raw)", optarg);
return false; return false;
} }
@ -1923,6 +1927,11 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
} }
} }
if (opts->record_filename && opts->audio_codec == SC_CODEC_RAW) {
LOGW("Recording does not support RAW audio codec");
return false;
}
if (!opts->control) { if (!opts->control) {
if (opts->turn_screen_off) { if (opts->turn_screen_off) {
LOGE("Could not request to turn screen off if control is disabled"); LOGE("Could not request to turn screen off if control is disabled");

View file

@ -25,6 +25,7 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
#define SC_CODEC_ID_AV1 UINT32_C(0x00617631) // "av1" in ASCII #define SC_CODEC_ID_AV1 UINT32_C(0x00617631) // "av1" in ASCII
#define SC_CODEC_ID_OPUS UINT32_C(0x6f707573) // "opus" in ASCII #define SC_CODEC_ID_OPUS UINT32_C(0x6f707573) // "opus" in ASCII
#define SC_CODEC_ID_AAC UINT32_C(0x00616163) // "aac in ASCII" #define SC_CODEC_ID_AAC UINT32_C(0x00616163) // "aac in ASCII"
#define SC_CODEC_ID_RAW UINT32_C(0x00726177) // "raw" in ASCII
switch (codec_id) { switch (codec_id) {
case SC_CODEC_ID_H264: case SC_CODEC_ID_H264:
return AV_CODEC_ID_H264; return AV_CODEC_ID_H264;
@ -36,6 +37,8 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
return AV_CODEC_ID_OPUS; return AV_CODEC_ID_OPUS;
case SC_CODEC_ID_AAC: case SC_CODEC_ID_AAC:
return AV_CODEC_ID_AAC; return AV_CODEC_ID_AAC;
case SC_CODEC_ID_RAW:
return AV_CODEC_ID_PCM_S16LE;
default: default:
LOGE("Unknown codec id 0x%08" PRIx32, codec_id); LOGE("Unknown codec id 0x%08" PRIx32, codec_id);
return AV_CODEC_ID_NONE; return AV_CODEC_ID_NONE;

View file

@ -29,6 +29,7 @@ enum sc_codec {
SC_CODEC_AV1, SC_CODEC_AV1,
SC_CODEC_OPUS, SC_CODEC_OPUS,
SC_CODEC_AAC, SC_CODEC_AAC,
SC_CODEC_RAW,
}; };
enum sc_lock_video_orientation { enum sc_lock_video_orientation {

View file

@ -173,6 +173,8 @@ sc_server_get_codec_name(enum sc_codec codec) {
return "opus"; return "opus";
case SC_CODEC_AAC: case SC_CODEC_AAC:
return "aac"; return "aac";
case SC_CODEC_RAW:
return "raw";
default: default:
return NULL; return NULL;
} }