Skip to content

Display and control your Android device

Add support for AAC audio codec

Romain Vimont4601735e51b1
diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy
index 5a50f6c5..f303ff66 100644
--- a/app/data/bash-completion/scrcpy
+++ b/app/data/bash-completion/scrcpy
@@ -73,7 +73,7 @@ _scrcpy() {
return
;;
--audio-codec)
- COMPREPLY=($(compgen -W 'opus' -- "$cur"))
+ COMPREPLY=($(compgen -W 'opus aac' -- "$cur"))
return
;;
--lock-video-orientation)
diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy
index 4f7ad5ef..a0d83a05 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)'
+ '--audio-codec=[Select the audio codec]:codec:(opus aac)'
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'
'--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 89533a1f..3ccbb111 100644
--- a/app/scrcpy.1
+++ b/app/scrcpy.1
@@ -27,7 +27,7 @@ Default is 128K (128000).
.TP
.BI "\-\-audio\-codec " name
-Select an audio codec (opus).
+Select an audio codec (opus or aac).
Default is opus.
diff --git a/app/src/cli.c b/app/src/cli.c
index 5f28164e..afd060b8 100644
--- a/app/src/cli.c
+++ b/app/src/cli.c
@@ -119,7 +119,7 @@ static const struct sc_option options[] = {
.longopt_id = OPT_AUDIO_CODEC,
.longopt = "audio-codec",
.argdesc = "name",
- .text = "Select an audio codec (opus).\n"
+ .text = "Select an audio codec (opus or aac).\n"
"Default is opus.",
},
{
@@ -1466,7 +1466,11 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) {
*codec = SC_CODEC_OPUS;
return true;
}
- LOGE("Unsupported audio codec: %s (expected opus)", optarg);
+ if (!strcmp(optarg, "aac")) {
+ *codec = SC_CODEC_AAC;
+ return true;
+ }
+ LOGE("Unsupported audio codec: %s (expected opus or aac)", optarg);
return false;
}
diff --git a/app/src/demuxer.c b/app/src/demuxer.c
index 482f2e04..64bf30a3 100644
--- a/app/src/demuxer.c
+++ b/app/src/demuxer.c
@@ -24,6 +24,7 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
#define SC_CODEC_ID_H265 UINT32_C(0x68323635) // "h265" 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_AAC UINT32_C(0x00616163) // "aac in ASCII"
switch (codec_id) {
case SC_CODEC_ID_H264:
return AV_CODEC_ID_H264;
@@ -33,6 +34,8 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
return AV_CODEC_ID_AV1;
case SC_CODEC_ID_OPUS:
return AV_CODEC_ID_OPUS;
+ case SC_CODEC_ID_AAC:
+ return AV_CODEC_ID_AAC;
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 c698e6e3..3efa2dd6 100644
--- a/app/src/options.h
+++ b/app/src/options.h
@@ -28,6 +28,7 @@ enum sc_codec {
SC_CODEC_H265,
SC_CODEC_AV1,
SC_CODEC_OPUS,
+ SC_CODEC_AAC,
};
enum sc_lock_video_orientation {
diff --git a/app/src/server.c b/app/src/server.c
index a797f01d..36146d86 100644
--- a/app/src/server.c
+++ b/app/src/server.c
@@ -167,6 +167,8 @@ sc_server_get_codec_name(enum sc_codec codec) {
return "av1";
case SC_CODEC_OPUS:
return "opus";
+ case SC_CODEC_AAC:
+ return "aac";
default:
return NULL;
}
diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java b/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java
index 4d9e3201..dc000e98 100644
--- a/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java
+++ b/server/src/main/java/com/genymobile/scrcpy/AudioCodec.java
@@ -3,7 +3,8 @@ package com.genymobile.scrcpy;
import android.media.MediaFormat;
public enum AudioCodec implements Codec {
- OPUS(0x6f_70_75_73, "opus", MediaFormat.MIMETYPE_AUDIO_OPUS);
+ OPUS(0x6f_70_75_73, "opus", MediaFormat.MIMETYPE_AUDIO_OPUS),
+ AAC(0x00_61_61_63, "aac", MediaFormat.MIMETYPE_AUDIO_AAC);
private final int id; // 4-byte ASCII representation of the name
private final String name;