Qt5 QMediaRecorder: does not support any codec or container
-
Hello everybody.
I'm trying to acquire a rtsp video stream from a remote IP camera and record it on a file.
I can successfully display the video stream using the QMediaPlayer and QVideoWidget classes. No problem in that.
Now, I need to record the video stream on a file. Doesn't really matter which video format (I will need a compressed format, though).
To do this I'm tryiing the QMediaRecorder class, but it seems I can't make it work.
The code I'm using is as follows:mainwindow.h
... #include <QMediaRecorder> ... QMediaRecorder *recorder; ...
mainwindow.cpp
recorder = new QMediaRecorder(player,this); connect(recorder, QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error), [=](QMediaRecorder::Error error){qDebug() << "Recorder error: " << error;}); qDebug() << "recorder->supportedVideoCodecs()" << recorder->supportedVideoCodecs(); qDebug() << "recorder->supportedAudioCodecs()" << recorder->supportedAudioCodecs(); qDebug() << "recorder->supportedContainers() " << recorder->supportedContainers(); qDebug() << "recorder->supportedFrameRates() " << recorder->supportedFrameRates(); qDebug() << "recorder->supportedResolutions()" << recorder->supportedResolutions(); QVideoEncoderSettings settings = recorder->videoSettings(); settings.setBitRate(4096); settings.setCodec("video/mpeg4"); settings.setResolution(640, 480); settings.setEncodingMode(QMultimedia::ConstantQualityEncoding); settings.setQuality(QMultimedia::HighQuality); recorder->setVideoSettings(settings); qDebug() << " "; qDebug() << "recorder->setVideoSettings(settings);"; qDebug() << " encodingMode" << settings.encodingMode() << recorder->videoSettings().encodingMode(); qDebug() << " codec " << settings.codec() << recorder->videoSettings().codec(); qDebug() << " bitRate " << settings.bitRate() << recorder->videoSettings().bitRate(); qDebug() << " frameRate " << settings.frameRate() << recorder->videoSettings().frameRate(); qDebug() << " resolution " << settings.resolution() << recorder->videoSettings().resolution(); qDebug() << " quality " << settings.quality() << recorder->videoSettings().quality();
Then the result I have on the QtCreator's console as the software is run is as follows:
recorder->supportedVideoCodecs() () recorder->supportedAudioCodecs() () recorder->supportedContainers() () recorder->supportedFrameRates() () recorder->supportedResolutions() () recorder->setVideoSettings(settings); encodingMode 0 0 codec "video/mpeg4" "" bitRate 4096 -1 frameRate 0 0 resolution QSize(640, 480) QSize(-1, -1) quality 3 2
Same happens if I use
settings.setCodec("video/avi");
orsettings.setCodec("H.264");
(even though I know that the problem is probably not on the video codec choice at this point).
It seems that the QMediaRecorder object does not support anything at all as it is created. No video/audio codec, no container (I don't even know what a "container" is), no resolution and no frame rate.
The same happens on both Windows 10, Windows 11 and Ubuntu 22.04.1 LTS.
I'm using Qt 5.15.2.Has anyone had this kind of problem before. Does anyone have any idea on how I can try to solve it?
-
Hello Joe.
Yes, I did. I installed it by writingsudo apt-get install gstreamer1.0-libav gstreamer1.0-plugins-base gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly sudo apt-get install libgstreamer1.0-dev
in the Linux console.
I'm using a virtual machine throuhg Oracle VM Virtualbox in a Windows system.Right now I'm trying to use Qt6 (never used it before), but with this one I'm having a lot of trouble with the rtsp video stream.
edit:
With Qt 6.7 I obtained that:
- recorder->mediaFormat().supportedFileFormats(QMediaFormat::Encode) returns QList(QMediaFormat::MPEG4, QMediaFormat::Matroska, QMediaFormat::WMV, QMediaFormat::AVI, QMediaFormat::QuickTime)
- recorder->mediaFormat().supportedFileFormats(QMediaFormat::Decode) returns QList(QMediaFormat::MPEG4, QMediaFormat::Matroska, QMediaFormat::WMV, QMediaFormat::AVI, QMediaFormat::QuickTime)
- recorder->mediaFormat().supportedVideoCodecs(QMediaFormat::Encode) returns QList(QMediaFormat::VideoCodec::MotionJPEG, QMediaFormat::VideoCodec::MPEG4, QMediaFormat::VideoCodec::MPEG1, QMediaFormat::VideoCodec::MPEG2)
- recorder->mediaFormat().supportedVideoCodecs(QMediaFormat::Decode) returns QList(QMediaFormat::VideoCodec::MotionJPEG, QMediaFormat::VideoCodec::MPEG4, QMediaFormat::VideoCodec::MPEG1, QMediaFormat::VideoCodec::MPEG2)
However, with Qt6 I got other problems
- Cannot stream from a IP Camera with the rtsp protocol
- How do I record from a QMediaPlayer with QMediaRecorder (it seems I can only record from a QCamera object)?
-
@JoeCFD Yes, I figured that out.
I tried to set the environment variable QT_MEDIA_BACKEND to gstreamer and managed to have a glimpse of video stream in Qt 6.
However I had a lot of lost packets, lantency issues and network errors (that I don't have in Qt 5).
Another problem of Qt 6 is that I need a QCamera object to be able to record thorugh QMediaCaptureSession and QMediaRecorder and I don't know how to set a QCamera with a remote IP camera.
So I decided to go back to Qt 5 (where I can at least successfully see the video stream).
For now I'm trying to record the video stream via a QProcess that executes the Linux commandffmpeg -rtsp_transport tcp -i rtsp://<user>:<password>@<IP>:<port> -acodec copy -vcodec mpeg4 videotest.mp4
It seems that it works this way, but it's only going to work on Linux machines.