Created
January 18, 2014 21:16
-
-
Save drassi/8496594 to your computer and use it in GitHub Desktop.
Yooouuutuuube emulator, just generates ffmpeg params with python
This file contains 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
# Example usage: | |
# youtube-dl https://www.youtube.com/watch?v=2XY3AvVgDns -o 'beyonce-countdown.mp4' | |
# python yooouuutuuube.py beyonce-countdown.mp4 beyonce-countdown-party.mp4 --width=1280 --height=720 --split=5 --delay=0.04 | |
# open beyonce-countdown-party.mp4 | |
import os | |
import sys | |
def yooouuutuuube(infile, outfile, total_width, total_height, n, delay): | |
width, height = total_width/n, total_height/n | |
cmd = 'ffmpeg ' | |
cmd += ('-i ' + infile + ' ') * n * n | |
cmd += '-filter_complex "nullsrc=size=' | |
cmd += '%dx%d' % (total_width, total_height) + ' [v0]; ' | |
for tile in range(n*n): | |
cmd += '[%d:v] setpts=PTS-STARTPTS+%f/TB' % (tile, delay * tile) | |
cmd += ', scale=%dx%d [tile%d]; ' % (width, height, tile) | |
tile = 0 | |
for row in range(n): | |
for col in range(n): | |
shortest = 'shortest=1:' if tile+1 == n*n else '' | |
cmd += '[v%d][tile%d] overlay=%sx=%d:y=%d ' % (tile, tile, shortest, width*col, height*row) | |
if tile+1 != n*n: | |
cmd += ' [v%s]; ' % (tile+1) | |
tile += 1 | |
cmd += '" -y %s' % outfile | |
os.system(cmd) | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser(description='Mosaic a video a la http://www.yooouuutuuube.com/v/?yt=BBAtAM7vtgc&width=192&height=120&flux=0&direction=top_right') | |
parser.add_argument('infile') | |
parser.add_argument('outfile') | |
parser.add_argument('--width', type=int, help='width of input video') | |
parser.add_argument('--height', type=int, help='height of input video') | |
parser.add_argument('--split', default=4, type=int, help='number of tiles to divide into per side (4 will create a 16-tile video)') | |
parser.add_argument('--delay', default=0.05, type=float, help='seconds to delay each tile by') | |
args = parser.parse_args() | |
yooouuutuuube(args.infile, args.outfile, args.width, args.height, args.split, args.delay) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah I have no idea what I'm doing at all. But that's fine! This probably did work with python 2.3 or something. And all the bones to make it go brrr are there. Hell it probably works now. But I'm just making my first steps into learning coding. So this will be a good benchmark of my own progression through the learning process.