Skip to content

Instantly share code, notes, and snippets.

@figgis
Created April 23, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save figgis/2473409 to your computer and use it in GitHub Desktop.
Save figgis/2473409 to your computer and use it in GitHub Desktop.
YCbCr viewer
#!/usr/bin/env python
import pygame
import Image
import sys
W = 352
H = 288
WH = (W, H)
pygame.init()
screen = pygame.display.set_mode(WH)
fd = open('foreman.yuv', 'rb')
y = fd.read(W * H)
u = fd.read(W * H / 4)
v = fd.read(W * H / 4)
# Use PIL to get a black-n-white version of the YCbCr
# and convert it to RGB
im = Image.fromstring("L",WH, y)
rgb = im.convert('RGB')
bin_str = im.tostring()
# Also tried to skip PIL and use
#s = pygame.image.fromstring(y, WH, 'P').convert()
# no errors or anything, but all black is displayed
s = pygame.image.fromstring(bin_str, WH, 'RGB').convert()
print s
screen.blit(s, (0,0))
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment