Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Record Sound and Video using QMediaRecorder
Forum Updated to NodeBB v4.3 + New Features

Record Sound and Video using QMediaRecorder

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 9.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ClementD
    wrote on last edited by
    #1

    Hello,

    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?

    mrjjM 1 Reply Last reply
    0
    • C ClementD

      Hello,

      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?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi

      • 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

      C 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi

        • 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

        C Offline
        C Offline
        ClementD
        wrote on last edited by
        #3

        @mrjj Thanks you i'll try tonight

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ClementD
          wrote on last edited by
          #4

          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();
          

          return:
          ()
          QMediaRecorder::StoppedState
          QMediaRecorder::NoError
          QUrl("")

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ClementD
              wrote on last edited by
              #6

              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();
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ClementD
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    One thing is: do you have an mp4 encoder on your machine ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • C Offline
                      C Offline
                      ClementD
                      wrote on last edited by
                      #10

                      @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.

                      1 Reply Last reply
                      1
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        VLC is ffmpeg based.

                        Qt doesn't provide any codec, it uses whatever the platform makes available.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • C Offline
                          C Offline
                          ClementD
                          wrote on last edited by
                          #12

                          How can i make codec available to Qt?
                          Do i have to edit kits ? or environnement variable?

                          1 Reply Last reply
                          1
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            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.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            2
                            • C Offline
                              C Offline
                              ClementD
                              wrote on last edited by
                              #14

                              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 ;)

                              1 Reply Last reply
                              1
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                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 ?

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                1
                                • C Offline
                                  C Offline
                                  ClementD
                                  wrote on last edited by
                                  #16

                                  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 !

                                  mrjjM 1 Reply Last reply
                                  0
                                  • C ClementD

                                    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 !

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @ClementD
                                    Happy new year to you too :)

                                    1 Reply Last reply
                                    0
                                    • C Offline
                                      C Offline
                                      ClementD
                                      wrote on last edited by
                                      #18

                                      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 !

                                      T 1 Reply Last reply
                                      3
                                      • C ClementD

                                        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 !

                                        T Offline
                                        T Offline
                                        thippu
                                        wrote on last edited by
                                        #19

                                        @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

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved