From add0cf32083278376cd65d5b485b1658295979b7 Mon Sep 17 00:00:00 2001 From: sebgab Date: Fri, 8 May 2020 16:10:07 +0200 Subject: [PATCH] It now copies files that aren't WebM or mp4 to the output folder. Changed to using variables for input and output folder instead of hardcoding it in. Added more comments --- convert.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/convert.py b/convert.py index 6d33ce8..a55d447 100644 --- a/convert.py +++ b/convert.py @@ -1,24 +1,32 @@ #!/usr/bin/python3 - +# Import the required libraries from os import listdir, system from os.path import isfile, join -mypath="ImagesIn" +# Set the in and out folders +InFolder="ImagesIn" +OutFolder="ImagesOut" -onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] +# Make a list with all the files in the appropriate folder +onlyfiles = [f for f in listdir(InFolder) if isfile(join(InFolder, f))] -#print("Here are the files in the Images folder") +# Check file type and do the appropriate action for f in onlyfiles: -# print(f) -# print("Converting " + f + " from WebM to GIF.") -# system("ffmpeg.exe -i \"ImagesIn\\" + f + "\" \"ImagesOut\\" + f + ".gif\"") - print(f[-4:]) if f[-4:] == ".mp4": print(f + " is an mp4 file, converting to GIF.") - system("ffmpeg.exe -i \"ImagesIn\\" + f + "\" \"ImagesOut\\" + f[:-4] + ".gif\"") + # Convert to GIF + system("ffmpeg.exe -i \"" + InFolder + "\\" + f + "\" -nostats -loglevel 0 \"" + OutFolder + "\\" + f[:-4] + ".gif\"") elif f[-5:] == ".webm": print(f + " is a WebM file, converting to GIF.") - system("ffmpeg.exe -i \"ImagesIn\\" + f + "\" \"ImagesOut\\" + f[:-5] + ".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("And that was all the files.") +# Print status message +print("That was all the files.") + +# Thank the user +print("Thank you for using my tool!")