Problem detecting video codecs using QMediaRecorder
-
Hi, I have simple problem but doesn't seems to find any solution to it.
I'm trying to create a video recorder by connecting to a camera using QCamera, QCameraInfo, QCameraViewfinder etc.
I was able to get the camera to work, I see the live video feed of my camera without any problem.Now, I want to record this live feed to a .mp4 file (or any other format) but when creating a QMediaRecorder, I tried to use the QMediaRecorder::supportedVideoCodecs() functions to get the available video codecs, but it always return an empty list. I have VLC installed on the computer, FFmpeg as well (the FFmpeg is also included in the project as a library but still, QMediaRecorder never find any codecs.)
const QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras(); if(!availableCameras.isEmpty()){ /* Create a camera with info */ m_camera.reset(new QCamera(availableCameras.first())); m_camera->setCaptureMode(QCamera::CaptureVideo); m_camera->setViewfinder(ui->viewfinder); m_camera->start(); /* Create media recorder */ m_mediaRecorder.reset(new QMediaRecorder(m_camera.data())); m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Video Title Test"))); QList<QCameraViewfinderSettings> viewFinderSettingsList = m_camera->supportedViewfinderSettings(); m_camera->setViewfinderSettings(viewFinderSettingsList.first()); m_camera->start(); QVideoEncoderSettings videoSettings = m_mediaRecorder->videoSettings(); QStringList supportedVideoCodecs = m_mediaRecorder->supportedVideoCodecs(); // ... // Code continue here but since the list is empty at this point, it ain't revelant for the problem }
Is there any thing I forgot to include ...
#include <QCamera> #include <QCameraInfo> #include <QMediaMetaData> #include <QMediaRecorder>
I used those configurations in the .pro file :
QT += core gui network multimedia multimediawidgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17
Thanks in advance for any hints you could give me !
-
Hi,
What OS are you running ?
-
Microsoft Windows 10 Pro
Version 10.0.18363 Build 18363
x64-based PC
Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz, 3408Mhz, 4 Core(s), 8 Logical Processor(s)
16 GB of Installed Physical Memory (RAM)
System manufacturer : HP -
In that case, the fact that ffmpeg and VLC are installed does not matter as they don't provide system codecs and Qt uses the native backend.
You'll have to install some other codec packages although I am surprised that you don't even have access to the classic AVI stuff.
Note that you can also use VLC in your application. They provide Qt wrappers.
-
I'm as surprised as you that I don't have at least one codec... I'll try installing other codecs packages and have a look at VLC's Qt Wrapper but I mainly choose to use QMediaRecorder to reduce any other inclusion of librairies.
Thanks for the info, I'll keep you up-to-date.