#!/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 handbrake = True 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 print("file: " + InFilePath) # Video if f[-4:] == ".mkv" or f[-4:] == ".mp4": print(f + " is a " + f[-3:] + " file, transcoding...") OutFilePath = "./" + OutFolder + "/" + f[:-4] + ".mkv" # Transcode if handbrake: system("HandBrakeCLI -i \"" + InFilePath + "\" -o \"" + OutFilePath + "\" -e nvenc_h264 -q 22 -E vorbis -s 1 --subtitle-default none --verbose 0 && rm \"" + InFilePath + "\"") #system("HandBrakeCLI -i \"" + InFilePath + "\" -o \"" + OutFilePath + "\" -e nvenc_h264 -q 22 -E vorbis --all-audio --all-subtitles --subtitle-default none --verbose 0 && rm \"" + InFilePath + "\"") else: system("ffmpeg -loglevel 0 -i \"" + InFilePath + "\" -c:s " + SubtitleAction + " -c:a " + AudioAction + " -c:v " + VideoAction + " \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"") # Audio if f[-5:] == ".opus": print(f + " is a " + f[-4:] + " file, converting...") OutFilePath = "./" + OutFolder + "/" + f[:-5] + ".ogg" # Transcode system("ffmpeg -loglevel 0 -vn -i \"" + InFilePath + "\" -c:a " + AudioAction + " \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"") if f[-4:] == ".m4a": print(f + " is a " + f[-3:] + " file, converting...") OutFilePath = "./" + OutFolder + "/" + f[:-4] + ".ogg" # Transcode system("ffmpeg -loglevel 0 -vn -i \"" + InFilePath + "\" -c:a " + AudioAction + " \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"") # If we run it through again, we convert the OGG to an MP3 if f[-4:] == ".ogg": print(f + " is a " + f[-3:] + " file, converting...") OutFilePath = "./" + OutFolder + "/" + f[:-4] + ".mp3" # Transcode system("ffmpeg -loglevel 0 -vn -i \"" + InFilePath + "\" -c:a " + "libmp3lame" + " \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"") if f[-5:] == ".webm": print(f + " is a " + f[-4:] + " file, converting...") OutFilePath = "./" + OutFolder + "/" + f[:-5] + ".ogg" # Transcode system("ffmpeg -loglevel 0 -vn -i \"" + InFilePath + "\" -c:a " + AudioAction + " \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"") # Images 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!")