SeaDve / Kooha

Elegantly record your screen
GNU General Public License v3.0
2.4k stars 70 forks source link

Audio stutters and eventually cuts out on longer recordings #218

Closed wtftf closed 4 months ago

wtftf commented 1 year ago

Except that's exactly the problem I'm now experiencing (on two consecutive failed attempts) recording video & audio of about 1:10:00 in total length. Audio starts disintegrating by 10:00 and cuts out completely at about 13:30.

pabrep commented 1 year ago

Exactly the same problem for me.

hariseldon78 commented 8 months ago

same problem for me with version 2.2.3, running on wayland though

johannesulf commented 8 months ago

I'm having the same problem with version 2.2.4 on Gnome 45 (Wayland). I'd be happy to provide more information since I'd love to use Kooha to record my lectures. Unfortunately, in its current state, it simply doesn't work for that since the audio is practically lost.

shineon82 commented 7 months ago

Same problem, version 2.2.4, Archlinux, Gnome 45 (Wayland)

nekohayo commented 7 months ago

Recording in MP4 format (H.264 + MP3 48 kHz), with an Intel Kabylake chipset on the Wayland version of GNOME 45 with Kooha 2.2.4 from Flathub, my observation in my case is that this happens to audio recorded from the microphone rather than the audio recorded from the playback (monitor) audio device... or at least, it happens much faster with the microphone.

For example, I was able make an 11-minutes-long "monitor audio only" recording and it was flawless, but when recording a video with microphone-only audio, the sound started stuttering at ~4 minutes 23 secs, within the next 5 seconds it started disintegrating significantly, at 4 mins 50 seconds it became near unusable, and beyond 5 mins 20 seconds it was pretty much unrecognizeable/unintelligible.

I tried again another recording "from the microphone" while writing this comment, and it failed in the exact same way, around the 4 minutes 13-23 seconds mark the sound started stuttering and getting progressively worse in the minute that followed.

The audio, while garbled, apparently remained in sync with the visuals (which remained smooth), however.

nekohayo commented 4 months ago

I have some new findings for you today. By total happenstance, I discovered that not only Kooha, but also @ryonakano's "Reco" app is affected with the same symptoms on the same computer: after the 5 minutes mark, my microphone's recorded sound stream in the app starts becoming increasingly/exponentially saccated and garbled.

The differences are:

Since it affects two different applications, this is starting to sound like a PipeWire (or PulseAudio / ALSA / GStreamer?) bug to me.


On this computer, I am using a "Logitech USB Desktop Microphone" (that's what the product is named), which is identified as such under Linux with lsusb:

Bus 003 Device 053: ID 0556:0001 Asahi Kasei Microsystems Co., Ltd AK5370 I/F A/D Converter

I don't know/remember what sampling rate etc. this thing uses, it's probably either 44.1 or 48 kHz... I don't know if this might be a factor vs the motherboard or my ThinkPad's USB-C docking station that serves as the sound output through speakers.

Let me know if there is any additional information I should gather here to make it easier for you to narrow down which software component might be causing the issue.

nekohayo commented 4 months ago

In case the developers never encountered this issue themselves and don't know what it "sounds" like, here is a test sample recording with Kooha in microphone-only mode (you'd get a similar result with Reco when recording in "Both" microphone+system mode):

https://github.com/SeaDve/Kooha/assets/479401/11c62e7b-de9f-44a6-b931-604d5d612484

Play that video, turn on the volume (it is muted by default) and seek to the 3mins 40s mark, listen to the music and within 10-20 seconds the stuttering will start becoming noticeable; afterwards it will fall apart very rapidly within the minute that follows.

SeaDve commented 4 months ago

developers never encountered this issue themselves

I did encounter it, and it was reproducible most of the time.

@nekohayo Thanks for the very detailed report, I have actually attempted to debug and determine the root cause of the issue and failed a lot of times before. But now, I think I have found it. It seems to be caused by audiomixer dropping buffers once they become late. This is proven by setting qos-messages=true on audiomixer's sink pads and listening for QoS messages on the bus. The QoS messages from the audiomixer will start to appear with the stuttering.

A quick fix is setting the audiomixer's latency property to some value, other than 0. I was able to record audio for longer than an hour with the audio never cut, which would have been cut earlier than ~10 minutes with latency=0. But ideally, I think that the latency should be adjusted depending on the audio sources.

SeaDve commented 4 months ago

By matching the actual-latency-time of the src with the latency of the audiomixer, it seems to be fixed. I again attempted to record 2 hours, and there are zero stutters.

SeaDve commented 4 months ago

If anyone have the time, please test https://github.com/SeaDve/Kooha/pull/279.

nekohayo commented 4 months ago

I have checked out git main, built it with GNOME Builder, confirmed the bug still happened there (within 5 minutes of recording), then checked out your fix-stutter-audio branch, built it, and can confirm that the issue does not occur there even after 10 minutes of recording with the same methodology. Great job!

Hopefully others can confirm, but I am pretty confident that this is going to solve everybody's problems. Given how impactful it can be on the recorded results, I believe this could warrant a release on its own, it's that big of a difference in usability for users with (external?) microphones :)

SeaDve commented 4 months ago

That's nice to here, thanks!

SeaDve commented 4 months ago

I believe this could warrant a release on its own, it's that big of a difference in usability for users with (external?) microphones :)

As much as I like to do a release, I would like to wait for org.gnome.Platform//46 release.

SeaDve commented 4 months ago

But if someone have the time to submit patch on https://github.com/flathub/io.github.seadve.Kooha, I would accept it.

SeaDve commented 4 months ago

Submitted a patch https://github.com/flathub/io.github.seadve.Kooha/pull/12

SeaDve commented 4 months ago

I have published a patch on Flathub that should be available on flatpak update any time now.