From d2952c7e93f151d773f38aa368b7163b0ff31cf2 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 3 Mar 2023 21:19:37 +0100 Subject: [PATCH] Add --audio-codec=raw option Add support for raw (PCM S16 LE) audio codec (a raw decoder is included in FFmpeg). PR #3757 --- app/data/bash-completion/scrcpy | 2 +- app/data/zsh-completion/_scrcpy | 2 +- app/scrcpy.1 | 2 +- app/src/cli.c | 13 +++++++++++-- app/src/demuxer.c | 3 +++ app/src/options.h | 1 + app/src/server.c | 2 ++ 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy index 74c3ee57..c3649364 100644 --- a/app/data/bash-completion/scrcpy +++ b/app/data/bash-completion/scrcpy @@ -78,7 +78,7 @@ _scrcpy() { return ;; --audio-codec) - COMPREPLY=($(compgen -W 'opus aac' -- "$cur")) + COMPREPLY=($(compgen -W 'opus aac raw' -- "$cur")) return ;; --lock-video-orientation) diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy index b28201a4..d713761c 100644 --- a/app/data/zsh-completion/_scrcpy +++ b/app/data/zsh-completion/_scrcpy @@ -10,7 +10,7 @@ local arguments arguments=( '--always-on-top[Make scrcpy window always on top \(above other windows\)]' '--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-encoder=[Use a specific MediaCodec audio encoder]' {-b,--video-bit-rate=}'[Encode the video at the given bit-rate]' diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 120ea192..e8e36188 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -35,7 +35,7 @@ Default is 50. .TP .BI "\-\-audio\-codec " name -Select an audio codec (opus or aac). +Select an audio codec (opus, aac or raw). Default is opus. diff --git a/app/src/cli.c b/app/src/cli.c index 122a5891..d45be878 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -134,7 +134,7 @@ static const struct sc_option options[] = { .longopt_id = OPT_AUDIO_CODEC, .longopt = "audio-codec", .argdesc = "name", - .text = "Select an audio codec (opus or aac).\n" + .text = "Select an audio codec (opus, aac or raw).\n" "Default is opus.", }, { @@ -1522,7 +1522,11 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) { *codec = SC_CODEC_AAC; 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; } @@ -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->turn_screen_off) { LOGE("Could not request to turn screen off if control is disabled"); diff --git a/app/src/demuxer.c b/app/src/demuxer.c index 15a595a0..a4fa19f4 100644 --- a/app/src/demuxer.c +++ b/app/src/demuxer.c @@ -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_OPUS UINT32_C(0x6f707573) // "opus" 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) { case SC_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; case SC_CODEC_ID_AAC: return AV_CODEC_ID_AAC; + case SC_CODEC_ID_RAW: + return AV_CODEC_ID_PCM_S16LE; default: LOGE("Unknown codec id 0x%08" PRIx32, codec_id); return AV_CODEC_ID_NONE; diff --git a/app/src/options.h b/app/src/options.h index d9c2d228..06b4ddfa 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -29,6 +29,7 @@ enum sc_codec { SC_CODEC_AV1, SC_CODEC_OPUS, SC_CODEC_AAC, + SC_CODEC_RAW, }; enum sc_lock_video_orientation { diff --git a/app/src/server.c b/app/src/server.c index 9d4fb098..7b503427 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -173,6 +173,8 @@ sc_server_get_codec_name(enum sc_codec codec) { return "opus"; case SC_CODEC_AAC: return "aac"; + case SC_CODEC_RAW: + return "raw"; default: return NULL; }