Display video stream in QLabel using PySide

Can someone point me in the right direction how to create a new QMovie provider in PySide?

I have a video stream that I want to show as simple as possible (without sound, just a sequence of frames with an unknown and variable frame rate). This example seems perfect, except that my video comes from an unconventional source. This is not a file, but a network stream in a format that is not standardized. I can easily write the code that each frame receives, and my idea is to create a “QMovie provider” so that I can simply display this stream on a shortcut, as in the example above.

My first thought was to simply subclass QMovie and rewrite several functions, but I started thinking about it while reading the documentation , since I don’t know what I should do with the “device” that my instance will read.

In the above documentation, I noticed that QMovie uses QImageReader, so my next thought was to extend this class and read its frames from my stream. However, similar questions arise, for example, what should I do with the "supportedImageFormats ()" function?

I experimented by simply updating the image on my QLabel every time I get a new frame, but then I get the error "QPixmap: it is not safe to use pixmaps outside the GUI stream".

So basically I'm a bit stumped and really appreciate any pointers or guides on how to get QLabel to display my video stream in PySide.

+4
source share
1 answer

In the future, contact us how I did it.

Using the mechanisms of signals and slots, the following application works. The signal / slot mechanism seems to show that the image created inside the up_camera_callback function and emitted by the CameraDisplay.updateFrame function comes from another stream and takes the necessary precautions.

class CameraDisplay(QtGui.QLabel): def __init__(self): super(CameraDisplay, self).__init__() def updateFrame(self, image): self.setPixmap(QtGui.QPixmap.fromImage(image)) class ControlCenter(QtGui.QWidget): up_camera_signal = QtCore.Signal(QtGui.QImage) up_camera = None def __init__(self): super(ControlCenter, self).__init__() self.up_camera = CameraDisplay() self.up_camera_signal.connect(self.up_camera.updateFrame) grid = QtGui.QGridLayout() grid.setSpacing(10) grid.addWidget(self.up_camera, 0, 0) self.setLayout(grid) self.setGeometry(300, 300, 350, 300) self.setWindowTitle('Control Center') self.show() def up_camera_callback(self, data): '''This function gets called by an external thread''' try: image = QtGui.QImage(data.data, data.width, data.height, QtGui.QImage.Format_RGB888) self.up_camera_signal.emit(image) except Exception, e: print(e) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) ex = ControlCenter() sys.exit(app.exec_()) 
+8
source

All Articles