video-to-gif-converter/convert.py

33 lines
1.1 KiB
Python
Raw Permalink 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="ImagesIn"
OutFolder="ImagesOut"
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:
if f[-4:] == ".mp4":
print(f + " is an mp4 file, converting to GIF.")
# Convert to GIF
system("ffmpeg.exe -i \"" + InFolder + "\\" + f + "\" -nostats -loglevel 0 \"" + OutFolder + "\\" + f[:-4] + ".gif\"")
2020-05-08 13:32:23 +00:00
elif f[-5:] == ".webm":
print(f + " is a WebM file, converting to GIF.")
# Convert to GIF
system("ffmpeg.exe -i \"" + InFolder + "\\" + f + "\" -nostats -loglevel 0 \"" + OutFolder + "\\" + f[:-5] + ".gif\"")
else:
print(f + " is not an mp4 or WebM file, copying image.")
system("copy /V \"" + InFolder + "\\" + f + "\" \"" + OutFolder + "\\" + f + "\"")
# 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!")