FFmpeg command to capture Audio from Android mobile
Asked Answered
C

2

2

I'm trying to capture Audio from my Android mobile using FFmpeg. Tried the below commands and the recorded clip has no Audio in it, it's just a dark black screen with no audio/video.

Basically, I want to stream the live microphone audio to the RTSP server

Given all Android permission for the microphone & camera.

Lib used : ffmpeg_kit_flutter

Here are the commands which I tried :

 FFmpegKit.execute('-y -f android_camera -i 0:1 -r 30 -c:a aac -f rtsp -rtsp_transport tcp "$Url"');

Command:

FFmpegKit.execute('-y -f android_camera -i 0:1 -r 30 -c:a libmp3lame -qscale:a 2 "/storage/emulated/0/Download/androidvideo.mp3"');

FFmpegKit.execute('-y -f android_camera -i 0:0 -r 30 -c:a wavpack -b:a 64k "/storage/emulated/0/Download/androidvideo.wav"');

This command records video but no audio in it

FFmpegKit.execute('-video_size hd720 -f android_camera -camera_index 1 -i anything -r 10 -t 00:00:15 "$dir/androidvideo.mp4”');

Response

I/flutter (22881): Loading ffmpeg-kit-flutter.
D/ffmpeg-kit-flutter(22881): FFmpegKitFlutterPlugin com.arthenica.ffmpegkit.flutter.FFmpegKitFlutterPlugin@7f3db78 started listening to events on io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation@518a6b1.
I/flutter (22881): Loaded ffmpeg-kit-flutter-android-https-arm64-v8a-5.1.0.
D/VendorTagDescriptor(22881): addVendorDescriptor: vendor tag id 3854507339 added
W/MapperHal(22881): buffer descriptor with invalid usage bits 0x202000
D/ViewRootImpl@53a7452[FlutterFragmentActivity](22881): ViewPostIme pointer 1
W/ACameraCaptureSession(22881): Device is closed but session 0 is not notified
I/flutter (22881): logs:ffmpeg version n5.1.2
I/flutter (22881): logs: Copyright (c) 2000-2022 the FFmpeg developers
I/flutter (22881): logs:
I/flutter (22881): logs:  built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
I/flutter (22881): logs:  configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --target-os=android --enable-neon --enable-asm --enable-inline-asm --ar=aarch64-linux-android-ar --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --ranlib=aarch64-linux-android-ranlib --strip=aarch64-linux-android-strip --nm=aarch64-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-pthreads --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --
I/flutter (22881): logs:  libavutil      57. 28.100 / 57. 28.100
I/flutter (22881): logs:  libavcodec     59. 37.100 / 59. 37.100
I/flutter (22881): logs:  libavformat    59. 27.100 / 59. 27.100
I/flutter (22881): logs:  libavdevice    59.  7.100 / 59.  7.100
I/flutter (22881): logs:  libavfilter     8. 44.100 /  8. 44.100
I/flutter (22881): logs:  libswscale      6.  7.100 /  6.  7.100
I/flutter (22881): logs:  libswresample   4.  7.100 /  4.  7.100
I/flutter (22881): logs:[android_camera @ 0x7450bb2f80] Requested video_size 0x0 not available, falling back to 4032x3024
I/flutter (22881): logs:Input #0, android_camera, from '0:0':
I/flutter (22881): logs:  Duration: 
I/flutter (22881): logs:N/A
I/flutter (22881): logs:, start: 
I/flutter (22881): logs:299109.760553
I/flutter (22881): logs:, bitrate: 
I/flutter (22881): logs:N/A
I/flutter (22881): logs:
I/flutter (22881): logs:  Stream #0:0
I/flutter (22881): logs:: Video: rawvideo (NV21 / 0x3132564E), nv21, 4032x3024
I/flutter (22881): logs:, 
I/flutter (22881): logs:30 fps, 
I/flutter (22881): logs:30 tbr, 
I/flutter (22881): logs:1000000000.00 tbn
I/flutter (22881): logs:
I/flutter (22881): logs:    Side data:
I/flutter (22881): logs:      
I/flutter (22881): logs:displaymatrix: rotation of -90.00 degrees
I/flutter (22881): logs:
I/flutter (22881): logs:Stream mapping:
I/flutter (22881): logs:  Stream #0:0 -> #0:0
I/flutter (22881): logs: (rawvideo (native) -> mpeg4 (native))
I/flutter (22881): logs:
I/flutter (22881): logs:Press [q] to stop, [?] for help
I/flutter (22881): logs:Output #0, mp4, to '/storage/emulated/0/Download/androidvideo.mp4':
I/flutter (22881): logs:  Metadata:
I/flutter (22881): logs:    encoder         : 
I/flutter (22881): logs:Lavf59.27.100
I/flutter (22881): logs:
I/flutter (22881): logs:  Stream #0:0
I/flutter (22881): logs:: Video: mpeg4 (mp4v / 0x7634706D), yuv420p(tv, progressive), 3024x4032, q=2-31, 200 kb/s
I/flutter (22881): logs:, 
I/flutter (22881): logs:30 fps, 
I/flutter (22881): logs:15360 tbn
I/flutter (22881): logs:
I/flutter (22881): logs:    Metadata:
I/flutter (22881): logs:      encoder         : 
I/flutter (22881): logs:Lavc59.37.100 mpeg4
I/flutter (22881): logs:
I/flutter (22881): logs:    Side data:
I/flutter (22881): logs:      
I/flutter (22881): logs:cpb: 
I/flutter (22881): logs:bitrate max/min/avg: 0/0/200000 buffer size: 0 
I/flutter (22881): logs:vbv_delay: N/A
I/flutter (22881): logs:
I/flutter (22881): logs:      
I/flutter (22881): logs:displaymatrix: rotation of -0.00 degrees
I/flutter (22881): logs:
I/flutter (22881): logs:frame=    1 fps=0.0 q=3.4 size=       0kB time=00:00:00.00 bitrate=5415.4kbits/s speed=32.5x    
I/flutter (22881): logs:frame=    2 fps=0.0 q=2.0 size=       0kB time=00:00:00.03 bitrate=  10.5kbits/s speed=0.0475x    
I/flutter (22881): logs:frame=    9 fps=6.8 q=10.9 size=     256kB time=00:00:00.26 bitrate=7863.7kbits/s dup=5 drop=0 speed=0.202x    
I/flutter (22881): logs:frame=   13 fps=6.6 q=22.7 size=     512kB time=00:00:00.40 bitrate=10484.9kbits/s dup=7 drop=0 speed=0.203x    
I/flutter (22881): logs:frame=   28 fps=8.4 q=31.0 size=     512kB time=00:00:00.90 bitrate=4660.4kbits/s dup=20 drop=0 speed=0.269x    
I/flutter (22881): logs:frame=   55 fps= 11 q=31.0 size=    1024kB time=00:00:01.80 bitrate=4660.4kbits/s dup=45 drop=0 speed=0.368x    
I/flutter (22881): logs:frame=   60 fps=9.8 q=31.0 size=    1280kB time=00:00:01.96 bitrate=5331.7kbits/s dup=49 drop=0 speed=0.321x    
I/flutter (22881): logs:frame=   73 fps=9.4 q=31.0 Lsize=    1500kB time=00:00:02.40 bitrate=5121.4kbits/s dup=61 drop=0 speed=0.309x    
I/flutter (22881): logs:video:1499kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.079011%
I/flutter (22881): logs:frame=   73 fps=9.4 q=31.0 Lsize=N/A time=00:00:02.40 bitrate=N/A dup=61 drop=0 speed=0.309x    
I/flutter (22881): logs:video:1499kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
I/flutter (22881): logs:[android_camera @ 0x7450bb2f80] Android camera capture session was closed.
I/flutter (22881): logs:Exiting normally, received signal 2.
I/flutter (22881): output:ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
I/flutter (22881):   built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
I/flutter (22881):   configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --target-os=android --enable-neon --enable-asm --enable-inline-asm --ar=aarch64-linux-android-ar --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --ranlib=aarch64-linux-android-ranlib --strip=aarch64-linux-android-strip --nm=aarch64-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-s
I/flutter (22881): failStackTrace:null
I/flutter (22881): result code:255
Constriction answered 8/7, 2023 at 15:12 Comment(0)
C
3

The package has been updated so you must run the command asynchronously, using async you can find new examples in a new version of package docs ffmpeg_kit_flutter, like this snippet I found:

import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';

FFmpegKit.execute('-i file1.mp4 -c:v mpeg4 file2.mp4').then((session) async {
  final returnCode = await session.getReturnCode();

  if (ReturnCode.isSuccess(returnCode)) {

    // SUCCESS

  } else if (ReturnCode.isCancel(returnCode)) {

    // CANCEL

  } else {

    // ERROR

  }
});
Cockhorse answered 13/7, 2023 at 16:46 Comment(4)
I'm using the latest version(5.1.0) of the package. I want to record Audio from the mobile microphone. have you tried that?Constriction
Yes, try the Package with new way I hope you don't forget to vote, Otherwise update the question if there is something new happendCockhorse
your example doesn't record audio from a mobile microphone, instead it -i file1.mp4 -> it takes the input file that is "file1.mp4" -c:v mpeg4 -> This is the codec you used file2.mp4 -> and this is the output file here is one example which tries to capture audio, but this command is not working. "-f android_camera -i 0:1 -c:a aac output.aac"Constriction
I know that ,my answer was to provide you the right way,so you can use your custom commandCockhorse
C
0

You can use this package to record audio and save it

Audo waveforms

Cooney answered 17/7, 2023 at 9:59 Comment(1)
why im using FFmpeg is actually I want to stream live audio to rtsp server so. Updated my question.Constriction

© 2022 - 2024 — McMap. All rights reserved.