Created
October 22, 2012 05:42
-
-
Save kracekumar/3929886 to your computer and use it in GitHub Desktop.
convert mts 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
#! /usr/bin/env python | |
import sys | |
import os | |
#import gevent | |
def convert_to_mp4(path, new_filename, old_filename): | |
threads = 4 | |
os.chdir(path) | |
try: | |
os.system("ffmpeg -i %s -threads %d -f mp4 %s" %(old_filename, threads, new_filename)) | |
print("ffmpeg completed converting for %s" % old_filename) | |
if os.path.exists(new_filename): | |
os.remove(old_filename) | |
except: | |
raise | |
print("Something went wrong") | |
if __name__ == "__main__": | |
path = sys.argv[1] | |
if path: | |
all_files = os.listdir(path) | |
tasks = [convert_to_mp4(path, filename.split('.')[0]+'.mp4', filename) for filename in all_files if filename.endswith('.MTS')] | |
#gevent.joinall(tasks) |
Typo. Missed a .mp4:
for FILE in *.MTS; do if [ ! -f ${FILE%%.MTS}.mp4 ]; then ffmpeg -i $FILE -threads 4 -f mp4 ${FILE%%.MTS}.mp4; fi; done
os.system is deprecated. Repplaced by subprocess module
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Let's see if I can write you the bash equivalent: