107 lines
3.2 KiB
Python
107 lines
3.2 KiB
Python
import os
|
|
import sys
|
|
|
|
def clearScreen():
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
def convertFilesInImport():
|
|
for filename in os.listdir('input'):
|
|
#os.path.splitext(filename)[0] gets ride of file extension
|
|
#yadiff is for deinterlace
|
|
ffmpegcmd = getFfmpegPath() + " -i " + getInputPath() + filename + " -vf yadif -b " + getBitrateSetting() + " -minrate " + getBitrateSetting() + " -maxrate " + getBitrateSetting() + " -bufsize " + getBitrateSetting() + " -vcodec libx264" + getAudioSetting() + " -y " + getOutputPath() + os.path.splitext(filename)[0] + ".mp4"
|
|
os.system(ffmpegcmd)
|
|
|
|
def getFfmpegPath():
|
|
if(os.name == "nt"):
|
|
return "ffmpeg\\windows\\ffmpeg.exe"
|
|
elif(sys.platform == "darwin"):
|
|
return "ffmpeg/osx/ffmpeg"
|
|
else:
|
|
returnErrorAndExit("Your os is not supported. Try using Windows or OSX")
|
|
|
|
def getOutputPath():
|
|
if(os.name == "nt"):
|
|
return "output\\"
|
|
else:
|
|
return "output/"
|
|
|
|
def getInputPath():
|
|
if(os.name == "nt"):
|
|
return "input\\"
|
|
else:
|
|
return "input/"
|
|
|
|
def askForResolution():
|
|
inputresolution = "0"
|
|
while(inputresolution != "1" and inputresolution != "2" and inputresolution != "3" and inputresolution != "4" and inputresolution != "5" and inputresolution != "6" and inputresolution != "7" and inputresolution != "8"):
|
|
clearScreen()
|
|
print("Tell me about your source video.")
|
|
print("1. 4k at a slow frame rate (24, 25, 30)")
|
|
print("2. 1080p at a slow frame rate (24, 25, 30)")
|
|
print("3. 720p at a slow frame rate (24, 25, 30)")
|
|
print("4. 480p at a slow frame rate (24, 25, 30)")
|
|
print("5. 4k at a fast frame rate (48, 50, 60)")
|
|
print("6. 1080p at a fast frame rate (48, 50, 60)")
|
|
print("7. 720p at a fast frame rate (48, 50, 60)")
|
|
print("8. 480p at a fast frame rate (48, 50, 60)")
|
|
inputresolution = input("Please enter a number from above: ")
|
|
return inputresolution
|
|
|
|
def askForAudioOutput():
|
|
audioOutput = "0"
|
|
while(audioOutput != "1" and audioOutput != "2" and audioOutput != "3" and audioOutput != "4"):
|
|
clearScreen()
|
|
print("Tell me what you would like your audio to output as.")
|
|
print("1. For no audio")
|
|
print("2. For Mono audio")
|
|
print("3. For Stereo audio")
|
|
print("4. For 5.1 audio")
|
|
audioOutput = input("Please enter a number from above: ")
|
|
return audioOutput
|
|
|
|
def getBitrateSetting():
|
|
# Bitrates recommended from YouTube: https://support.google.com/youtube/answer/1722171?hl=en
|
|
# 4k 24, 25,30 fps
|
|
if(resolution == "1"):
|
|
return "40000k"
|
|
# 1080p 24, 25,30 fps
|
|
elif(resolution == "2"):
|
|
return "8000k"
|
|
# 720p 24, 25,30 fps
|
|
elif(resolution == "3"):
|
|
return "5000k"
|
|
# 480p 24, 25,30 fps
|
|
elif(resolution == "4"):
|
|
return "2500k"
|
|
# 4k 48, 50, 60 fps
|
|
elif(resolution == "5"):
|
|
return "55000k"
|
|
# 1080p 48, 50, 60 fps
|
|
elif(resolution == "6"):
|
|
return "12000k"
|
|
# 720p 48, 50, 60 fps
|
|
elif(resolution == "7"):
|
|
return "7500k"
|
|
# 480p 48, 50, 60 fps
|
|
elif(resolution == "8"):
|
|
return "4000k"
|
|
|
|
def getAudioSetting():
|
|
if(audio == "1"):
|
|
return " -an"
|
|
elif(audio == "2"):
|
|
return " -ab 128k"
|
|
elif(audio == "3"):
|
|
return " -ab 384k"
|
|
elif(audio == "4"):
|
|
return " -ab 512k"
|
|
|
|
|
|
def returnErrorAndExit(message):
|
|
input(message)
|
|
sys.exit()
|
|
|
|
#Run Program
|
|
resolution = askForResolution()
|
|
audio = askForAudioOutput()
|
|
convertFilesInImport() |