Important: Please read the Qt Code of Conduct -

[SOLVED]Can't set output location for QMediaRecorder

  • Hi everybody!

    I am trying to save video from my camera into the file but I can't set the output location. The method SetOutputLocation always returns FALSE.
    Bellow is the code:

    QCamera * camera;
    QMediaRecorder * rec;

    QApplication app(argc, argv);
    camera = new QCamera;
    rec = new QMediaRecorder(camera);
    QString file = "D:\\qt\\test\\test.avi";
    QFile file1(file);;


    What should I do to fix this problem?

    Thanks in advance.


    [edit: please add @ tags around your code for better readability, Eddy]

  • I Quickly tested your code on mac, and it works..

    I guess i has something todo with the filePath

    can your try:

    @QString file = QCoreApplication::applicationDirPath() + "/testings.avi";@

  • I tried as you wrote. No change.

  • I checked:


    and it returned False.

    Could it be the reason? I use simple web camera. Are these methods camera dependent?

    And if the camera is the reason, what kind of camera should I have to have in order to do this?

  • i tested your code on Mac, and it worked out of the box with my build in camera...

    What platform do you use ?

  • Windows XP 2002, SP3.

  • Did you compile directshow plugin ?

  • No, I didn't. I installed QtCreator and that's all. Where can I get this plugin and what should I do to compile it?

  • Beacuse I couldn't make it work with QCamera and QMediaRecorder, I installed OpenCV. I typed the code:

    #include "opencv2/highgui/highgui.hpp"
    #include <iostream>

    using namespace cv;
    using namespace std;

    int main(int argc, char* argv[])
    VideoCapture cap("clock.avi"); // open the video file for reading
    if ( !cap.isOpened() ) // if not success, exit program
    cout << "Cannot open the video file: " << endl;
    return -1;


    And the story is the same: "Cannot open the video file".

    I tried this on 2 different computers (win7, xp) and the result is the same. I installed on both computers the same QT creator.

    Maybe is something wrong with my installation of the QT. Some rights, pathes, environment variables, ...

    Any ideas?

    [edit: added coding tags "@" SGaist]

  • Hi!

    I think I found the reason why it doesn't work: codecs. Some files I can read (CRAM codec), most of them I don't. And these things work better with opencv than with QMediaRecorder. So, I need more knowledge on codecs. If anyone knows where to get a good tutorial on using video codecs I would be very grateful.
    stevenceuppens:: Thank you for your help.


Log in to reply