[PyQt] [PyQt5] : QAbstractVideoSurface

Kermit stef.kermit at gmail.com
Tue Feb 17 14:42:50 GMT 2015


hi,

i've this little script :
__________________________________________
import sys
import os
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtMultimedia import *
from PyQt5.QtMultimediaWidgets import *


class VideoSurface(QAbstractVideoSurface):

     def __init__(self, parent=None):
         QAbstractVideoSurface.__init__(self, parent)
         self.imageFormat = QImage.Format_Invalid

     def
supportedPixelFormats(self,handleType=QAbstractVideoBuffer.NoHandle):
         formats = [QVideoFrame.PixelFormat()]
         if (handleType == QAbstractVideoBuffer.NoHandle):
             for f in [QVideoFrame.Format_RGB32,
                       QVideoFrame.Format_ARGB32,
                       QVideoFrame.Format_ARGB32_Premultiplied,
                       QVideoFrame.Format_RGB565,
                       QVideoFrame.Format_RGB555
                       ]:
                 formats.append(f)
         return formats

     def isFormatSupported(self, _format):
         imageFormat =
QVideoFrame.imageFormatFromPixelFormat(_format.pixelFormat())
         size = _format.frameSize()
         _bool = False
         if (imageFormat != QImage.Format_Invalid and not
             size.isEmpty() and
             _format.handleType() == QAbstractVideoBuffer.NoHandle):
             _bool = True
         return _bool

     def start(self, _format):
         imageFormat =
QVideoFrame.imageFormatFromPixelFormat(_format.pixelFormat())
         size = _format.frameSize()
         if (imageFormat != QImage.Format_Invalid and not size.isEmpty()):
             self.imageFormat = imageFormat
             self.imageSize = size
             self.sourceRect = _format.viewport()
             QAbstractVideoSurface.start(self, _format)
             return True
         else:
             return False

     def stop(self):
         self.currentFrame = QVideoFrame()
         QAbstractVideoSurface.stop(self)


     def present(self, frame):
         if (self.surfaceFormat().pixelFormat() != frame.pixelFormat() or
self.surfaceFormat().frameSize() != frame.size()):
             self.setError(QAbstractVideoSurface.IncorrectFormatError)
             self.stop()
             return False
         else:
             self.currentFrame = frame
             return True


if __name__=="__main__":
    import sys
    app = QApplication(sys.argv)
    surface = VideoSurface()
    mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
    mediaPlayer.setVideoOutput(surface)
    app.exec_()
______________________________________________________________________

this script is base on this post :
http://www.riverbankcomputing.com/pipermail/pyqt/2013-October/033256.html

this script failed ( crash ) if i comment this import:
from PyQt5.QtMultimediaWidgets import *


I'm on windows
Python version 2.7.9 x64
QT_VERSION_STR    '5.4.0'
PYQT_VERSION_STR '5.4'
SIP_VERSION_STR '4.16.5'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150217/d07ca5fb/attachment.html>


More information about the PyQt mailing list