Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [MediaRecorder] Name the recorded video and set the path to save the recorded video.
Forum Updated to NodeBB v4.3 + New Features

[MediaRecorder] Name the recorded video and set the path to save the recorded video.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 501 Views 2 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.
  • T Offline
    T Offline
    TamLe
    wrote on last edited by
    #1

    I'm new to QT.

    I'm writing an application that shows the camera to qml and records the video at the same time.

    I've been able to display the camera image and record it. However, I don't know how to set the name for the recorded video and the path to save the recording.

    I read that there is an outputLocation to use: however, when I enter the path, it takes the path name as the video name.

    I use:
    OS: win 10
    version: QT6.4.3

    Below is my source code:

    import QtQuick 6.2
    import QtMultimedia
    import recordcamera
     
    Window {
        width: 800
        height: 600
     
        visible: false
        title: "recordcamera"
     
        MediaDevices {
                id: mediaDevices
            }
     
        Component.onCompleted: {
            recorder.record();
        }
     
        Component.onDestruction: {
            recorder.stop();
        }
     
        CaptureSession {
            id: captureSession
            camera: Camera {
                id: camera
                cameraDevice: mediaDevices.defaultVideoInput
                focusMode: Camera.FocusModeAutoNear
                active: true
                onErrorOccurred: (error,errorString)=> {
                                                console.log( "camera");
                                                console.log(errorString);
                                                console.log(error);
                                             }
            }
            audioInput: AudioInput {}
            recorder: MediaRecorder {
                id: recorder
                onErrorOccurred: (error,errorString)=> {
                                                console.log( "recorder");
                                                console.log(errorString);
                                                console.log(error);
                                             }
                quality: MediaRecorder.NormalQuality
                outputLocation: "D:\\QT_map\\recordcamera\\build\\Desktop_Qt_6_6_3_MSVC2019_64bit-Release\\test.mp4"
            }
            videoOutput: videoOutput
        }
     
        VideoOutput {
                id: videoOutput
                anchors.fill: parent
                fillMode: Image.Stretch
            }
    }
    

    Please help me with this problem.
    Thanks!

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

      Use QUrl::fromLocalFile when building URLs from file path.

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

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

        Hi,

        Since the parameter is a URL, I think you are missing the file:// protocol before the file path.

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

        T 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Since the parameter is a URL, I think you are missing the file:// protocol before the file path.

          T Offline
          T Offline
          TamLe
          wrote on last edited by TamLe
          #3

          @SGaist Thank you! I tried and it worked.

          but i want to ask one more thing? when i pass a QUrl from c++ to QML. i don't know how to handle it?

          property string outputFile: ""
          Component.onCompleted: {
                  outputFile = obj.location_file;
                  recorder.record();
              }
          
          CaptureSession {
                  id: captureSession
                  camera: Camera {
                      id: camera
                      cameraDevice: mediaDevices.defaultVideoInput
                      focusMode: Camera.FocusModeAutoNear
                      active: true
                      onErrorOccurred: (error,errorString)=> {
                                                      console.log( "camera");
                                                      console.log(errorString);
                                                      console.log(error);
                                                   }
                  }
                  audioInput: AudioInput {}
                  recorder: MediaRecorder {
                      id: recorder
                      onErrorOccurred: (error,errorString)=> {
                                                      console.log( "recorder");
                                                      console.log(errorString);
                                                      console.log(error);
                                                   }
                      quality: MediaRecorder.NormalQuality
                      outputLocation: outputFile
                  }
                  videoOutput: videoOutput
              }
          

          but I got an error code: 4 (Output location not writable), even though i tried QT.url(outputFile) still got the same error.
          I also wrote as below but still got the error message as above:

          Component.onCompleted: {
                  recorder.outputLocation = obj.location_file;
                  recorder.record();
              }
          
          1 Reply Last reply
          0
          • T Offline
            T Offline
            TamLe
            wrote on last edited by
            #4

            I think this is a bug or not? when I use the above code in QT6.6.3 version, it has no problem.

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

              How do you create the QUrl object in C++ ?

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

              T 1 Reply Last reply
              0
              • SGaistS SGaist

                How do you create the QUrl object in C++ ?

                T Offline
                T Offline
                TamLe
                wrote on last edited by TamLe
                #6

                @SGaist, thanks for the feedback.
                Here is my code.

                QString name_record = QString("%1_%2.mp4")
                                  .arg(recordName)
                                  .arg(QDateTime::currentMSecsSinceEpoch());
                    location_file = QUrl(QDir::currentPath()+"/"+name_record);
                

                When I apply this code in QT6.6.3, it still works normally. But in QT6.4.3, it has the above error.

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

                  Use QUrl::fromLocalFile when building URLs from file path.

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

                  T 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Use QUrl::fromLocalFile when building URLs from file path.

                    T Offline
                    T Offline
                    TamLe
                    wrote on last edited by
                    #8

                    @SGaist
                    I see. Thank you very much.

                    1 Reply Last reply
                    0
                    • T TamLe has marked this topic as solved on

                    • Login

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