Important: Please read the Qt Code of Conduct -

get camera frame on Android (PC is ok)

  • header file content:
    class FilterTestRunnable : public QVideoFilterRunnable
    FilterTest *m_filter;

    //void deleteColorComponentFromYUV(QVideoFrame *input);

    FilterTestRunnable(FilterTest *filter) : m_filter(filter) { }
    QVideoFrame run(QVideoFrame input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags);
    cpp file content:
    return new FilterTestRunnable(this);

    QVideoFrame FilterTestRunnable::run(QVideoFrame *input,
    const QVideoSurfaceFormat &surfaceFormat,
    QVideoFilterRunnable::RunFlags flags)
    if (!input->isValid())
    return *input;

    QAbstractVideoBuffer::MapMode mode = input->mapMode();
            qWarning() << "Is readable!";
    return *input;


    Always print "QVideoFrame::unmap() was called more times then QVideoFrame::map()"
    “input->isReadable()” is always false

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    IIRC, on Android the the QVideoFrame contains a texture. You should check the QAbstractVideoBuffer::HandleType of it.

  • @SGaist
    Thank you very much, I still don't quite understand what I should do, can you give me a simple example?

  • @SGaist
    did you mean like this:(This is someone else's code, I don't know what it does, and there is the usage of the handleType you mentioned.)
    QListQVideoFrame::PixelFormat supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
    return QListQVideoFrame::PixelFormat()
    << QVideoFrame::Format_ARGB32
    << QVideoFrame::Format_ARGB32_Premultiplied
    << QVideoFrame::Format_RGB32
    << QVideoFrame::Format_RGB24
    << QVideoFrame::Format_RGB565
    << QVideoFrame::Format_RGB555
    << QVideoFrame::Format_ARGB8565_Premultiplied
    << QVideoFrame::Format_BGRA32
    << QVideoFrame::Format_BGRA32_Premultiplied
    << QVideoFrame::Format_BGR32
    << QVideoFrame::Format_BGR24
    << QVideoFrame::Format_BGR565
    << QVideoFrame::Format_BGR555
    << QVideoFrame::Format_BGRA5658_Premultiplied
    << QVideoFrame::Format_AYUV444
    << QVideoFrame::Format_AYUV444_Premultiplied
    << QVideoFrame::Format_YUV444
    << QVideoFrame::Format_YUV420P
    << QVideoFrame::Format_YV12
    << QVideoFrame::Format_UYVY
    << QVideoFrame::Format_YUYV
    << QVideoFrame::Format_NV12
    << QVideoFrame::Format_NV21
    << QVideoFrame::Format_IMC1
    << QVideoFrame::Format_IMC2
    << QVideoFrame::Format_IMC3
    << QVideoFrame::Format_IMC4
    << QVideoFrame::Format_Y8
    << QVideoFrame::Format_Y16
    << QVideoFrame::Format_Jpeg
    << QVideoFrame::Format_CameraRaw
    << QVideoFrame::Format_AdobeDng;

  • Lifetime Qt Champion

    No, rather qDebug() << frame.handleType().

    In any case, you should take a look at this project which implements a QVideoFilterRunnable which handles video frame also on Android.

  • @SGaist
    thank you very much.
    it's ok. thanks.

  • @SGaist
    sorry I don't know how to change " UNSOLVED" to " SOLVED"

  • @SGaist
    Hi, in thant code,I want to know supportedViewfinderResolutions of camera,so the main.qml is:

    ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("My Video Filter")

    Camera {
        id: camera
        //viewfinder.resolution: "320x240"
        //viewfinder.resolution: "600x400"
    VideoOutput {
        id: videoOutput
        anchors.fill: parent
        autoOrientation: true
        source: camera
        filters: [ videoFilter ]
    MyVideoFilter {
        id: videoFilter
        orientation: videoOutput.orientation
        id: mousearea
        anchors.fill: parent
        onClicked: show_frame_rate()
    function show_frame_rate()
        //there is problem:
        /* print
        qml: QSize(-1, -1)
        qml: undefined


    I don't konw why , I can't get :
    print info:
    qml: QSize(-1, -1)
    qml: undefined
    is it possible to get those info in my filter:
    class MyVideoFilterRunnable : public QVideoFilterRunnable
    MyVideoFilterRunnable(MyVideoFilter* parent = nullptr);

    QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags) Q_DECL_OVERRIDE;
    QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags, QImage image);

    MyVideoFilter* m_Filter;
    int m_Orientation;
    int m_Flip;

  • Lifetime Qt Champion

    The backend might have some limitation there.

    Out of curiosity, what do you need these values for ?

  • @SGaist
    I know these resolutions and choose one of them I need.

Log in to reply