Record Sound and Video using QMediaRecorder
I am using Win 10 and I would like to record video from a camera and sound-using microphone.
I have tried to use QMediaRecorder but it do not record.
Code: I’ll put the code tonight because I am not home.
Always return no recording state, no error and empty output location
Do someone have a working example?
Is QMediaRecorder is working on windows?
Do I have to be careful to each codec? Which I can use to record in avi/ mp4?
I had another Idea.
I succeed at recording audio using QAudioRecorder and at recording video using OpenCV
Do someone knows how I can merge sound and video into one file?
- Do someone knows how I can merge sound and video into one file?
You can easy do with QProcess and command line ffmpeg
ffmpeg -i video.mp4 -i audio.mp3 output.mp4
@mrjj Thanks you i'll try tonight
I tried to use only Qt and here is my try. does someone know this problem?
mCamera = new QCamera(this); mRecorder = new QMediaRecorder(mCamera, this); mCamera->start(); mRecorder->record(); qDebug()<<mRecorder->supportedVideoCodecs(); qDebug()<<mRecorder->state(); qDebug()<<mRecorder->error(); qDebug()<<mRecorder->outputLocation();
You should first enumerate your camera to see if there's anything found.
Then you should configure QMediaRecorder. You didn't set any output file to record the video to.
The camera is working i checked using a viewfinder.
I tried to configure the recorder but stille the same states
mRecorder = new QMediaRecorder(mCamera, this);
QVideoEncoderSettings settings = mRecorder->videoSettings(); settings.setResolution(640,480); settings.setQuality(QMultimedia::VeryHighQuality); settings.setFrameRate(30.0); settings.setCodec("video/mp4"); mRecorder->setVideoSettings(settings); mRecorder->setContainerFormat("mp4"); bool test = mRecorder->setOutputLocation(QUrl("test.mp4")); qDebug()<< test; // false mCamera->setCaptureMode(QCamera::CaptureVideo); mCamera->start(); mRecorder->record(); qDebug()<<mRecorder->supportedVideoCodecs(); qDebug()<<mRecorder->state(); qDebug()<<mRecorder->error(); qDebug()<<mRecorder->outputLocation();
You should rather connect the related signals. Calling record and right after state and error is a bad idea since the recording might not have been started yet e.g. camera loading, setup, activation, recording setup etc.
I have connected my test to a push button. it still fails. i don't know why but i'll use openCV and ffmpeg then.
Thank you for your help . if you notice a solution, tell me.
One thing is: do you have an mp4 encoder on your machine ?
@SGaist I think not. i have VLC or openCV but i don't think Qt can access it.
Qt doesn't have a native encoder? i don't need mp4 , still can be avi or anything.
VLC is ffmpeg based.
Qt doesn't provide any codec, it uses whatever the platform makes available.
How can i make codec available to Qt?
Do i have to edit kits ? or environnement variable?
Make them available to Windows. Like I said, Qt backends implementation are platform specific, so you have to install the codecs you want on your system in order for Qt to be able to use them.
Thanks you! i'll try tonight. But if i deploy my software, do i have to install codecs on each computer using my software or does Qt include it during the deployment?
At the moment i am currently working with openCV for the video.
On the audio part, i noticed a problem using QAudioRecorder. when i try to change settings, it's always fail. maybe i have the same problem with QMediaRecorder.
Keep looking for a solution and i'll telle you if i find the solution. Thanks you for your help ;)
No, Qt won't install such stuff for you, it's up to you to either point the user to where he should get one or make it part of your installer.
What settings are you using ?
Hello, sorry i have been working during the end of years events so i did not work on my own project.
I have currently created a thread using Open CV in order to record video in .avi and i used the Qt's audiorecorder example to record sound. i juste changed it a little but it's fully functionnal.
Next step is to merge these two process and to syncronously record video and sound.
I will creat a last thread that will use ffmpeg to merge the two files.
happy new year everybody and i wish you a happy coding year !
Happy new year to you too :)
Finaly, i have finished and it is working!
To conclude :
I used the audio recorder example to record sound.
I used OpenCV to record video syncroniously
at the end of the recording, I used a QProcess in order to launch ffmpeg.
Linking it with some signals to a main process which handle all processes.
Well! Problem SOLVED. Thanks you all !
thippu last edited by
@ClementD , @SGaist ,Hi
This is thippu
I'm working on video recording project using Qt creator coding in c++
I'm new to it Plz help me how to record video and save the recorded video(with audio).
or if u have created project already provide link so that I can refer and use
It helps me lot !!
thank you in advance