mass-video-transcode/convert.py

40 lines
1.3 KiB
Python
Raw Normal View History

2020-05-08 13:32:23 +00:00
#!/usr/bin/python3
# Import the required libraries
2020-05-08 13:32:23 +00:00
from os import listdir, system
from os.path import isfile, join
# Set the in and out folders
InFolder="FilesIn"
OutFolder="FilesOut"
# Chose actions for subs, video, audio, and images
SubtitleAction = "copy"
AudioAction = "libvorbis"
VideoAction = "h264_nvenc"
ImageAction = "jpeg"
2020-05-08 13:32:23 +00:00
# Make a list with all the files in the appropriate folder
onlyfiles = [f for f in listdir(InFolder) if isfile(join(InFolder, f))]
2020-05-08 13:32:23 +00:00
# Check file type and do the appropriate action
2020-05-08 13:32:23 +00:00
for f in onlyfiles:
InFilePath = "./" + InFolder + "/" + f
if f[-4:] == ".mkv" or f[-4:] == ".mp4" or f[-4:] == ".m4a":
print(f + " is a " + f[-3:] + " file, transcoding...")
OutFilePath = "./" + OutFolder + "/" + f[:-4] + ".mkv"
# Transcode
system("ffmpeg -loglevel 0 -i '" + InFilePath + "' -c:s " + SubtitleAction + " -c:a " + AudioAction + " -c:v " + VideoAction + " '" + OutFilePath + "' && rm '" + InFilePath + "'")
if f[-5:] == ".webp":
print(f + " is a " + f[-4:] + " file, converting...")
OutFilePath = "./" + OutFolder + "/" + f[:-4] + ImageAction
# Convert
system("convert '" + InFilePath + "' '" + OutFilePath + "' && rm '" + InFilePath + "'")
# Print status message
print("That was all the files.")
2020-05-08 13:32:23 +00:00
# Thank the user
print("Thank you for using my tool!")