[MediaRecorder] Name the recorded video and set the path to save the recorded video.
-
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.3Below 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! -
Use QUrl::fromLocalFile when building URLs from file path.
-
Hi,
Since the parameter is a URL, I think you are missing the
file://
protocol before the file path. -
Hi,
Since the parameter is a URL, I think you are missing the
file://
protocol before the file path.@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(); }
-
How do you create the QUrl object in C++ ?
-
@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.
-
Use QUrl::fromLocalFile when building URLs from file path.
-
Use QUrl::fromLocalFile when building URLs from file path.
-