import sys from PySide2.QtGui import * from PySide2.QtCore import * from PySide2.QtMultimedia import * from PySide2.QtWidgets import * class VideoSurface(QAbstractVideoSurface): def __init__(self, parent=None): super(VideoSurface, self).__init__(parent) print("surface init", self.error()) def present(self, frame): print("present()") return False def start(self, format): print("start()") image_format = QVideoFrame.imageFormatFromPixelFormat(format.pixelFormat()) image_size = format.frameSize() if image_format != QImage.Format_Invalid and not image_size.isEmpty(): super(VideoSurface, self).start(format) return True else: return False def stop(self): print("stop()") super(VideoSurface, self).stop() def supportedPixelFormats(self, type: QAbstractVideoBuffer.HandleType = ...): print("supportedPixelFormats()") if type == QAbstractVideoBuffer.NoHandle: formats = [ QVideoFrame.Format_RGB32, ] return formats else: return [] def isFormatSupported(self, format): print("isFormatSupported", format) return True @Slot(QMediaPlayer.MediaStatus) def on_media_player_media_status_changed(status): print("player status", status) @Slot(QMediaPlayer.Error) def on_media_player_error(error): print("player error", error) if __name__ == "__main__": app = QApplication(sys.argv) surface = VideoSurface() media_player = QMediaPlayer(flags=QMediaPlayer.VideoSurface) media_player.mediaStatusChanged.connect(on_media_player_media_status_changed) media_player.error.connect(on_media_player_error) media_player.setVideoOutput(surface) media_player.setMedia( QMediaContent(QUrl("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/VolkswagenGTIReview.mp4"))) media_player.play() err = app.exec_() sys.exit(err)