I'm quite new to pyqt. So please forgive any misconcepts I might have.
I have trouble to load video directly to QMovie using:
__init__ (self, QString fileName, ...)
QMovie itself seems quite picky when it comes to supporting (decoding) Video formats.
This is why I want to decode the VideoFiles using FFMPEG, store the frames into a QIODevice and feed the device to QMovie using:
__init__ (self, QIODevice device, ...)
This code uses FFMPEG to decode a Video file and stores the first 20 frames into a QIODevice stream as JPGs. This QIODevice is fed to the QMovie.
Great! the QMovie plays at full speed...
But.. only once ...
and the QMovie.frameCount()
returns just 1
frame instead of 20... (when queried before QMovie.start()
)
Using PyQt4, imageio, numpy
print('>> FFMPEG Loading file : '+videoFile)
# Use FFMPEG to decode Video through imageio
self.vid=imageio.get_reader(str(videoFile), 'ffmpeg')
# Init QIODevice
byte_array = QtCore.QByteArray()
self.buf = QtCore.QBuffer()
self.movie= QtGui.QMovie(parent)
# Populate 20 Frames Stream
i=0
self.buf.open(QtCore.QIODevice.Append)
#Sample 20 Frames from videoFile
while i<20:
# decode / read to rgb24 Frame
npArray_RGB888 = self.vid.get_data(i).astype(np.uint8)
# Actually 'append' the Frame data to the Stream as JPG
npArray_RGB888.save(self.buf, 'JPG')
#print(' == == '+str(self.buf.data().size()))
#print(' == == '+str(buf.data()))
i+=1
# Close the Stream
self.buf.close()
# Load the QIODecvice buffer in QMovie
# self.movie.setFileName(videoFile) # To decode with QMovie directly
self.movie = QtGui.QMovie(self.buf, 'jpg', self)
print('>>> FrameCount : '+str(self.movie.frameCount()))
self.movie.start()
Why is the framecount 1
instead of 20?
What am I doing wrong?
Is there a more direct way to store FFMPEG result data into QIODevice? Prehaps loading the videoFile at once into the QIODevice instead of each frame individually?
Many thanks in advance.