I have a h264/264 file and i am trying to play it in QML like this:
MediaPlayer {
id: mediaplayer
source: "file:///blah.h264"
}
VideoOutput{
id: videoPlayer
anchors.fill: parent
source:mediaplayer
}
MouseArea {
id: playArea
anchors.fill: parent
onPressed: {
console.log("play")
mediaplayer.play()
}
}
it doesn't work. i tried the same but with a .mp4 file that worked but this doesnt.
Also i am using python pyside if that helps...
Most playback engines don’t support raw streams. Put the file in a container. ffmpeg -i blah.264 -codec copy blah.mp4
Related
I'm working on a QML based app. where I dynamically load the content. However when running the application it takes quite a long time (5-10 secs), so I need to show any loading screen or indicator while the whole content is being loaded. Can anyone suggest me how to do it ?
For example, after I login in my application it took some time to load the next page so within that oeriod of time i want to show the loading screen.
App {
id: app
height: 400
width: 200
Rectangle {
id: rectangle
Button {
id: button
text: qsTr("GO TO NEXT PAGE")
onClicked:stackView.push("page2.qml")
}
Image {
id: image
fillMode: Image.PreserveAspectFit
source: "default-app.png"
}
}
}
Suppose this is my code then where can i use loader ? I never used it before
You can use the status from a Loader component (I'm guessing you are using that since you are loading "dynamically"). Then use that in a BusyIndicator.
Loader {
id: loader
asynchronous: true
...
BusyIndicator {
anchors.centerIn: parent
running: loader.status == Loader.Loading
}
}
Heck, the Qt docs for BusyIndicator should have get you going!
I am trying to create a simple video player that just plays a specified video on loop. While the video plays as expected, it does not loop.
The following is the code I am using:
import QtQuick 2.0
import QtMultimedia 5.0
Rectangle
{
width : 320
height : 240
signal buttonPressed(string msg)
property string currentVideo
function playVideo(videoName)
{
currentVideo = videoName
videoPlayer.source = videoName
videoPlayer.seek(1)
videoPlayer.play()
}
function loopVideo()
{
if(videoPlayer.duration === 0)
{
playVideo(currentVideo)
}
}
function stopVideoPlayback()
{
videoPlayer.stop()
}
MediaPlayer {
id: videoPlayer
source: ""
autoPlay: false
autoLoad: false
loops: 100
}
VideoOutput {
id: videoOutput
source: videoPlayer
anchors.fill: parent
visible: true
}
}
I call playVideo from C++. It starts playing as expected. However, once it completes, the frame freezes on the last one. I tried looping it by calling the loopVideo function in a QTimer. That does not work either.
What might I be doing wrong?
Your code is ok. (slight tip: you might want to use MediaPlayer.Infinite instead 100 for looping)
I believe that your situation is same like mine.
I have played a little with MediaPlayer component and at my end I am unable to seek video because seekable is always false. And seekable is false because somehow QML uses my file as live stream, and that results duration property to be 0.
Also note that onPaused and onStopped are never triggered and position is just increasing after end of video (live stream never ends).
Now I think that this is related to looping, because basically looping seeks back to 0. Because there is no duration (MediaPlayer thinks it is live stream) it cannot seek (and loop).
One nasty workaround that I found is this (append to your code):
Rectangle {
id: root
//...
MediaPlayer {
//...
onPositionChanged: {
if (position > VIDEO_LENGTH) {
root.stopVideoPlayback()
root.playVideo(root.currentVideo)
}
}
}
}
Where VIDEO_LENGTH is length of your video file in milliseconds.
Click here for MediaPlayer element documentation
UPDATE:
It looks like that is bug in Qt for mingw version (closed bug report).
UPDATE 2: I have downloaded MSVC version of Qt and media player works as it is supposed.
So it is bug in Qt for mingw.
Either use this workaround (which I wouldn't recommend) or download MSVC version.
I have created new bug report here.
Using stopped signal try this code :
MediaPlayer {
id: mediaplayer
source: "groovy_video.mp4"
onStopped: play()
}
I'm trying to play test video with qml by this code:
import QtQuick 2.2
import QtMultimedia 5.0
Item {
width: 300
height: 300
MediaPlayer {
id: player
source: "C:\\Downloads\\video.mp4"
}
VideoOutput {
id: video
anchors.fill: parent
source: player
}
MouseArea {
anchors.fill: parent
onPressed: player.play()
}
}
But, when I click on view, nothing happens. And if I change onPressed event to something else action (not with the player), it works fine, then it's not a MouseArea problem.
Where did I wrong?
Thank you.
The file path seems to be wrong. Since baclslashes need to be escaped in string litterals, the actual path remaining is:
c:\Downloads\video.mp4
That's a path, but not an URL. The correct URL is (see File URIs in Windows):
file:///C:/Downloads/video.mp4
On your code source:
C:\\Downloads\\video.mp4
should be source:
C://Downloads//video.mp4
I am using Qtmultimedia 5.0 to record and capture video from webcam. The example provided by Qt helped me very much. I could record and stop the captured video using the following code.
Camera {
id: camera
}
Rectangle{
Text{
text: qsTr("Record")
}
MouseArea{
onClicked: camera.videoRecorder.record()
}
}
Rectangle{
Text{
text: qsTr("Stop")
}
MouseArea{
onClicked: camera.stop()
}
}
Now i need the pause and resume the webcam video. Is there any function to do that job. If I resume the video it should append to the opened file.
just want to let you know that you can use Qt Media Encoding Library for that task.
It is here - http://kibsoft.ru
I have a problem with a BusyIndicator, what happens is that I have appointed BusyIndicator that when loading the feed is removed, but in my file. QML images do not appear in the feed, I wonder if there is any way to tell the BusyIndicator that when the image is displayed BusyIndicator remove.
Well I did this, you can give it a try.
Image
{
id : image1
source:"...your source here"
}
BusyIndicator
{
id:busy1
anchors.centerIn: parent
width:50
height:50
visible: image1.status == Image.Loading
running: image1.status == Image.Loading
}
//indicator only visible and run when image is loading. After image is being loaded or when Image.Ready, the busy indicator will disappear.
You can do something like this
Image{
id:remoteImage
source: "http://www.example.com/m.jpg"
onProgressChanged: {
if(progress==1.0)
busyIndicator.visible=false;
}
}