QT video playback in Linux
-
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:
#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