From 05269f3284a8a9da75e0a49f3e1575afad567943 Mon Sep 17 00:00:00 2001 From: sebgab Date: Fri, 6 Aug 2021 14:10:15 +0200 Subject: [PATCH] More options --- convert.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/convert.py b/convert.py index 830c8e6..de65090 100755 --- a/convert.py +++ b/convert.py @@ -9,6 +9,7 @@ InFolder="FilesIn" OutFolder="FilesOut" # Chose actions for subs, video, audio, and images +handbrake = True SubtitleAction = "copy" AudioAction = "libvorbis" VideoAction = "h264_nvenc" @@ -20,17 +21,37 @@ 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": + + # Video + if f[-4:] == ".mkv" or f[-4:] == ".mp4": 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 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 -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 -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 + "'") + system("convert \"" + InFilePath + "\" \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"") # Print status message print("That was all the files.")