From da63fd91ff3fd00737f51f2de633697e931de6bc Mon Sep 17 00:00:00 2001 From: megapro17 Date: Tue, 7 Nov 2023 15:09:47 +0300 Subject: [PATCH 1/4] flac --- app/data/bash-completion/scrcpy | 2 +- app/data/zsh-completion/_scrcpy | 2 +- app/scrcpy.1 | 2 +- app/src/cli.c | 23 +++++++++++++++++-- app/src/demuxer.c | 3 +++ app/src/options.h | 1 + app/src/server.c | 2 ++ .../com/genymobile/scrcpy/AudioCodec.java | 1 + 8 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy index eaed88b7c9..fbba3e2b71 100644 --- a/app/data/bash-completion/scrcpy +++ b/app/data/bash-completion/scrcpy @@ -97,7 +97,7 @@ _scrcpy() { return ;; --audio-codec) - COMPREPLY=($(compgen -W 'opus aac raw' -- "$cur")) + COMPREPLY=($(compgen -W 'opus aac flac raw' -- "$cur")) return ;; --video-source) diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy index 4b1e5868af..75d8a1a6a2 100644 --- a/app/data/zsh-completion/_scrcpy +++ b/app/data/zsh-completion/_scrcpy @@ -11,7 +11,7 @@ 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-buffer=[Configure the audio buffering delay (in milliseconds)]' - '--audio-codec=[Select the audio codec]:codec:(opus aac raw)' + '--audio-codec=[Select the audio codec]:codec:(opus aac flac 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]' '--audio-source=[Select the audio source]:source:(output mic)' diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 2901d01471..4d784a9722 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, aac or raw). +Select an audio codec (opus, aac, flac or raw). Default is opus. diff --git a/app/src/cli.c b/app/src/cli.c index 56b5cfb214..45d6ed8393 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -152,7 +152,7 @@ static const struct sc_option options[] = { .longopt_id = OPT_AUDIO_CODEC, .longopt = "audio-codec", .argdesc = "name", - .text = "Select an audio codec (opus, aac or raw).\n" + .text = "Select an audio codec (opus, aac, flac or raw).\n" "Default is opus.", }, { @@ -1626,6 +1626,9 @@ get_record_format(const char *name) { if (!strcmp(name, "aac")) { return SC_RECORD_FORMAT_AAC; } + if (!strcmp(name, "flac")) { + return SC_RECORD_FORMAT_FLAC; + } return 0; } @@ -1695,11 +1698,15 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) { *codec = SC_CODEC_AAC; return true; } + if (!strcmp(optarg, "flac")) { + *codec = SC_CODEC_FLAC; + return true; + } if (!strcmp(optarg, "raw")) { *codec = SC_CODEC_RAW; return true; } - LOGE("Unsupported audio codec: %s (expected opus, aac or raw)", optarg); + LOGE("Unsupported audio codec: %s (expected opus, aac, flac or raw)", optarg); return false; } @@ -2376,6 +2383,18 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], "(try with --audio-codec=aac)"); return false; } + if (opts->record_format == SC_RECORD_FORMAT_FLAC + && opts->audio_codec != SC_CODEC_FLAC) { + LOGE("Recording to FLAC file requires an FLAC audio stream " + "(try with --audio-codec=flac)"); + return false; + } + } + + if (opts->audio_codec == SC_CODEC_FLAC) { + if (opts->audio_bit_rate) { + LOGW("--audio-bit-rate is ignored for flac audio codec"); + } } if (opts->audio_codec == SC_CODEC_RAW) { diff --git a/app/src/demuxer.c b/app/src/demuxer.c index 943f72b659..ca27c0bc1f 100644 --- a/app/src/demuxer.c +++ b/app/src/demuxer.c @@ -26,6 +26,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_AAC UINT32_C(0x664c6143) // "fLaC in ASCII" #define SC_CODEC_ID_RAW UINT32_C(0x00726177) // "raw" in ASCII switch (codec_id) { case SC_CODEC_ID_H264: @@ -43,6 +44,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_FLAC: + return AV_CODEC_ID_FLAC; case SC_CODEC_ID_RAW: return AV_CODEC_ID_PCM_S16LE; default: diff --git a/app/src/options.h b/app/src/options.h index 18b437d83e..ee8874baf8 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -41,6 +41,7 @@ enum sc_codec { SC_CODEC_AV1, SC_CODEC_OPUS, SC_CODEC_AAC, + SC_CODEC_FLAC, SC_CODEC_RAW, }; diff --git a/app/src/server.c b/app/src/server.c index 2b3439dad0..d4726c2af8 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -178,6 +178,8 @@ sc_server_get_codec_name(enum sc_codec codec) { return "opus"; case SC_CODEC_AAC: return "aac"; + case SC_CODEC_FLAC: + return "flac"; case SC_CODEC_RAW: return "raw"; default: diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java b/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java index 1f3b07a032..fcfb3b6d03 100644 --- a/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java +++ b/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java @@ -5,6 +5,7 @@ public enum AudioCodec implements Codec { OPUS(0x6f_70_75_73, "opus", MediaFormat.MIMETYPE_AUDIO_OPUS), AAC(0x00_61_61_63, "aac", MediaFormat.MIMETYPE_AUDIO_AAC), + FLAC(0x66_4c_61_43, "flac", MediaFormat.MIMETYPE_AUDIO_FLAC), RAW(0x00_72_61_77, "raw", MediaFormat.MIMETYPE_AUDIO_RAW); private final int id; // 4-byte ASCII representation of the name From a507a32e5924548fbc3c56721817e9ec3d80749d Mon Sep 17 00:00:00 2001 From: megapro17 Date: Tue, 7 Nov 2023 15:16:30 +0300 Subject: [PATCH 2/4] also there --- app/src/options.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/options.h b/app/src/options.h index ee8874baf8..5a37b13118 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -25,6 +25,7 @@ enum sc_record_format { SC_RECORD_FORMAT_MKA, SC_RECORD_FORMAT_OPUS, SC_RECORD_FORMAT_AAC, + SC_RECORD_FORMAT_FLAC, }; static inline bool @@ -33,6 +34,7 @@ sc_record_format_is_audio_only(enum sc_record_format fmt) { || fmt == SC_RECORD_FORMAT_MKA || fmt == SC_RECORD_FORMAT_OPUS || fmt == SC_RECORD_FORMAT_AAC; + || fmt == SC_RECORD_FORMAT_FLAC; } enum sc_codec { From 9ee2e5b46dbbec4bc3bebd74bc30f5657b55da7e Mon Sep 17 00:00:00 2001 From: megapro17 Date: Tue, 7 Nov 2023 17:44:22 +0300 Subject: [PATCH 3/4] fix --- app/src/demuxer.c | 2 +- app/src/options.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/demuxer.c b/app/src/demuxer.c index ca27c0bc1f..69d0c42b76 100644 --- a/app/src/demuxer.c +++ b/app/src/demuxer.c @@ -26,7 +26,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_AAC UINT32_C(0x664c6143) // "fLaC in ASCII" +#define SC_CODEC_ID_FLAC UINT32_C(0x664c6143) // "fLaC in ASCII" #define SC_CODEC_ID_RAW UINT32_C(0x00726177) // "raw" in ASCII switch (codec_id) { case SC_CODEC_ID_H264: diff --git a/app/src/options.h b/app/src/options.h index 5a37b13118..b8199ea2b6 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -25,7 +25,7 @@ enum sc_record_format { SC_RECORD_FORMAT_MKA, SC_RECORD_FORMAT_OPUS, SC_RECORD_FORMAT_AAC, - SC_RECORD_FORMAT_FLAC, + SC_RECORD_FORMAT_FLAC; }; static inline bool @@ -33,7 +33,7 @@ sc_record_format_is_audio_only(enum sc_record_format fmt) { return fmt == SC_RECORD_FORMAT_M4A || fmt == SC_RECORD_FORMAT_MKA || fmt == SC_RECORD_FORMAT_OPUS - || fmt == SC_RECORD_FORMAT_AAC; + || fmt == SC_RECORD_FORMAT_AAC || fmt == SC_RECORD_FORMAT_FLAC; } From fda7e13755a21c99c0c8be26b353406d57813bad Mon Sep 17 00:00:00 2001 From: megapro17 Date: Tue, 7 Nov 2023 17:53:23 +0300 Subject: [PATCH 4/4] last place --- app/src/recorder.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/recorder.c b/app/src/recorder.c index 23c8b4975c..d13b122ae9 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -69,6 +69,8 @@ sc_recorder_get_format_name(enum sc_record_format format) { return "matroska"; case SC_RECORD_FORMAT_OPUS: return "opus"; + case SC_RECORD_FORMAT_FLAC: + return "flac"; default: return NULL; }