Skip to content

Instantly share code, notes, and snippets.

@draganmarjanovic
Last active November 24, 2015 12:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draganmarjanovic/62f41a2a592d784554af to your computer and use it in GitHub Desktop.
Save draganmarjanovic/62f41a2a592d784554af to your computer and use it in GitHub Desktop.
Convert any supported video file type to MP4.
#!/usr/bin/python
import os
from os import listdir
from os.path import isfile, join
# Preferences
supported_formats = ["mkv", "mp4", "wmv", "flv", "m4v"]
output_format = "mp4"
file_path = os.getcwd()
conversion_list = []
# File Processing and Preparation
directory_files = [f for f in listdir(file_path) if isfile(join(file_path, f))]
for x in directory_files:
if (x[-3:] in supported_formats) and (x[-3:] != output_format):
x_safe = x.replace(" ", "\ ")
conversion_list.append(x_safe)
else:
pass
# Output
for video in conversion_list:
print ("Converting: " + video[0:-4])
# os.system("touch " + video[0:-4] + ".txt")
os.system("FFmpeg -i " + video + " -vcodec copy -acodec copy " + video[0:-4] + "." + output_format)
print ("Conversion Completed")
print ("########## All Conversion Completed ##########")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment