Search code examples
qt6video-recording

QT6: Name the recorded video and set the path to save the recorded video by MediaRecorder


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: win 10 and QT6.4.3

Below is my source code: App.qml

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:\\recordcamera\\build\\Desktop_Qt_6_6_3_MSVC2019_64bit-Release\\test.mp4"
        }
        videoOutput: videoOutput
    }
 
    VideoOutput {
            id: videoOutput
            anchors.fill: parent
            fillMode: Image.Stretch
        }
}

Solution

  • I'm sorry to bother you.

    I used the wrong outputLocation.

    Wrong:

    outputLocation: "D:\recordcamera\build\Desktop_Qt_6_6_3_MSVC2019_64bit-Release\test.mp4"

    Correct

    outputLocation: "file:\\D:\recordcamera\build\Desktop_Qt_6_6_3_MSVC2019_64bit-Release\test.mp4"