QMediaPlayer inside QGraphicsView with gstreamer PySide6

76 Views Asked by At

I have tried to launch a gstreamer pipeline in Python using QGraphicsView with QMediaPlayer.

It works if I use QVideoWidget, however, I am unable to run it with QGraphicsView. I need QGraphicsView, because I need functionality of it, as I will need to be able to draw on it, move around and etc.

Python: 3.10.12 PySide6: 6.6.1 GStreamer: 1.20.3 OS: Ubuntu 22.04

I have tried to use the example from QMediaPlayer documentation page, but it was not helpful. I have tried various sinks, sources and it did not work.

The code runs without throwing any errors, but all I get is empty gray window.

import sys
from PySide6.QtCore import QUrl
from PySide6.QtWidgets import QApplication, QGraphicsView, QGraphicsScene
from PySide6.QtMultimedia import QMediaPlayer, QVideoFrame
from PySide6.QtMultimediaWidgets import QGraphicsVideoItem

app = QApplication(sys.argv)

class VideoPlayer(QGraphicsView):
    def __init__(self):
        super().__init__()
        self.scene = QGraphicsScene(0, 0, 640, 480)
        self.setScene(self.scene)

        self.player = QMediaPlayer()
        self.videoItem = QGraphicsVideoItem()
        self.scene.addItem(self.videoItem)

        self.player.setVideoOutput(self.videoItem)

        self.player.setSource(QUrl("gst-pipeline: videotestsrc ! xvimagesink name=\"qtvideosink\""))
        self.player.play()

    def closeEvent(self, event):
        self.player.stop()
        super().closeEvent(event)

if __name__ == '__main__':
    player = VideoPlayer()
    player.show()
    sys.exit(app.exec())

I believe that this is Gstreamer pipeline issue, because, if I launch my a local video, the display does work:

self.player.setSource(QUrl.fromLocalFile("1.mp4"))

I am not exactly sure what else could I do...

0

There are 0 best solutions below