-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flac audio codec #4410
Flac audio codec #4410
Conversation
Refs #3757 (comment) Small fix to compile: diff --git a/app/src/demuxer.c b/app/src/demuxer.c
index ca27c0bc1..69d0c42b7 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 5a37b1311..914338946 100644
--- a/app/src/options.h
+++ b/app/src/options.h
@@ -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;
}
But at runtime, I get:
To be investigated. EDIT: (Also, an argument to set the compression compression should maybe be added?) |
maybe this? @@ -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;
}; |
would |
If I hardcode this value, it "works": diff --git a/app/src/demuxer.c b/app/src/demuxer.c
index 69d0c42b7..520ac609e 100644
--- a/app/src/demuxer.c
+++ b/app/src/demuxer.c
@@ -210,6 +210,7 @@ run_demuxer(void *data) {
codec_ctx->channels = 2;
#endif
codec_ctx->sample_rate = 48000;
+ codec_ctx->sample_fmt = AV_SAMPLE_FMT_S16;
}
if (avcodec_open2(codec_ctx, codec, NULL) < 0) { But another problem is that the flac encoder is not low latency at all: it produces blocks of 4096 samples, which represent ~85.333ms. So to make it work, the audio latency must be increased:
And recording to mp4 does not work (mp4 does not support flac), only mkv works. 😕 |
can you share binary for windows? even without ffmpeg dlls
it does, opus too as well as vp9. by the official mpeg specification. most players can play these files fine. ffmpeg can create it without problems
seems like there's no any other lossless audio encoder built in android... i guess you don't need low latency when recording to a file |
(only the .exe and the server, not tested)
For some reason, the call to Line 428 in 446ea81
|
OK, so I guess the extradata produced by scrcpy/server/src/main/java/com/genymobile/scrcpy/Streamer.java Lines 103 to 117 in 446ea81
EDIT: for reference, the config packet produced by
EDIT: I confirm that if we cut only this part in the config packet, it works (I can record to mp4 properly now):
(I have not done it properly, I just hardcoded to test) |
PR #4410 <##4410> Co-authored-by: Romain Vimont <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
I made the following changes:
Here is a full release of branch
Please review and test. |
PR #4410 <##4410> Co-authored-by: Romain Vimont <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
Wow, nice work! Everything works now, audio is recorded and played without any problems. But the file has no duration, to fix it I have to convert the file. But isn't that fixConfigPacket for each codec is looks weird? Maybe there is a more elegant solution..... |
Indeed, when a FLAC audio stream is muxed to flac ( However, for an OPUS audio stream muxed to opus ( Similarly, when a FLAC audio stream is muxed to MP4 ( So I guess this is related to the flac muxer, it does not write the duration when writing the trailer. I don't know if we can pass some more configuration so that it correctly writes the duration. Related code: https://github.com/FFmpeg/FFmpeg/blob/6d60cc7baf662b64e3c50f95826dead58cf8e839/libavformat/flacenc.c#L320-L346
It's just that MediaCodec wraps the extradata into its own structure (different per codec), so we have to extract the relevant extradata to pass to FFmpeg. |
PR #4410 <##4410> Co-authored-by: Romain Vimont <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
On top of these changes, I added support for recording raw audio to Branch:
Please review and test 😉 |
PR #4410 <##4410> Co-authored-by: Romain Vimont <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
I merged flac and wav support into If we find a way to fix the missing flac duration, that would be great, but this can still be merged as is. |
I didn't tested it, compiling is complicated
It would also be nice to have an 8 compression ratio