Android Question Reduce audio latency in captured video

Cadenzo

Active Member
Licensed User
Longtime User
Hi, I use this solution as basic for video recording in music online teaching. It works very good, thanks to this super example. Student videos and tutor comments can be uploaded and downloaded from a server.
Only one problem: The audio latency. The sound is about one second later then the video and this is much for music teaching. By myself I only found ways to change video solution. May be, this code gives a hint?
B4X:
Public Sub Initialize (CameraPanel As Panel)
    mPanel = CameraPanel
    Camera.Initialize("Camera")
    jcamera = Camera
    PreviewSize.Initialize(1920, 1080)
    CaptureSize.Initialize(1920, 1080)
    StaticCaptureRequest.InitializeStatic("android.hardware.camera2.CaptureRequest")
    StaticCameraCharacteristics.InitializeStatic("android.hardware.camera2.CameraCharacteristics")
    StaticCaptureResult.InitializeStatic("android.hardware.camera2.CaptureResult")
    PreviewSettingsMap.Initialize
    CaptureSettingMap.Initialize
    bothMaps = Array(PreviewSettingsMap, CaptureSettingMap)
End Sub
I am lost in this android hardware settings. Could someone, please, help?
 

stevel05

Expert
Licensed User
Longtime User
Have you tried playing back the video on a different device (preferably a PC) to see if the latency is caused by the recording or playback?
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
This is indeed very strange. I use for Android the mentioned Camera2 / CamEx2 solution for recording, SimpleExoPlayer for playing. For iOS I use this LLCamera with Audio for recording and this VideoPlayer for playing.

Now, if I record and play a video with anroid it has this not acceptable latency. If I record and play with iPad it is almost no latency. But it is also good, if I record on android and receive on iPad. And it is also good, if I record on iPad and receive on android.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Playing on a PC, the iPad recorded (see here) is much better (and even mach smaller), than the android one (see here). But even the android recorded is (almost) acceptable. Really bad is, how the android ExoPlayer deals with the android recorded ones.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
There can be differences in implementation of codecs of different players on any system which can be exaggerated on lower power devices. Have you tried using the native VideoView to play them on Android?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just looked at your examples, still not perfect as you say.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Yes, I can try VideoView, but I thought, that ExoPlayer is the better one. I am still searching, how to make the android record better. As you mentioned, even on other players, it is not good yet.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I haven't used the library so don't know what the options are, but possibly changing the audio codec or changing to a lower sample rate may help if it's available.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Another option is to record the video with VideoRecordApp which relies on the default camera app
It would be much better to have this low level solution. Especially I was glad, that there is a almost similar one for B4i. But the recorded videos should be able to run on every standard player. So I will give a try the VideoRecordApp.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
run on every standard player
Part of the problem may be device specific, I tried recording with my Motorola G6 Play using the example you linked to in your first post and played it back using the default Android photo app. While not perfect, it was much better than the Android example video you posted.

Apple have control of the hardware that goes into their devices, so can generally provide a more consistent result, for newer devices at least..
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
It seems that for android I will find a solution, even if I have to choose VideoRecordApp instead of the prefered low level solution. Much more questions are now with the iOS version, I started a thread here. My tests with small videos where so successful, that I promised my music colleagues a new teaching platform on the end of the week. Now, in praxis with longer videos it becomes more complicated. Everything works fine, only the recording part is the big problem, in the moment.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I don't have B4i or a recent Apple device, so can't try it. I'm sure someone will help.
 
Upvote 0
Top