Skip to content

Instantly share code, notes, and snippets.

@illume
Created July 18, 2015 12:03
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 illume/f8792964d20df2576a6d to your computer and use it in GitHub Desktop.
Save illume/f8792964d20df2576a6d to your computer and use it in GitHub Desktop.
a glitchy video
'''
How to download and cut up the video (requires python3 and ffmpeg)
virtualenv-3.4 anenv
. ./anenv/bin/activate
pip3.4 install you-get
you-get https://vimeo.com/45878034
ffmpeg -i View\ from\ the\ ISS\ at\ Night\ from\ Knate\ Myers\ on\ Vimeo.mp4 -ss 00:02:36 -t 00:00:10 -c copy source-video.mp4
Now we cut it up into separate images:
mkdir video-images
ffmpeg -i source-video.mp4 -f image2 video-images/image-%3d.jpg
We can change the images, and then join them into a video:
ffmpeg -framerate 29.97 -i output-images/image-%3d.jpg -c:v libx264 -r 29.97 -pix_fmt yuv420p our-glitchy-video.mp4
Let's join all our work together:
ffmpeg -i "concat:our-glitchy-video.mp4|our-glitchy-video2.mp4|our-glitchy-video3.mp4" -c:v libx264 -pix_fmt yuv420p our-video-joined-together.mp4
To update our video as we change the code:
python process_images.py video-images output-images;rm our-glitchy-video.mp4;ffmpeg -framerate 29.97 -i output-images/image-%3d.jpg -c:v libx264 -r 29.97 -pix_fmt yuv420p our-glitchy-video.mp4;open our-glitchy-video.mp4
'''
import os, sys, glob, random
os.environ["SDL_VIDEODRIVER"] = "dummy"
import pygame
if 1:
#some platforms might need to init the display for some parts of pygame.
import pygame.display
pygame.display.init()
screen = pygame.display.set_mode((1,1))
pygame.font.init()
txt = "Pygame"
font = pygame.font.Font(None, 60)
pygame_surf = font.render(txt, 1, (127,127,0))
input_dir, output_dir = sys.argv[1], sys.argv[2]
images = glob.glob(os.path.join(input_dir, 'image-*.jpg'))
print list(sorted(images))
if not images:
raise ValueError("no images in input_dir")
if not os.path.exists(output_dir):
os.mkdir(output_dir)
for i, image_path in enumerate(images):
surf = pygame.image.load(image_path)
# if not (i % (int(random.random() * 5) + 1)):
if random.random() > 0.3:
surf = pygame.transform.laplacian(surf)
if i > 50:
surf.blit(pygame_surf, surf.get_rect().center)
new_path = image_path.replace(input_dir, output_dir)
pygame.image.save(surf, new_path.replace(".png", ".jpg"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment