Created
May 18, 2012 22:59
-
-
Save yourcelf/2728011 to your computer and use it in GitHub Desktop.
Command line wrapper for mplayer to make rifftrax syncing easier
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
#!/usr/bin/env python | |
import sys | |
import time | |
import subprocess | |
def main(vid, aud): | |
try: | |
vidproc = subprocess.Popen(["mplayer", vid], stdin=subprocess.PIPE) | |
audproc = subprocess.Popen(["mplayer", aud], stdin=subprocess.PIPE) | |
while True: | |
key = getch() | |
if ord(key) == 3: | |
raise KeyboardInterrupt | |
elif key == 'd': | |
print "Delaying video..." | |
vidproc.stdin.write(' ') | |
time.sleep(0.1) | |
vidproc.stdin.write(' ') | |
elif key == 'a': | |
print "Delaying audio..." | |
audproc.stdin.write(' ') | |
time.sleep(0.1) | |
audproc.stdin.write(' ') | |
else: | |
vidproc.stdin.write(key) | |
audproc.stdin.write(key) | |
except KeyboardInterrupt: | |
pass | |
finally: | |
vidproc.kill() | |
audproc.kill() | |
class _Getch: | |
"""Gets a single character from standard input. Does not echo to the | |
screen.""" | |
def __init__(self): | |
try: | |
self.impl = _GetchWindows() | |
except ImportError: | |
self.impl = _GetchUnix() | |
def __call__(self): return self.impl() | |
class _GetchUnix: | |
def __init__(self): | |
import tty, sys | |
def __call__(self): | |
import sys, tty, termios | |
fd = sys.stdin.fileno() | |
old_settings = termios.tcgetattr(fd) | |
try: | |
tty.setraw(sys.stdin.fileno()) | |
ch = sys.stdin.read(1) | |
finally: | |
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | |
return ch | |
class _GetchWindows: | |
def __init__(self): | |
import msvcrt | |
def __call__(self): | |
import msvcrt | |
return msvcrt.getch() | |
getch = _Getch() | |
if __name__ == "__main__": | |
main(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./mplayer-rifftrax.py video_file audio_file
Once playing, the usual mplayer keyboard commands are sent to both video and audio players.
Additionally, press 'd' to delay the video by 0.1 seconds, and 'a' to delay the audio by 0.1 seconds.