Reputation: 71
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.
Upvotes: 7
Views: 10954
Reputation: 39
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))
Add it to the cmake project list by including the following lines
find_package(Qt6 6.2 COMPONENTS Multimedia REQUIRED)
Also update the target_link_libraries
target_link_libraries(yourprojectname, PRIVATE Qt6::Multimedia)
Also set autorcc on
set(CMAKE_AUTORCC ON)
Save your cmake file
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();
}
}
}
Upvotes: 0
Reputation: 5468
I faced the same problem on Arch and Debian. After installing the following packages, everything works fine.
ARCH:
Installed with yay
:
yay -S gstreamer gstreamer0.10 gst-plugins-base-libs gst-plugins-good gst-libav qt5-tools
Debian:
Installed with apt
:
apt install libqt5multimedia5-plugins
Upvotes: 1
Reputation: 31
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
Upvotes: 3
Reputation: 51
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.
Upvotes: 5
Reputation: 9681
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.
Upvotes: 1