Bug 493308

Summary: Audio recording not working with specific device (external USB microphone - LCS_USB_Audio driver)
Product: [Applications] kdenlive Reporter: Slawek Mikula <slawek.mikula>
Component: Project Bin & ImportAssignee: Jean-Baptiste Mardelle <jb>
Status: REPORTED ---    
Severity: normal CC: fritzibaby, martin.evald+kde
Priority: NOR Keywords: triaged
Version First Reported In: 24.08.1   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: logs compressed

Description Slawek Mikula 2024-09-18 06:41:35 UTC
Created attachment 173816 [details]
logs compressed

At the beginning - audio recording on other devices (internal microphone, usb headset with microphone) works OK. There is issue with one USB microphone ("pro").

- plug device into USB
- device is discovered
- start kdenlive, enter settings, set recording to this device (is detected), set 44k1 and 1-channel (mono)
- go to timeline, enable sound monitoring for recording, soundbar displays correctly sound level from this microphone
- clik on the record button, it is enabled, automatically in the project bin displays the error that CaptureXXXX.wav cannot be loaded

I've checked all setting variations (1/2 channels, 44k1, 48k). 
In Audacity recording with this device works OK.

In the log one can see error:
qt.multimedia.ffmpeg.encoder: Stream initialization error: "Audio device has invalid preferred format"
 !!!!!!!!!!!!!!!! ERROR : QMediarecorder - Capture failed

Something is wrong with setting recording format during initialization.

In the attachment:
- lsusb of this device - it is branded "Mozos", but it is generic "chinese" microphone platform with generic USB interface
- dmesg of this device during connection
- kdenlive log with selected behaviour (two consecutive clicks on the record button)
Comment 1 Martin Evald 2025-03-01 12:05:39 UTC
I'm also running into this on version 24.12.2. Looks like bug #496211 may be a duplicate of this one.
Comment 2 Slawek Mikula 2025-03-01 21:18:29 UTC
Additionally I might add, that this exact device was recording correctly with previous version of Kdenlive. Don't know exact numbers, but before the recording architecture overhaul - from Qt5 to Qt6 AFAIK (sorry for this shortcut). Firstly when early versions of Kdenlive with Qt6 was released the recording in-app was postponed to next versions. And next when it returns, the recording hits this bug. I hope this helps a bit.

I can try to fix/fiddle with it (can compile Kdenlive) and provide some tips to correctly fix it, but if someone could pinpoint area in the code which can be responsible for this. I think something with creating audio recorder objects and audio format. Sorry. Not an expert with Qt :)  and don't have much time for digging it by myself.
Comment 3 emohr 2025-03-03 08:33:18 UTC
Thank you for reporting. 
For me it looks like your microphone is connected to the graphic card and so hardware accelerated.

Try the following:
Update your graphic card driver
Download the latest official AppImage https://kdenlive.org/en/download/, this to avoid any packaging issue
Try again

If the issue still happen try your microphone on a "normal" USB connection on your computer
Comment 4 Slawek Mikula 2025-03-03 08:38:46 UTC
Hi, 

 Sorry, don't know exactly what do you mean about hardware acceleration of this microphone (first heard of). You mean that in the graphic card has usb/xlr/jack connector ? Using laptop and long time no pc/desktop user :) It is/was always connected via USB bus/cable to the computer. Using ubuntu 24.04 and using standard intel+nvidia drivers. How can I find if this audio connection is hardware accelerated ?
Comment 5 Martin Evald 2025-03-03 08:44:31 UTC
(In reply to emohr from comment #3)
> Thank you for reporting. 
> For me it looks like your microphone is connected to the graphic card and so
> hardware accelerated.
> 
> Try the following:
> Update your graphic card driver
> Download the latest official AppImage https://kdenlive.org/en/download/,
> this to avoid any packaging issue
> Try again
> 
> If the issue still happen try your microphone on a "normal" USB connection
> on your computer

I'm seeing this error on my computer which is a regular desktop computer with an Asus PRIME X670-P motherboard, and the USB microphone connected directly to one of the normal motherboard USB connectors.
Comment 6 Martin Evald 2025-03-03 08:56:11 UTC
For what it's worth, I was able to work around this issue by adding the microphone as a JACK client using alsa_in, selecting the microphone as the default source in PipeWire, routing the capture channels from the microphone JACK device to the capture_FL and capture_FL inputs on the PipeWire JACK device, and finally selecting "JACK Source" as the capture device in Kdenlive. I'm not sure if all of these steps are necessary, and "JACK Source" overall seems like a weird device option to have for me given that Kdenlive seemingly doesn't add its own JACK device which you can route stuff to, but I was able to successfully record sound from the microphone using this method at least.