QMediaRecorder::record() delay on Windows
-
Hi! I have a program which uses the QMediaRecorder class. Everything is configured as required (including my input devices and the QMediaCaptureSession). The program triggers audio recording at a press of a push button and stops the recording procedure when the button is released. On Windows, I have noticed that there is significant delay between the moment when the button triggers the QMediaRecorder::record() method and the time when the QMediaRecorder state is changed to RecordingState. This results in a glitch, where you think the recording has already started, but in fact you need keep the pushbutton pressed for long enough so it actually starts the recording process.
The same program works without issues on MacOS. This is using Qt 6.5.0 with both platforms utilizing their native multimedia backend (I am not using ffmpeg).
What could be the cause of such delay?
Don't know if this is related, but when launching the program in debug mode, I caught the following exception and the app crashed after that:
Exception at 0x7ffda9c1cf19, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in igd10um64xe!OpenAdapter_D3D11On12 -
Hi,
Do you have the same issue if you run in release mode ? Debug mode can sometime incur performance hit that can explain such behaviour.
-
@szumial Yes, it happens also when I trigger the recording using the "clicked" signal.
Whatever I do, there is always a noticeable delay. Before the recorder goes to RecordingState it is around 3 seconds when I trigger recording for the first time. Consecutive times have a slightly smaller delay time.
Here is a sample of my code:
// QMediaRecorder settings m_recorder.setMediaFormat({QMediaFormat::MP3}); m_recorder.setAudioChannelCount(1); m_recorder.setQuality(QMediaRecorder::Quality::VeryHighQuality); m_recorder.setEncodingMode(QMediaRecorder::ConstantQualityEncoding); // Pushbutton connections connect(recordButton, &QToolButton::pressed, this, [this] { record(true); }); connect(recordButton, &QToolButton::released, this, [this] { record(false); }); // Record method void MyWidget::record(bool on) { if (on) { recordButton->setChecked(true); QDir{}.mkpath(m_outputPath); m_recorder.setOutputLocation(QUrl::fromLocalFile(m_recordedFile)); m_audio->recorder().record(); recordButton->setText(tr(" Recording...")); } else { recordButton->setChecked(false); m_recorder.stop(); recordButton->setText(tr(" Start recording")); } }
-
@SGaist I am recording the microphone input to a local drive.
I was wondering if moving the recorder logic to a separate thread could improve it, but initial trials did not bring any benefits.
Another idea I have is a silly workaround to start recording at program start in order for any QMediaRecorder resources to be initialized before I trigger the recording with that pushbutton. This would not solve the root cause of the problem, but maybe improve user experience at least.