PDA

View Full Version : QMediaRecorder recording QMediaPlayer Video Problems



Avan
11th May 2017, 04:13
Hi, I am new here. I am trying to record a local video file that is played by a QMediaPlayer. But it seems that the QMediaRecorder is not recording the video that is being played.

Basically I have a video player that is playing that the video will start recording whenever the user click on the record button.
Below is the code snippet for my recording function.



void VideoPlayer::record()
{
if (!isRecording)
{

videoRecorder = new QMediaRecorder(&mediaPlayer);
videoRecorder->setOutputLocation(QUrl::fromLocalFile(QCoreApplica tion::applicationDirPath() + "/" + "testRecord.mp4"));
videoRecorder->record();
isRecording = true;
}
else
{
videoRecorder->stop();
}
}


I try debugging and these are the values I got from QMediaRecorder.

QMediaPlayer state is playing state during recording.
QMediaRecorder status = UnavailableStatus
QMediaRecorder state = StoppedState
QMediaRecorder error = NoError

What am I doing wrong? This has been bugging me for days and I really need help.
I am begging on my knees.

d_stranz
11th May 2017, 18:23
For one thing, your code creates a new QMediaRecorder instance each time you click the record button and isRecording is false. Each of these instances gets attached to the same media player. In the code you posted, these videoRecorder instances are never destroyed.

You should probably create a single instance of videoRecorder when the media player is created and simply start and stop that instance in the record slot.

If you are running this program in Windows 7 or 10, be sure you actually have permission to create files in your output directory. You don't have any error checking to see if the call to setOutputLocation() actually succeeded. You also aren't connecting any slots to the signals emitted by QMediaRecorder (statusChanged(), error()), so you have no way of determing what the state of the recorder is.

Simply assuming that every call works without checking any of the return values gets you to the situation you're in now - it isn't working and you have no idea why.