Unable to play video in QML - qt

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.

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.

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

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.

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))
First download the multimedia package from the qt maintenance tool (QtMultimedia)
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();
}
}
}

Related

Mock a module using qmltestrunner ? Is it possible?

I am running some QML Unit tests and they being tested using "qmltestrunner" However, I am stuck on something that I am not sure it is possible to mock it.
Here a snipped on my "TitleBusyIndicator.qml":
import QtQuick.Layouts
import QtQuick.Controls.Material
import GUI.PageNavigatorPT 1.0
Rectangle
{
width: parent.width
height: parent.height
... a bunch of stuff
here is part of my unit test that will test the QML above
import QtQuick
import QtQuick.Controls
import QtTest
Rectangle
{
TitleBusyIndicator
{
id : titleBusyIndicatorId
}
However the import below is not known to the QMLTestRunner because it does not have the full project. It just testing one single qml file.
import GUI.PageNavigatorPT 1.0
When I try to run the unittest I get this (expected):
Running test = %QMLTESTRUNNER%\qmltestrunner -input tst_TitleBusyIndicator.qml
********* Start testing of qmltestrunner *********
Config: Using QtTest library 6.3.1, Qt 6.3.1 (x86_64-little_endian-llp64 shared (dynamic) release build; by GCC 11.2.0), windows 10
QWARN : qmltestrunner::tst_TitleBusyIndicator::compile()
tst_TitleBusyIndicator.qml produced 2 error(s):
tst_TitleBusyIndicator.qml:18,5: Type TitleBusyIndicator unavailable
TitleBusyIndicator.qml:21,1: module "GUI.PageNavigatorPT" is not installed
Is there a way to make qmltestrunner ignore the module or mock it? I could not find much documention on how to mock modules inside qml files for qml runner.
thank you.
Since you're using Qt6.3.1 you should consult https://doc.qt.io/qt-6/qtqml-syntax-imports.html specifically the section on QML Import Path in particular the section regarding setting the QML_IMPORT_PATH environment variable.
In short, you should consider setting QML_IMPORT_PATH prior to running qmltestrunner. This allows you to nominate additional Qt QML plugins that may not be part of the standard Qt install.
You can use QML_IMPORT_PATH to point to production, QA, dev, or even stub versions of your Qt QML Plugin.
If those plugins have additional dependencies, you may need to also append those to the PATH environment variable so that the qmltestrunner can find those as well.
For completeness, for those who are on older Qt5.15.x or older, the environment variable is QML2_IMPORT_PATH. For more details, see https://doc.qt.io/qt-5/qtqml-syntax-imports.html

QT6 QTMultimedia FFMPEG backend preview procedure

I'm needing to display RTSP footage through a QML application. I have code written for this that works perfectly on Linux, simply because QT ships with a gstreamer backend on linux straight out of the box. On Windows this is a different story. Windows comes with "Windows Media Foundation" which doesn't support hardly any formats/codecs, much less an rtsp stream.
QT says with the release of QT6.4 they added an FFMPEG backend as a preview(https://doc-snapshots.qt.io/qt6-6.4/qtmultimedia-index.html). Some people on articles claim theyve gotten a working version by compiling QT with ffmpeg(https://forum.qt.io/topic/140524/use-ffmpeg-with-qt6-4/16). Everyone fails to produce steps and detailed information. I'm needing some help getting my QT6.4 installation to work with a ffmpeg backend. Also I've tried it with the mentioned environment variable as well.
If we can solve this here, we would be benefiting TONS of people. I can't tell you how many people have been posting about this.
Here's the quote from QT:
"Target platform and backend notes
On most platforms, there are two different backends that can be used for Qt Multimedia.
The first one is the backend built on the native multimedia framework of the underlying >operating system. This is currently the default, and will use gstreamer on Linux, >AVFoundation on macOS/iOS, WMF on Windows, and the MediaCodec framework on Android.
While we try to support our full API on all backends using the native multimedia framework, >platform specific limitations do exist in a few places. This is due to the fact that the >feature set supported by those frameworks varies, implying that some functionality might >not be available on all platforms. This is especially true for the set of supported file >formats and codecs, as well as advanced camera functionality.
Where limitations exist, we aim to document those in the respective classes and methods.
With Qt 6.4, we are adding a new, more platform independent backend based on the FFmpeg >framework. The FFmpeg backend is currently available as a technology preview. This backend >has the advantage that we can offer proper cross-platform support for all features of Qt >Multimedia, going beyond the limitations that exist with many of the native frameworks.
You can test the FFmpeg backend right now by using a Qt build that has FFmpeg enabled and >setting the QT_MEDIA_BACKEND environment variable to ffmpeg:
export QT_MEDIA_BACKEND=ffmpeg"
And here's my WORKING code on Linux:
import QtQuick
import QtMultimedia
import QtQml
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
color: "#000000"
Video {
id: stream
anchors.fill: parent
focus: true
source: "MY URL"
opacity: 1.0
fillMode: Image.Stretch
muted: true
Timer {
interval: 300000; running: true; repeat: true
onTriggered: {
console.log("Log: Refresh")
stream.stop()
stream.source="MY URL"
stream.play()
}
}
onErrorChanged: {
console.log("VIDEO ERROR")
stream.stop()
stream.source="MY URL"
stream.play()
}
Text {
id: text1
width: 73
height: 18
color: "#ffffff"
text: qsTr("Audio: False")
anchors.left: parent.left
anchors.top: parent.top
font.pixelSize: 15
anchors.leftMargin: 0
anchors.topMargin: 0
}
Keys.onPressed: (event)=> {
if(event.key === Qt.Key_M) {
stream.play()
if(text1.text === "Audio: True") {
text1.text = "Audio: False"
stream.muted = true
} else if (text1.text === "Audio: False") {
text1.text = "Audio: True"
stream.muted = false
}
}
}
}
// Component.onCompleted: {
// stream.play()
// }
}
Qt introduced the ffmpeg backend in 6.4; in 6.4 the ffmpeg backend is available in most binary builds, but it should be switched on by setting the environment variable QT_MEDIA_BACKEND=ffmpeg.
So in your case set it from the console or in main.cpp before qt initialization, e.g. setenv("QT_MEDIA_BACKEND", "ffmpeg")
Note, in 6.5, from beta 2, qt makes the ffmpeg backend default, native backends are optionally available. Aslo, in 6.5 the ffmpeg backend becomes more stable, so it's better to use it if possible.
If you want to compile qt with ffmpeg by yourself, you should install or compile ffmpeg by yourself. E.g., t makes sense to use qt provisioning build scripts: coin/provisioning/%os%/90-install-ffmpeg.sh
After that ffmpeg path should be provided to qt's configuration:
configure -submodules qtmultimedia -- -DFFMPEG_DIR=%ffmpegpath%
Config result is expected to contain:
FFmpeg ............................... yes

Installing QML modules on Fedora

I am trying to implement a simple map view in a PySide6 Qt project by linking a QML file.
import QtQuick 2.0
import QtQuick.Window 2.14
import QtLocation 5.6
import QtPositioning 5.6
Item {
width: Qt.platform.os == "android" ? Screen.width : 512
height: Qt.platform.os == "android" ? Screen.height : 512
visible: true
Plugin {
id: mapPlugin
name: "osm"
}
Map {
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(59.91, 10.75) // Oslo
zoomLevel: 14
}
}
To which Qt Creator or the main program starting the widget answer that the QtLocation and QtPositioning modules are not installed.
I'm on Fedora 35 KDE and there is indeed nothing in the repositories providing qml-modules-location, and the only modules available seem to be part of the KDE desktop. I installed PySide6 through pip3.
I tried to install Qt from the .run file on their website. I picked the "Additional libraries" that sounded close to it (datavisualization, charts, etc.) and the Qt studio. It downloaded some 9 GB of bloat and I still don't have the modules after.
How can I fetch those modules and where should I put them on my OS ? Preferably in a way that doesn't involve downloading another 10 GB because I don't have an unlimited data plan. It feels like it should just be grabbing some header files from a git repo and yet it's a turducken of unwanted libs, and everything on Qt Linux points to Ubuntu installations with apt-get.

qt webview shows no https site

I have a device with linux and I build the system with yocto. I use Qt as a webbrowser and it works for http sites. But when I want to show a https site I got a blank white site. It shows no error messages and also openssl is built and linked (otherwise i would get error messages?!). The folling code shows how i call the WebEngineView in a shell file.
import QtQuick 2.0
import QtQuick.Window 2.2
import QtWebEngine 1.2
Window {
width: 720
height: 1280
visible: true
WebEngineView {
anchors.fill: parent
url: "https://wiki.selfhtml.org/"
}
}
Does somebody knows any tipp?

QML QtGraphicalEffect are not rendered in target machine

I wrote a minimal example that display an Image and a DropShadow:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0
Window {
visible: true
color: "black"
Image {
id: imgBackground
source: "file:///path-to-background.png"
Image {
id: imgSpinner
source: "file:///path-to-spinner.png"
x: imgBackground.width / 2 - imgSpinUp.width / 2
y: 260
visible: false
antialiasing: true
}
DropShadow {
id: sdwSpinner
anchors.fill: imgSpinner
horizontalOffset: 8
verticalOffset: 8
radius: 4.0
samples: 17
color: "#AA000000"
source: imgSpinner
}
}
}
In the development machine all works fine: I see the image with its shadow as expected. Now I want to deploy it on a target computer.
To find the needed file I created a virtual machine with a fresh install of the operating system and tried to run my application. Works as expected, fine!
Eventually, I deployed the same file to my customer machine... here the DropShadow is not rendered! If I set the visible property of the image I can see it (i.e. the paths are ok). Hence are the QtGraphicalEffects that don't work.
All the three machines (development, virtual machine, customer's computer) run the same o.s.: Windows 7 Home Premium 64-bit.
The Qt version is 5.9 MinGW.
Here the files I deployed:
imageformats/
images/
platforms/
QtGraphicalEffect/
QtQml/
QtQuick/
QtQuick.2/
libgcc_s_dw2-1.dll
libstdc++-6.dll
libwinpthread-1.dll
opengl32sw.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Network.dll
Qt5Qml.dll
Qt5Quick.dll
myapplication.exe
The development / virtual machine video card is a GeForce GTX 670, the customer one is an Intel GMA 4500.
What could prevent the rendering of such an item?
It sounds like an openGL issue.
Note: Some effects may not be available with all graphics APIs.
OpenGL, which is used by default in most cases, has full support for
all of them. However, the software backend for instance does not
support effects at all. Therefore, when running with graphics APIs
other than OpenGL, refer to the documentation of the QML types in
question to check if the effect is available. For more information on
the Qt Quick scene graph backends, see Scene Graph Adaptations.
http://doc.qt.io/qt-5/qtgraphicaleffects-index.html

Resources