Raspberry pi-4. Issues with video, Media player example crashes and freezes when loading and playing videos.
-
Im trying to use the MediaPlayer in QML to play a video for my application, i noticed some issues with it and found the same issues were present in the QML examples that also used the MediaPlayer
When running the "Media player" example app from QT-creator's library of example applications, on a raspberry pi 4, connected to a 1080 by 1080 p monitor, the video will run fine the first time, then when reloaded to view again, will start to stutter and stop till eventually it freezes. Once this occurs, usually “Internal data stream error” occasionally flashes to the screen. Whilst the console prints “warning: a lot of buffers are being dropped” Furthermore it completely crashes when trying to load a 6 MB video.
I Have been able to replicate this issue on two separate R-pi4's with two separate copy's of bootToQt
So far in an attempt to debug this i have added a heat-sink to the R-PI4 , which has kept its temps at a stable 40c. I have changed the "QT_MEDIA_BACKEND" environment variable to several different settings , but am unsure if there is a specific one for R-PI which i haven't tried. I have reduced the memory size of the input video to 1.3mb , and have been using a 640 pixel by 360 pixel video. i reduced the size of the output display window for the video to a variety of sizes, even 100 pixels by 100 pixels.
if you would like to replicate the issue:
Here is an example of the video : https://videos.pexels.com/video-files/855401/855401-sd_640_360_25fps.mp4
though the error also occurs with the video that comes with the example application.
I am using Boot to QT 6.7.0 and replicated the same issue with 6.8.0
Code can be found in the qt-creator example named "Media Player"
it can take a few re-loads of the video to cause the error. -
reported the issue to qt support , its now a bug which they are working on: https://bugreports.qt.io/browse/QTBUG-125292
incase anyone else has the same issue, i have a work around fix:
construct a timer and a loader. use the timer to delete the media player every time the video finished playing and reconstruct it with the loader.import QtMultimedia Item { /// the below is written as a work around for a bug with the multimedia player on raspberry pi's. /// i belive some kind of memory leak in the media player forms when the media player compiles for the r-pi. /// this causes the media player to slow down with each iteration fo the video loop /// as such , this code deletes the video player and constructs a new video player between each loop. id: root property point beginDrag property var source property bool hotReload Component { id: mediaPlayerContainer MediaPlayer { Component.onCompleted:{ console.log("Player loaded"); play()} Component.onDestruction: {console.log("Destruction Beginning!")} id: mediaPlayer videoOutput: vidya loops: MediaPlayer.Infinite source: root.source } } Timer { id: timer interval: 1000 property int counter: 100 repeat: true triggeredOnStart: true onTriggered: { counter += 1 //console.log(counter) if(counter > 55) { counter = 0 //console.log("hotReaload"); hotReload = true } else hotReload = false } Component.onCompleted:{ timer.start()} } VideoOutput { id: vidya anchors.fill: root } Loader { id:videoloader active: !hotReload sourceComponent: mediaPlayerContainer } Component.onCompleted: {console.log("ITEM LOADED");Loader.active=true; timer.start() } }
-
@Thomas-Pearson said in Raspberry pi-4. Issues with video, Media player example crashes and freezes when loading and playing videos.:
I am using Boot to QT 6.7.0
Since Boot2Qt is a commercial product you can also ask QtCompany directly for support if you can't find help here.
-
reported the issue to qt support , its now a bug which they are working on: https://bugreports.qt.io/browse/QTBUG-125292
incase anyone else has the same issue, i have a work around fix:
construct a timer and a loader. use the timer to delete the media player every time the video finished playing and reconstruct it with the loader.import QtMultimedia Item { /// the below is written as a work around for a bug with the multimedia player on raspberry pi's. /// i belive some kind of memory leak in the media player forms when the media player compiles for the r-pi. /// this causes the media player to slow down with each iteration fo the video loop /// as such , this code deletes the video player and constructs a new video player between each loop. id: root property point beginDrag property var source property bool hotReload Component { id: mediaPlayerContainer MediaPlayer { Component.onCompleted:{ console.log("Player loaded"); play()} Component.onDestruction: {console.log("Destruction Beginning!")} id: mediaPlayer videoOutput: vidya loops: MediaPlayer.Infinite source: root.source } } Timer { id: timer interval: 1000 property int counter: 100 repeat: true triggeredOnStart: true onTriggered: { counter += 1 //console.log(counter) if(counter > 55) { counter = 0 //console.log("hotReaload"); hotReload = true } else hotReload = false } Component.onCompleted:{ timer.start()} } VideoOutput { id: vidya anchors.fill: root } Loader { id:videoloader active: !hotReload sourceComponent: mediaPlayerContainer } Component.onCompleted: {console.log("ITEM LOADED");Loader.active=true; timer.start() } }
-