Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to change format of output video file in videoRecorder?



  • Hi. Is it possible to record video from camera to a specified format like "mkv" or "avi"?
    By default videoRecorder uses "ogg" and chagings of settings doesn't any effect.
    For example:

    videoRecorder {
    ...
    videoCodec: "h264"
    mediaContainer: "mkv"
    outputLocation: "/home/user/record.mkv"
    ...
    }
    

    will write file "/home/user/record.mkv.ogg"

    What I'm doing wrong?

    Thanks!



  • @r3d9u11 checking documentation for CameraRecorder QML Type says:

    CameraRecorder allows recording camera streams to files, and adjusting recording settings and metadata for videos.

    It should not be constructed separately, instead the videoRecorder property of a Camera should be used.

    See the example snippet shown there...



  • @pablo-j-rogina I'm sorry for my incomplete example
    Sure, I defined videoRecorder inside the Camera object:

    Camera {
        id: camera
        deviceId: QtMultimedia.availableCameras[0].deviceId
        captureMode: Camera.CaptureVideo
    
        onError: {
            if (Camera.NoError !== error) {
                console.log("[qmlvideo] CameraItem.onError error " + error + " errorString " + errorString)
            }
        }
    
        videoRecorder {
            muted: true
            videoCodec: "h264"
            mediaContainer: "mp4"
            videoRecorder.outputLocation: "/home/user/Desktop/record-1.mp4"
            
            onRecorderStateChanged: {
                if (camera.videoRecorder.recorderState == CameraRecorder.RecordingState) {
                    console.log("recording to: " + camera.videoRecorder.outputLocation)
                }
                else if (camera.videoRecorder.recorderState == CameraRecorder.StoppedState) {
                    console.log("saved to: " + camera.videoRecorder.outputLocation)
                }
            }
        }
    }
    

    I changed it:

    Camera {
        id: camera
        deviceId: QtMultimedia.availableCameras[0].deviceId
        captureMode: Camera.CaptureVideo
    
        onError: {
            if (Camera.NoError !== error) {
                console.log("[qmlvideo] CameraItem.onError error " + error + " errorString " + errorString)
            }
        }
    
        videoRecorder.muted: true
        videoRecorder.videoCodec: "h264"
        videoRecorder.mediaContainer: "mp4"
        videoRecorder.outputLocation: "/home/user/Desktop/record-1.mp4"
        
        videoRecorder.onRecorderStateChanged: {
            if (camera.videoRecorder.recorderState == CameraRecorder.RecordingState) {
                console.log("recording to: " + camera.videoRecorder.outputLocation)
            }
            else if (camera.videoRecorder.recorderState == CameraRecorder.StoppedState) {
                console.log("saved to: " + camera.videoRecorder.outputLocation)
            }
        }
    }
    

    And nothing changed, still .ogg files in output.
    Both samples will write file /home/user/Desktop/record-1.mp4.ogg

    Same situation with any other extensions (e.g. mkv).
    Also same situation with image capturing (recorder will write images to *.ogg files, too).

    I'm on Qt 5.9.8


  • Lifetime Qt Champion

    Hi,

    Might be a silly question but do you have a matroska codec available for your system ?



  • @sgaist Yes, I think. I can watch mkv files via VLC without any troubles, for example.


  • Lifetime Qt Champion

    The fact that VLC can play the file has no role here. VLC doesn't use the system backend. However, QtMultimedia uses the system backend hence my question about having a codec on your system.



  • @r3d9u11 you need to check :

    1. supportedVideoCodecs
    2. supportedContainers

    according that set your QVideoEncoderSettings for mediarecorder


Log in to reply