Created
February 21, 2012 15:39
-
-
Save tito/1877073 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.graphics.fbo import Fbo | |
from kivy.graphics import Rectangle, Color | |
from kivy.core.gl import glReadPixels, GL_RGBA, GL_UNSIGNED_BYTE | |
import pygame | |
def save_texture(texture, filename): | |
fbo = Fbo(size=texture.size) | |
fbo.add(Color(1, 1, 1)) | |
fbo.add(Rectangle(size=texture.size, texture=texture)) | |
fbo.draw() | |
fbo.bind() | |
w, h = texture.size | |
data = glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE) | |
fbo.release() | |
pixels = pygame.image.fromstring(data, texture.size, 'RGBA', True) | |
image = pygame.Surface(texture.size, depth=24) | |
image.blit(pixels, (0, 0)) | |
pygame.image.save(image, filename) | |
if __name__ == '__main__': | |
import sys | |
from kivy.uix.video import Video | |
from kivy.base import runTouchApp | |
from kivy.clock import Clock | |
video = None | |
def save_video_image(dt): | |
save_texture(video.texture, 'test.png') | |
sys.exit(0) | |
Clock.schedule_once(save_video_image, 3) | |
video = Video(source=sys.argv[1], play=True) | |
runTouchApp(video) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment