Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to play video in QML

Tags:

qt

qml

I am working on ubuntu 14.04 with Qt 5.8 and trying to play video in my application using Qt multimedia module. I put "QT += quick multimedia" in ".pro".

ContentVideo.qml

import QtQuick 2.1
import QtMultimedia 5.0

Rectangle {
    width: 400
    height: 400
    color:"black"

    MediaPlayer {
        id: mediaPlayer
        autoPlay: true
        autoLoad: true
        source:"/home/macos/Desktop/FroggerHighway.mp4"
    }

    VideoOutput {
        id:videoOutput
        source:mediaPlayer
        anchors.fill: parent
    }
}

main.qml

import QtQuick 2.1
import QtQuick.Window 2.1

Window {
    id: root
    color: "black"
    width: 400
    height: 400
    visible: true
    ContentVideo {
        anchors.fill: parent
    }
}

My video is not running and I am getting black screen without any error. QT QML EXAMPLES video is working on my PC. Any help will appreciated, Thank you.

like image 652
Soukaina Ouad Avatar asked May 18 '17 10:05

Soukaina Ouad


5 Answers

MediaPlayer.source is a URI and I don't think the value you are specifying is a valid URI. Try adding "file://" in front of the path the the mp4 file.

like image 69
Takeshi Kanemoto Avatar answered Oct 16 '22 11:10

Takeshi Kanemoto


I had just met the same issue as yours, it seems that QtMultimedia will looking for decoders from gstreamer in system at run time, so I install video codec package:

sudo apt-get install gstreamer1.0-libav gstreamer1.0-vaapi

Then qml video player works correctly now

like image 26
id9502 Avatar answered Oct 16 '22 10:10

id9502


If the QML video examples work without any issues it's probably a problem that comes from the lack of codecs to encode your video. Check if you have all the Multimedia Dependencies. My guess is that the provided video samples are encoded in a open format the support for which is provided by default by your distro.

like image 20
rbaleksandar Avatar answered Oct 16 '22 09:10

rbaleksandar


Add QT+= multimedia to your .pro file.

like image 21
Vineesh TP Avatar answered Oct 16 '22 11:10

Vineesh TP


I faced the same problem on Arch and Debian. After installing the following packages, everything works fine.

ARCH:

  • extra/gstreamer
  • aur/gstreamer0.10
  • extra/gst-plugins-base-libs
  • extra/gst-plugins-good
  • extra/gst-libav
  • extra/qt5-tools

Installed with yay:

yay -S gstreamer gstreamer0.10 gst-plugins-base-libs gst-plugins-good gst-libav qt5-tools

Debian:

  • libqt5multimedia5-plugins
  • gstreamer1.0-plugins-good
  • gstreamer1.0-libav
  • libqt5multimediagsttools5

Installed with apt:

apt install libqt5multimedia5-plugins 
like image 23
Manuel Schmitzberger Avatar answered Oct 16 '22 11:10

Manuel Schmitzberger