def save(self, path): width, height = self.width, self.height count = 0 fd = open(path, 'w') encoder = Encoder(width, height) image = Image(width, height, vpx.VPX_IMG_FMT_I420) timebase = encoder.cfg.g_timebase.den, encoder.cfg.g_timebase.num fd.write(ivf_file_header(width, height, timebase, count)) for t, frame in self.frames: print "streaming frame %i..." % t, with Image(width, height, vpx.VPX_IMG_FMT_RGB24, getPixels(frame)) as src: src.convertTo(image) image.flip() for kind, packet in encoder.encode(image, t): if kind == vpx.VPX_CODEC_CX_FRAME_PKT: fd.write(ivf_frame_header(len(packet), t)) fd.write(packet) count += 1 print "ok." image.free() fd.seek(0) fd.write(ivf_file_header(width, height, timebase, count)) fd.close() encoder.close()
image = Image(width, height, vpx.VPX_IMG_FMT_I420) encoder = Encoder(width, height) width = encoder.cfg.g_w height = encoder.cfg.g_h timebase = encoder.cfg.g_timebase.den, encoder.cfg.g_timebase.num fd.write(ivf_file_header(width, height, timebase, count)) for t, frame in frames: image_src = Image(width, height, vpx.VPX_IMG_FMT_RGB24, buffer(frame)) image_src.convertTo(image) image.flip() for kind, packet in encoder.encode(image, t): if kind == vpx.VPX_CODEC_CX_FRAME_PKT: fd.write(ivf_frame_header(len(packet), t)) fd.write(packet) count += 1 image.free() fd.seek(0) fd.write(ivf_file_header(width, height, timebase, count)) fd.close() encoder.close() from argon import graphics from OpenGL.GL import * from ctypes import CDLL libgl = CDLL('libGL.so') def getPixels(texture): texture.bind() data = glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE)