Created
April 9, 2022 17:27
-
-
Save HamousOnWheels/521f35d1aa28a72f6a264cc3816c27bb to your computer and use it in GitHub Desktop.
quick script for converting a video to gif, with the choice of resulting dimensions and framerate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import easygui, sys, os | |
| #TODO remake for multiple files | |
| try: | |
| # get input file from dragging and dropping onto the script | |
| input_file=sys.argv[1] | |
| except IndexError: | |
| # if the script is double clicked, open a file dialog | |
| input_file=easygui.fileopenbox() | |
| # getting the input filename, removing its extension and appending .gif | |
| output_file=input_file.rsplit(".",1)[0]+".gif" | |
| # asking for a framerate and width of the resulting gif. If none given, using the source | |
| input_fps=input("gif framerate (leave blank to use source): ") | |
| if input_fps: # no input causes input_fps to be False; inputting anything makes it True | |
| fps=f"fps={input_fps}, " # assembling ffmpeg's psychotic syntax | |
| else: # if no input given, blank out fps, which will cause ffmpeg to use the source framerate | |
| fps="" | |
| input_width=input("gif width (leave blank to use source): ") | |
| if input_width: | |
| width=f"scale={input_width}:-1:flags=lanczos, " | |
| else: | |
| width="" | |
| # os.system runs a terminal command | |
| # f is for paying respects and slapping the variables directly into the string | |
| # \ continues the line into the next line | |
| # encasing the string with ' ' on the outside and " " on the inside, to be able to use spaces in paths | |
| os.system(f'ffmpeg -i "{input_file}" \ | |
| -vf "{fps}{width}\ | |
| split[s0][s1]; [s0]palettegen[p]; [s1][p]paletteuse=diff_mode=rectangle" \ | |
| -loop 0 \ | |
| "{output_file}"') | |
| input("done. press any key") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment