Skip to content

Instantly share code, notes, and snippets.

@adammhaile
Created September 4, 2017 12:15
Show Gist options
  • Save adammhaile/7acb91b23b13a8a57b5abc8453b7d7ec to your computer and use it in GitHub Desktop.
Save adammhaile/7acb91b23b13a8a57b5abc8453b7d7ec to your computer and use it in GitHub Desktop.
from bibliopixel.drivers.driver_base import DriverBase
import time
import struct
import os
from PIL import Image
import numpy
from skvideo.io import FFmpegWriter
import scipy.misc
class MP4(DriverBase):
"""For Testing: Provides no ouput, just a valid interface"""
def __init__(self, num, filename=None, fps=30,
scale=1, size=(32, 32), **kwds):
super().__init__(num, **kwds)
self.filename = filename
self.fps = fps
self.scale = scale
self.file = open(self.filename, 'wb+')
self.rows = 0
self.width, self.height = size
self.video = FFmpegWriter(self.filename, outputdict={
'-vcodec': 'libx264', '-b': '300000000', '-r': str(fps)
})
def cleanup(self):
print('Writing ' + self.filename)
self.video.close()
def _compute_packet(self):
self._packet = numpy.array(self._colors).reshape(self.width, self.height, 3)
self._packet = scipy.misc.imresize(self._packet,
(self.width * self.scale, self.height * self.scale, 3),
interp='nearest')
# self._packet = scipy.ndimage.zoom(self._packet, self.scale, order=0, mode='nearest')
print(self._packet.shape)
def _send_packet(self):
# img = Image.fromarray(self._packet.astype('uint8'), 'RGB')
# self.video.write(cv2.cvtColor(numpy.array(self._packet.astype('uint8')), cv2.COLOR_RGB2BGR))
self.video.writeFrame(self._packet.astype(numpy.uint8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment