[cgkit-user] cgkit.mediafile with PyQt4 and Python3
Brought to you by:
mbaas
|
From: Timothy W. G. <tim...@si...> - 2013-10-09 22:30:48
|
Anyone with successful experience of using cgkit.mediafile with PyQt4
and Python3 ?
Since I'm working with Python 3 the use of PIL Images isn't available to
me (or is it?), so
I'm attempting to paint a video frame to a QImage instead. Below is an
attempt to do so
with the first frame from a sample video found in Windows 7, but no joy
yet. Any ideas
are most welcome.
Best regards,
Tim Grove
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from cgkit import mediafile
import numpy as np
if __name__ == '__main__':
app = QApplication(sys.argv)
## setup widgets to display video frames
widget = QWidget(None)
widget.resize(QSize(400, 300))
videoLabel = QLabel(widget)
videoLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
videoLabel.setPixmap(QPixmap(QSize(400, 300)))
layout = QVBoxLayout()
layout.addWidget(videoLabel)
widget.setLayout(layout)
widget.show()
fileName = "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv"
vid = mediafile.open(fileName) # open file
frame = next(vid.iterData()) # get data for first frame
# Get the current video frame as a numpy.ndarray.
ndArray = frame.numpyArray()
w = ndArray.shape[0]
h = ndArray.shape[1]
# paint data into a QImage
img = QImage(w, h, QImage.Format_RGB32)
img.ndarray = ndArray # keep ndArray for image; NOTE: necessary???
# convert ndArray into a QByteArray NOTE: is this correct ???
byteArray = QByteArray(ndArray.data.tobytes())
img.fromData(byteArray)
# convert QImage to a QPixmap and paint it into the video QLabel
videoLabel.pixmap().convertFromImage(img)
## NOTE: NOTHING HAPPENS !!!
vid.close() #close file
sys.exit(app.exec_())
|