-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoItem.py
79 lines (66 loc) · 2.65 KB
/
VideoItem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'''
Created on Oct 4, 2012
@author: yvesremi
'''
from PyQt4 import QtMultimedia, QtGui, QtCore
class VideoItem(QtMultimedia.QAbstractVideoSurface, QtGui.QGraphicsItem):
'''
classdocs
'''
imageFormat = QtGui.QImage.Format_Invalid
framePainted = False
imageSize = None
currentFrame = None
def __init__(self, parent = None):
'''
Constructor
'''
if parent is None:
super(VideoItem, self).__init__()
else:
super(VideoItem, self).__init__(parent)
def boundingRect(self):
a=0
a=a+1
def paint(self, painter):
if (self.currentFrame.map(QtMultimedia.QAbstractVideoBuffer.ReadOnly)):
oldTransform = painter.transform()
if (self.surfaceFormat().scanLineDirection() == QtMultimedia.QVideoSurfaceFormat.BottomToTop):
painter.scale(1, -1)
painter.translate(0, -self.widget.height())
image= QtGui.QImage(self.currentFrame.bits(), self.currentFrame.width(), self.currentFrame.height(), self.currentFrame.bytesPerLine(), self.imageFormat)
painter.drawImage(self.targetRect, image, self.sourceRect)
painter.setTransform(oldTransform)
self.framePainted = True
self.currentFrame.unmap()
def supportedPixelFormats(self, handleType):
if(handleType == QtMultimedia.QAbstractVideoBuffer.NoHandle ):
return [QtMultimedia.QVideoFrame.Format_RGB32, QtMultimedia.QVideoFrame.Format_ARGB32, QtMultimedia.QVideoFrame.Format_ARGB32_Premultiplied, QtMultimedia.QVideoFrame.Format_RGB24, QtMultimedia.QVideoFrame.Format_RGB565, QtMultimedia.QVideoFrame.Format_RGB555]
else:
return []
def start(self, form):
if (self.isFormatSupported(form)):
self.imageFormat = QtMultimedia.QVideoFrame.imageFormatFromPixelFormat(form.pixelFormat())
self.imageSize = form.frameSize()
self.framePainted = True
super(VideoItem, self).start(form)
self.prepareGeometryChange()
return True
else:
return False
def stop(self):
self.currentFrame = QtMultimedia.QVideoFrame();
self.framePainted = False
super(VideoItem, self).stop()
def present(self, frame):
if (not(self.framePainted)):
if(not(self.isActive())):
raise Exception('Video is not started!')
return False
else:
self.currentFrame = frame
self.framePainted = False
self.update()
return True
def sizeHint(self):
return QtCore.QSize(800, 600)