2020-05-08 13:32:23 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Import the required libraries
|
2020-05-08 13:32:23 +00:00
|
|
|
from os import listdir, system
|
|
|
|
|
from os.path import isfile, join
|
|
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Set the in and out folders
|
2021-04-14 19:58:22 +00:00
|
|
|
InFolder="FilesIn"
|
|
|
|
|
OutFolder="FilesOut"
|
2020-06-24 01:05:43 +00:00
|
|
|
|
2021-04-14 19:58:22 +00:00
|
|
|
# Chose actions for subs, video, audio, and images
|
2021-08-06 12:10:15 +00:00
|
|
|
handbrake = True
|
2020-06-24 01:05:43 +00:00
|
|
|
SubtitleAction = "copy"
|
|
|
|
|
AudioAction = "libvorbis"
|
2021-04-14 19:58:22 +00:00
|
|
|
VideoAction = "h264_nvenc"
|
|
|
|
|
ImageAction = "jpeg"
|
2020-05-08 13:32:23 +00:00
|
|
|
|
2020-05-08 14:10:07 +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
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Check file type and do the appropriate action
|
2020-05-08 13:32:23 +00:00
|
|
|
for f in onlyfiles:
|
2020-06-24 01:05:43 +00:00
|
|
|
InFilePath = "./" + InFolder + "/" + f
|
2023-05-19 16:04:21 +00:00
|
|
|
print("file: " + InFilePath)
|
2021-08-06 12:10:15 +00:00
|
|
|
|
|
|
|
|
# Video
|
|
|
|
|
if f[-4:] == ".mkv" or f[-4:] == ".mp4":
|
2021-04-14 19:58:22 +00:00
|
|
|
print(f + " is a " + f[-3:] + " file, transcoding...")
|
|
|
|
|
OutFilePath = "./" + OutFolder + "/" + f[:-4] + ".mkv"
|
2020-06-24 01:05:43 +00:00
|
|
|
# Transcode
|
2021-08-06 12:10:15 +00:00
|
|
|
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
|
2023-05-19 16:04:21 +00:00
|
|
|
system("ffmpeg -loglevel 0 -vn -i \"" + InFilePath + "\" -c:a " + AudioAction + " \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"")
|
2021-08-06 12:10:15 +00:00
|
|
|
|
|
|
|
|
if f[-4:] == ".m4a":
|
|
|
|
|
print(f + " is a " + f[-3:] + " file, converting...")
|
|
|
|
|
OutFilePath = "./" + OutFolder + "/" + f[:-4] + ".ogg"
|
|
|
|
|
# Transcode
|
2023-05-19 16:04:21 +00:00
|
|
|
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 + "\"")
|
2021-04-14 19:58:22 +00:00
|
|
|
|
2021-08-06 12:10:15 +00:00
|
|
|
# Images
|
2021-04-14 19:58:22 +00:00
|
|
|
if f[-5:] == ".webp":
|
|
|
|
|
print(f + " is a " + f[-4:] + " file, converting...")
|
|
|
|
|
OutFilePath = "./" + OutFolder + "/" + f[:-4] + ImageAction
|
|
|
|
|
# Convert
|
2021-08-06 12:10:15 +00:00
|
|
|
system("convert \"" + InFilePath + "\" \"" + OutFilePath + "\" && rm \"" + InFilePath + "\"")
|
2020-05-08 14:10:07 +00:00
|
|
|
|
|
|
|
|
# Print status message
|
|
|
|
|
print("That was all the files.")
|
2020-05-08 13:32:23 +00:00
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Thank the user
|
|
|
|
|
print("Thank you for using my tool!")
|