Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT video playback in Linux
Qt 6.11 is out! See what's new in the release blog

QT video playback in Linux

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 878 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Nilsson
    wrote on last edited by
    #1

    Hi, I am trying to get QT video playback, preferrably through HW-offload and GL rendering on Ubuntu 16.04. The long-term goal is then to get this also running under Yocto on the i.mx6 platform.

    I am trying using Qt 5.7 on my Linux host, but will need to run under QT 5.5 on the i.mx6 target.

    My code is as follows:

    main.cc:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QCommandLineParser>
    #include <QCommandLineOption>
    #include <QtQml>
    #include <QtGui>
    
    
    #define PROJECT_NAME "simpleVideoPlayer"
    #define PROJECT_VERSION "0.1.0"
    
    int main(int argc, char *argv[])
    {
        int q = 1;
    
        QGuiApplication app(argc, argv);
    
        // Print application banner.
        qDebug();
        qDebug() << "Starting" << PROJECT_NAME << " version " << PROJECT_VERSION
                 << " - using Qt library " << qVersion();
    
        QCommandLineParser parser;
        parser.setApplicationDescription("qtsignage");
        QGuiApplication::setApplicationVersion(PROJECT_VERSION);
    
        parser.addHelpOption();
        parser.addVersionOption();
    
        QCommandLineOption fileNameOption(QStringList() << "filename",
                    QCoreApplication::translate("main", "Video to play"), "videoname");
        parser.addOption(fileNameOption);
    
        QCommandLineOption videoSinkOption(QStringList() << "videosink",
                    QCoreApplication::translate("main", "Force to use this video sink"), "videosink");
        parser.addOption(videoSinkOption);
    
        parser.process(app);
    
        // Set GST_ properties
        QString videoSinkString = parser.value(videoSinkOption);
        if (!videoSinkString.isEmpty())
        {
            qDebug() << "Setting videosink to " << videoSinkString;
            qputenv("QT_GSTREAMER_WINDOW_VIDEOSINK", videoSinkString.toUtf8());
        }
    
        QString fileNameString = parser.value(fileNameOption);
        if (fileNameString.isEmpty())
        {
            qWarning() << "Mandatory video name not set, exit!";
            exit(1);
        }
    
        QQmlApplicationEngine engine;
        engine.rootContext()->setContextProperty("fileName", fileNameString);
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        return app.exec();
    }
    

    main.qml:

    import QtQuick 2.5
    import QtQuick.Window 2.2
    import QtMultimedia 5.6
    
    Window {
    //Rectangle {
        visible: true
        width:  Screen.width
        height: Screen.height
        color: "red"
    
        Video
        {
            id: mplayer
            autoPlay: true
            anchors.fill: parent
    //        source: "file://" + fileName
            source: "/home/greta/simpleVideoPlayer/20161114_123724.mp4"
        }
    }
    

    .pro:

    TEMPLATE = app
    
    QT += qml quick multimedia multimediawidgets widgets gui core
    CONFIG += c++11 qml_debug
    
    SOURCES += main.cc
    
    RESOURCES += qml.qrc
    
    INCLUDEPATH = "/usr/include/x86_64-linux-gnu/qt5/QtQml/"
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    

    My result is that I get a red fullscreen window that doesnt play anything. Playing video, recording from camera, HW-offload all work on the command line using gstreamer directly.

    I am lost as what to do from here. Any suggestions appreciated.

    /Daniel

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved