mass-video-transcode/convert.py
sebgab 47134245f5 Added support for more filetypes
Renamed it from "mass file transcode" to "mass file transcode" due to the changing nature of the script
2021-04-14 21:58:22 +02:00

40 lines
1.3 KiB
Python
Executable File

#!/usr/bin/python3
# Import the required libraries
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"
# Make a list with all the files in the appropriate folder
onlyfiles = [f for f in listdir(InFolder) if isfile(join(InFolder, f))]
# Check file type and do the appropriate action
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.")
# Thank the user
print("Thank you for using my tool!")