Last active
December 12, 2015 09:09
-
-
Save nanaze/4749750 to your computer and use it in GitHub Desktop.
convert video files to mp4
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
import os | |
import logging | |
import subprocess | |
import tempfile | |
import shutil | |
def convert(src, dest): | |
_, temp_dest = tempfile.mkstemp(suffix='.mp4') | |
assert os.path.exists(src), src + ' does not exist' | |
# | |
# | |
subprocess.check_call(['HandbrakeCLI', '-i', src, '-o', temp_dest]) | |
shutil.move(temp_dest, dest) | |
def main(): | |
logging.basicConfig(level=logging.DEBUG) | |
for filename in os.listdir('.'): | |
root, ext = os.path.splitext(filename) | |
if ext in ['.mov', '.avi']: | |
dest = (root + '.mp4') | |
if os.path.exists(dest): | |
logging.info('File exists, skipping. %s', dest) | |
else: | |
logging.info('Converting file %s to %s', filename, dest) | |
convert(filename, dest) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment