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

Error displaying video from the camera



  • Hi everyone !

    I am having an error displaying video from the camera (I use qt5.15, arm64-v8a.so, android-9 phone )

    W libuntitled_arm64-v8a.so: The video surface is not compatible with any format supported by the camera
    

    My code

       camera = new QCamera();
       viewfinder = new QCameraViewfinder();
       camera->setViewfinder(viewfinder);
       viewfinder->show();
       camera->start();
    

    thanks in advance !



  • @DQUY05 setViewfinder call sets a video surface as the viewfinder of a camera.
    camera & viewfinder are default constructed object. Which camera device do you want to open?

    You can use QCameraInfo to list available cameras and choose which one to use.

    const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    for (const QCameraInfo &cameraInfo : cameras) {
    if (cameraInfo.deviceName() == "mycamera")
    camera = new QCamera(cameraInfo);
    }



  • @nagesh said in Error displaying video from the camera:

    const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    for (const QCameraInfo &cameraInfo : cameras) {
    if (cameraInfo.deviceName() == "mycamera")
    camera = new QCamera(cameraInfo);
    }

    Thank you for your help !
    I tried as below, but still get the same error message : W libuntitled_arm64-v8a.so: The video surface is not compatible with any format supported by the camera

         const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
         for (const QCameraInfo &cameraInfo : cameras) {
             if (cameraInfo.deviceName() == "back")
             {
                 qDebug() <<"video start";
                 camera = new QCamera(cameraInfo);
                 viewfinder = new QCameraViewfinder();
                 viewfinder->showMaximized();
                 camera->setCaptureMode(QCamera::CaptureViewfinder);
                 camera->setViewfinder(viewfinder);
                 viewfinder->show();
                 camera->start();
                 qDebug() <<"video finish";
             }
         }
    

    I think the video format is not suitable for my phone, but I don't know how to convert it
    Regards !



  • @DQUY05 said in Error displaying video from the camera:

    The video surface is not compatible with any format supported by the camera

    There was some discussion regarding this topic.
    https://forum.qt.io/topic/93173/camera-access-in-android-device

    There is Camera example in Qt.

    you also need to check whether mode is supported before calling setCaptureMode using isCaptureModeSupported(QCamera::CaptureViewfinder)



  • @nagesh said in Error displaying video from the camera:

    @DQUY05 said in Error displaying video from the camera:

    The video surface is not compatible with any format supported by the camera

    There was some discussion regarding this topic.
    https://forum.qt.io/topic/93173/camera-access-in-android-device

    There is Camera example in Qt.

    you also need to check whether mode is supported before calling setCaptureMode using isCaptureModeSupported(QCamera::CaptureViewfinder)

    it has support (ui->inform->setText("with support");)

         const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
         for (const QCameraInfo &cameraInfo : cameras) {
             if (cameraInfo.deviceName() == "back")
             {
                 camera = new QCamera(cameraInfo);
                 if(camera->isCaptureModeSupported(QCamera::CaptureViewfinder))
                 {
                 ui->inform->setText("with support");
                 }
                 viewfinder = new QCameraViewfinder();
                 viewfinder->setMinimumSize( 50, 50 );
                 camera->setCaptureMode(QCamera::CaptureViewfinder);
                 camera->setViewfinder(viewfinder);
                 viewfinder->show();
                 camera->start();
             }
         }
    

    Can you show me how to use the QVideoFrame :: Format_NV21 converter?
    https://forum.qt.io/topic/93173/camera-access-in-android-device

    Many thanks!



  • @DQUY05 I never used Qmultimedia module..

    check in the below link qt docs..
    https://doc.qt.io/qt-5/android-platform-notes.html
    it says
    The Qt Multimedia Widgets module is not supported on Android, which means video display is only available using the Video QML Type.



  • @nagesh said in Error displaying video from the camera:

    @DQUY05 I never used Qmultimedia module..

    check in the below link qt docs..
    https://doc.qt.io/qt-5/android-platform-notes.html
    it says
    The Qt Multimedia Widgets module is not supported on Android, which means video display is only available using the Video QML Type.

    Thank you !

    I have never written in QML before, but I must try it



  • @nagesh said in Error displaying video from the camera:

    @DQUY05 I never used Qmultimedia module..

    check in the below link qt docs..
    https://doc.qt.io/qt-5/android-platform-notes.html
    it says
    The Qt Multimedia Widgets module is not supported on Android, which means video display is only available using the Video QML Type.

    Hi Mr.
    I tried with QML to get video from camera, rendering on QML is fine, but c ++ has connection but no output image in SLOT, i spend a lot of time but still no result

    .qml

        Camera
        {
            id: camera
            objectName: "set_camera"
    
            imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
    
            exposure
            {
                exposureCompensation: -1.0
                exposureMode: Camera.ExposurePortrait
            }
    
            focus
            {
                focusMode: Camera.FocusContinuous
                focusPointMode: Camera.FocusPointCenter
            }
    
            flash.mode: Camera.FlashRedEyeReduction  // giảm hiệu ứng mắt đỏ flash
    
            imageCapture
            {
                onImageCaptured:
                {
                    photoPreview.source = preview  // Show the preview in an Image
                }
            }
    
        }
    
        VideoOutput
        {
            orientation: 270  // xoay khung camera
            source: camera
            anchors.fill: parent
            focus : false // to receive focus and capture key events when visible
        }
    

    .cpp

        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/motlan.qml")));
    
        QObject *qmlCamera = engine.rootObjects().at(0)->findChild<QObject*>("set_camera");
        ui->inform->setText(qmlCamera->objectName());  // I test show is fine !
        QCamera *camera1 = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));   
    
        probe_.setSource(camera1);
        connect(&probe_,SIGNAL(videoFrameProbed(const QVideoFrame &)),
                        this, SLOT(present(const QVideoFrame &)));
    

    Thanks !


  • Lifetime Qt Champion

    Hi,

    What do you mean by "no output image in slot" ?



  • @SGaist said in Error displaying video from the camera:

    Hi,

    What do you mean by "no output image in slot" ?

    Yes, I mean I don't get a signal or signal that is not in QVideoFrame format, or when I switch to Widget environment, qml is disabled when win.show():

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow win;
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/motlan.qml")));
    
        QTest::qWait(5000);
    
        win.show();
        return a.exec();
    }
    

    Many thanks!


  • Lifetime Qt Champion

    It looks like you are trying to do some strange mix.

    What is your exact goal with your application ?



  • @SGaist said in Error displaying video from the camera:

    It looks like you are trying to do some strange mix.

    What is your exact goal with your application ?

    My aim is to get video from camera using Qml, then pass real-time VideoFrame into Ui :: MainWindow widget, (because I tried a lot of different ways to get Video Camera on Ui :: MainWindow widget but failed)
    To me this is very important, I am stuck !

    Thanks!


  • Lifetime Qt Champion

    If you use a QQuickWidget properly you'll have your QtQuick interface show in your QMainWindow.


Log in to reply