androidqtqmlandroid-cameraqtmultimedia

Qt/QML Android: Camera was detected but ImageCapture send "Camera is not ready." error


I have bellow codes, the Camera in Qt/QML android app detected correctly but ImageCapture send "Camera is not ready." error.

import QtQuick
import QtQuick.Controls
import QtMultimedia



/*! ***********************************************************************************************
 * The CameraController's task involves periodically refreshing CameraDevice frames through a
 * CaptureSession within a specified time interval.
 *
 * ************************************************************************************************/
Item {
    id: cameraController

    /* Property Declarations
     * ****************************************************************************************/
    //! Media devices
    property MediaDevices mediaDevices: null

    //! Camera Device
    property ICamera cameraDev: null

    /* Children
     * ****************************************************************************************/
    // Timer to capture frames as fast as possible
    Timer {
        id: timer
        running: cameraDev.enable
        interval: 1000.0 / 24.0
        repeat: true
        onTriggered: {
            if (imageCapture.readyForCapture)
                imageCapture.capture();
        }
    }

    // Frame handler
    CaptureSession {
        id: captureSession

        // camera
        camera: Camera {
            id: mycameraDevice
            active: true
            
            cameraDevice: cameraDev.index >= 0 ? mediaDevices.videoInputs[cameraDev.index] : null

            onErrorOccurred: (error, errorString) => {
                                 console.log("Camera name", cameraDev.name,
                                             "Camera error:", errorString)
                             }
        }

        // image capture
        imageCapture: ImageCapture {
            id: imageCapture

            onImageCaptured: (requestId, previewImage) => {
                                 cameraDev.currentFrame = previewImage
                             }

            onErrorOccurred: (id, err, errstr) => {
                                 console.log("errstr :  ", id, err, errstr) // Camera is not ready.
                             }
        }
    }
}

I need to capture frames from camera in QML. Thanks


Solution

  • I'm currently using Qt version 6.5.2, and it's functioning as expected. This version of Qt utilizes FFmpeg for multimedia operations.