[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] [PyQt5] : QAbstractVideoSurface
From:       Kermit <stef.kermit () gmail ! com>
Date:       2015-02-17 14:42:50
Message-ID: CA+4Qr9aATijdudLwkt7QKRdQmmBir+=fop7DJQ7WscGB6p9sHw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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'

[Attachment #5 (text/html)]

<div dir="ltr">hi,<div><br></div><div>i&#39;ve this little script \
:</div><div>__________________________________________</div><div><div>import \
sys</div><div>import os</div><div>from PyQt5.QtGui import *</div><div>from \
PyQt5.QtWidgets import *</div><div>from PyQt5.QtCore import *</div><div>from \
PyQt5.QtMultimedia import *</div><div>from PyQt5.QtMultimediaWidgets import \
*</div><div><br></div><div><br></div><div>class \
VideoSurface(QAbstractVideoSurface):</div><div><br></div><div>        def \
__init__(self, parent=None):</div><div>              \
QAbstractVideoSurface.__init__(self, parent)</div><div>              self.imageFormat \
= QImage.Format_Invalid</div><div><br></div><div>        def \
supportedPixelFormats(self,handleType=QAbstractVideoBuffer.NoHandle):</div><div>      \
formats = [QVideoFrame.PixelFormat()]</div><div>              if (handleType == \
QAbstractVideoBuffer.NoHandle):</div><div>                    for f in \
[QVideoFrame.Format_RGB32,</div><div>                                   \
QVideoFrame.Format_ARGB32,</div><div>                                   \
QVideoFrame.Format_ARGB32_Premultiplied,</div><div>                                   \
QVideoFrame.Format_RGB565,</div><div>                                   \
QVideoFrame.Format_RGB555</div><div>                                   ]:</div><div>  \
formats.append(f)</div><div>              return formats</div><div><br></div><div>    \
def isFormatSupported(self, _format):</div><div>              imageFormat = \
QVideoFrame.imageFormatFromPixelFormat(_format.pixelFormat())</div><div>              \
size = _format.frameSize()</div><div>              _bool = False</div><div>           \
if (imageFormat != QImage.Format_Invalid and not</div><div>                    \
size.isEmpty() and</div><div>                    _format.handleType() == \
QAbstractVideoBuffer.NoHandle):</div><div>                    _bool = True</div><div> \
return _bool</div><div><br></div><div>        def start(self, _format):</div><div>    \
imageFormat = QVideoFrame.imageFormatFromPixelFormat(_format.pixelFormat())</div><div> \
size = _format.frameSize()</div><div>              if (imageFormat != \
QImage.Format_Invalid and not size.isEmpty()):</div><div>                    \
self.imageFormat = imageFormat</div><div>                    self.imageSize = \
size</div><div>                    self.sourceRect = _format.viewport()</div><div>    \
QAbstractVideoSurface.start(self, _format)</div><div>                    return \
True</div><div>              else:</div><div>                    return \
False</div><div><br></div><div>        def stop(self):</div><div>              \
self.currentFrame = QVideoFrame()</div><div>              \
QAbstractVideoSurface.stop(self)</div><div><br></div><div><br></div><div>        def \
present(self, frame):</div><div>              if (self.surfaceFormat().pixelFormat() \
!= frame.pixelFormat() or self.surfaceFormat().frameSize() != \
frame.size()):</div><div>                    \
self.setError(QAbstractVideoSurface.IncorrectFormatError)</div><div>                  \
self.stop()</div><div>                    return False</div><div>              \
else:</div><div>                    self.currentFrame = frame</div><div>              \
return True</div><div><br></div><div><br></div><div>if \
__name__==&quot;__main__&quot;:</div><div>      import sys</div><div>      app = \
QApplication(sys.argv)</div><div>      surface = VideoSurface()</div><div>      \
mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)</div><div>      \
mediaPlayer.setVideoOutput(surface)</div><div>      \
app.exec_()</div><div>______________________________________________________________________</div><div><br></div><div>this \
script is base on this post :</div></div><div><a \
href="http://www.riverbankcomputing.com/pipermail/pyqt/2013-October/033256.html">http: \
//www.riverbankcomputing.com/pipermail/pyqt/2013-October/033256.html</a><br></div><div><br></div><div>this \
script failed ( crash ) if i comment this import:</div><div>from \
PyQt5.QtMultimediaWidgets import \
*<br></div><div><br></div><div><br></div><div>I&#39;m on windows</div><div>Python \
version 2.7.9 x64</div><div><div>QT_VERSION_STR      \
&#39;5.4.0&#39;</div></div><div><div>PYQT_VERSION_STR \
&#39;5.4&#39;</div></div><div><div>SIP_VERSION_STR \
&#39;4.16.5&#39;</div></div><div><br></div><div><br></div></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic