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
Related
I'm struggling to authenticate in HERE plugin. I'm using windows 10 with Qt 5.9.1 Mingw 32bit and my app is almost all written in c++. The only part Where I use QML is about the map. I want to use the HERE plugin, but I am a newbie with QtLocation and plugins, and I really can't understand what I need to do to authenticate in HERE. I tried to follow the guide on the HERE site but I really can't understand.
I know from qt that the code I must use to athenticate on HERE is the following:
Plugin {
name: "here"
PluginParameter { name: "here.app_id"; value: "myapp" }
PluginParameter { name: "here.token"; value: "abcdefg12345" }
}
So I need here.app_id and here.token.
I created an account on the HERE site and I created a project using REST. So now I have my APP ID parameter but I really don't understand how to get the TOKEN value to put in the second line. First of all for my specific case I need to create an api key or an OAuth 2.0?
I tried to follow what is written in this link using Postman and at the end I got a really long tokoen that I copied and put in the "here.token" parameter but when I run the application it gives me Invalid here.token and it does not display the map.
Can somebody give me any hint on how to correctly get the token value? Or can somebody point me to some links? Is there a different way to login using an api key for example instead of the token?
---------------- UPDATE ---------------------------------------
After some time I had to return on this problem that I never solved: the situation right now is that I manage to get the token through postman but it's always invalid.
Right now I'm using Qt 5.15.2 and MinGw 64 bit.
I'm using the minimal_map example modified to add the here.app_id and here.token parameter.
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtLocation 5.6
import QtPositioning 5.6
Window {
width: Qt.platform.os == "android" ? Screen.width : 512
height: Qt.platform.os == "android" ? Screen.height : 512
visible: true
Plugin {
id: mapPlugin
name: "here" // "mapboxgl", "esri", ...
// specify plugin parameters if necessary
parameters: [
PluginParameter {
name: "here.app_id"
value: "xxxxx"
},
PluginParameter {
name: "here.token"
value: "yyyyyy"
}]
}
Map {
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(59.91, 10.75) // Oslo
zoomLevel: 14
}
}
the problem is that when I run the app the output is the following:
Invalid here.token
3 , "Qt Location requires app_id and token parameters.\nPlease register at https://developer.here.com/ to get your personal application credentials."
To get the token I've done the following:
I registered myself at developer.here site with a Freemium plan and I created a project.
I created a REST API and an OAuth 2.0 (JSON Web Tokens) as follows (I saved the credentials.properties files that I used in the 3. step):
I download Postman, I created an account and I followed the instruction from the answer to this question.
I received response in a json format like this:
a
I went in my minimal_map example and I set as app_id (instead of "xxxxx") the APP ID value displayed inside the first image I posted and as here.token (instead of the "yyyyyy") the acces_token received in the JSON response from POSTMAN.
I tried to clean the project, delete the build folder but nothing changed, the answer is always:
Invalid here.token
3 , "Qt Location requires app_id and token parameters.\nPlease register at https://developer.here.com/ to get your personal application credentials."
What am I missing to get a token to display the here plugin in Qt?
The HERE service has been updated but Qt has not updated its plugin.
The main changes are:
The app_id and token is only necessary when using the HERE SDK, in the case of Qt the apiKey must be used.
The HERE services url has had the following changes:
Use https (it was previously accessible through http but not now).
The previous host had the format X.api.here.com but now it is X.ls.hereapi.com.
That is, you have to change the request from:
http://X.api.here.com/?app_code={here.app_code}&app_id={here.app_id}&{other_parameters}
to
https://X.ls.here.com/?apiKey={here.apiKey}&{other_parameters}
Qt 5.14:
Considering the above I have created a patch that implements the above, so to use it you must follow the following procedure:
git clone https://code.qt.io/qt/qtlocation.git
cd qtlocation
git checkout 5.14
wget https://raw.githubusercontent.com/eyllanesc/stackoverflow/master/questions/60544057/Qt5.14/update-HERE-Qt5.14.patch
git config --global user.email "you#example.com"
git am < update-HERE-Qt5.14.patch
qmake .
make
make install
Qt 5.9:
Considering the above I have created a patch that implements the above, so to use it you must follow the following procedure:
git clone https://code.qt.io/qt/qtlocation.git
cd qtlocation
git checkout 5.9
wget https://raw.githubusercontent.com/eyllanesc/stackoverflow/master/questions/60544057/Qt5.9/update-HERE-Qt5.9.patch
git config --global user.email "you#example.com"
git am < update-HERE-Qt5.9.patch
qmake .
make
make install
Window {
visible: true
width: 640
height: 480
Plugin {
id: mapPlugin
name: "here"
PluginParameter { name: "here.apiKey"; value: "{YOUR_API_KEY}" }
}
Map {
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(59.91, 10.75) // Oslo
zoomLevel: 14
}
}
UPDATE
Here service provides various authentication systems with different access urls. So considering the above I have tried each of those cases and I have found that Qt uses HERE SDK FOR IO or HERE SDK FOR ANDROID (in my part before my answer it is used for authentication type REST).
So in this case you must activate one of those types of authentications:
In the case of the HERE SDK FOR IOS or HERE SDK FOR ANDROID you must set any value for the bundle or package name, respectively.
So you must use APP ID for here.app_id and APP CODE for here.token:
Plugin {
id: mapPlugin
name: "here"
parameters: [
PluginParameter {
name: "here.app_id"
value: "APP_ID"
},
PluginParameter {
name: "here.token"
value: "APP_CODE"
}
]
}
I can run a boilerplate QT Quick Application (empty project) fine - the window shows and does not crash. If I then update the QML with some simple controls and run the application it shows the window for 3 seconds then crashes. This problem occurs when I run the example QT Quick application projects aswell.
The application output window shows:
The program has unexpectedly finished.
The process was ended forcefully.
What is going wrong and how can I fix this?
Information:
I am on Windows 10 64bit, using QT Creator, the project using QMake and mininum QT version allowed is 5.9
I am compiling in Debug mode using Desktop QT 5.11.1 MSVC2017 64bit. Note I am not able to compile in any other settings (MSVC2015, MinGW) - I get errors. If I compile in Release mode I still experience the same crash.
Desktop QT 5.11.1 MSVC2017 64bit does have an exclamation mark next to it No debugger setup
The following QML works:
import QtQuick 2.11
import QtQuick.Window 2.11
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}
This causes it to crash:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
menuBar: MenuBar {
Menu {
title: 'File'
}
}
header: ToolBar {
RowLayout {
}
}
TextArea {
id: area
anchors.fill: parent
}
}
I was getting this crash too, with only a rectangle on the Window.
For me the crash was fixed by adding the following line before instantiating my QGuiApplication :
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
from the docs, on windows, this tells qt to use the angle. Angle is driver that translates opengl into directx
you can read more about the diferent driver option on
http://doc.qt.io/qt-5/windows-requirements.html
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
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();
}
}
}
I need to get my location in nokia QT.
I have the following code:
Rectangle {
id: page
width: 350
height: 350
PositionSource {
id: positionSource
updateInterval: 1000
active: true
onPositionChanged: {
console.log("latitude : "+positionSource.position.coordinate.latitude);
console.log("longitude :"+positionSource.position.coordinate.longitude);
}
}
}
In the project file I have set the capability and mobility configuration:
symbian:
{
TARGET.CAPABILITY += Location
CONFIG += mobility
MOBILITY +=location
}
This code is run fine on the simulator, but on the real handset (Nokia 5530 XpressMusic) it doesn't work and I got this message:
[Qt Message] QGeoPositionInfoSource::createDefaultSource() requires the Symbian Location capability to succeed on the Symbian platform
What is the problem?
Other than some certification problems, that CAPABILITY+=Location line is sufficient.
However, after adding that, you must ensure that qmake is run at least once, so all your build scripts and metafiles are refreshed. If you are still getting that error after adding that line, just run qmake either from command line, or from project context manu in qtcreator