Unable to play video in QML

Viewed 7698

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.

6 Answers

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

Add QT+= multimedia to your .pro file.

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 

Since qt6 prefers cmake instead of qmake so in case you want to add multimedia files to your cmake list you could perfrom the steps given below (the solution below worked on a mac (apple silicon))

  1. First download the multimedia package from the qt maintenance tool (QtMultimedia) enter image description here
  1. Add it to the cmake project list by including the following lines

     find_package(Qt6 6.2 COMPONENTS Multimedia REQUIRED)
    
  2. Also update the target_link_libraries

     target_link_libraries(yourprojectname, PRIVATE Qt6::Multimedia)
    
  3. Also set autorcc on

     set(CMAKE_AUTORCC ON)
    
  4. Save your cmake file

  5. Regarding the qml file the following code worked for me without errors

     import QtQuick
     import QtQuick.Controls
     import QtMultimedia
    
     ApplicationWindow
     {
         width:640
         height: 480
         visible : true
         title: "audio player"
         MediaPlayer {
             id: player 
             source : "give your path to source file "
             audioOutput: AudioOutput{}
    
         Component.onCompleted:{
             player.play();
         }
        }
       }
    
Related