From 7321db6f28914df81e654cc4e2fbb3deec15fe2c Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 7 May 2023 12:35:27 +0200 Subject: [PATCH] Add recording to opus file Use the FFmpeg opus muxer to record an opus file. PR #3978 --- app/src/cli.c | 10 ++++++++++ app/src/options.h | 4 +++- app/src/recorder.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/cli.c b/app/src/cli.c index 40fe242e..ee0319ee 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -1493,6 +1493,9 @@ get_record_format(const char *name) { if (!strcmp(name, "mka")) { return SC_RECORD_FORMAT_MKA; } + if (!strcmp(name, "opus")) { + return SC_RECORD_FORMAT_OPUS; + } return 0; } @@ -1986,6 +1989,13 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], LOGE("Audio container does not support video stream"); return false; } + + if (opts->record_format == SC_RECORD_FORMAT_OPUS + && opts->audio_codec != SC_CODEC_OPUS) { + LOGE("Recording to OPUS file requires an OPUS audio stream " + "(try with --audio-codec=opus)"); + return false; + } } if (opts->audio_codec == SC_CODEC_RAW) { diff --git a/app/src/options.h b/app/src/options.h index 2424638f..0547b4ec 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -23,12 +23,14 @@ enum sc_record_format { SC_RECORD_FORMAT_MKV, SC_RECORD_FORMAT_M4A, SC_RECORD_FORMAT_MKA, + SC_RECORD_FORMAT_OPUS, }; static inline bool 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_MKA + || fmt == SC_RECORD_FORMAT_OPUS; } enum sc_codec { diff --git a/app/src/recorder.c b/app/src/recorder.c index 10102ec4..b0c41df0 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -66,6 +66,8 @@ sc_recorder_get_format_name(enum sc_record_format format) { case SC_RECORD_FORMAT_MKV: case SC_RECORD_FORMAT_MKA: return "matroska"; + case SC_RECORD_FORMAT_OPUS: + return "opus"; default: return NULL; }