Last active
January 14, 2022 09:00
-
Star
(124)
You must be signed in to star a gist -
Fork
(17)
You must be signed in to fork a gist
-
-
Save rock3r/a923a79e8d8a850911aa to your computer and use it in GitHub Desktop.
Revisions
-
rock3r revised this gist
Oct 10, 2016 . 1 changed file with 13 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,13 +17,14 @@ def look_for_ffmpeg_or_abort(): ffmpeg_path = find_executable('ffmpeg') if ffmpeg_path == None: print "** ComputerSaysNoError **" print "You need to have ffmpeg installed on your system and on the path for Giffify to work" exit(1) def parse_cli_arguments(): parser = argparse.ArgumentParser(description='Processes a video into a gif.') parser.add_argument('video', type=str, help='The video to be processed') parser.add_argument('-r', '--rotate', dest='rotate', action='store_true', help='Rotate output 270 degrees clockwise (useful for Genymotion)') parser.add_argument('-o', '--outfile', type=str, help='Target path') parser.add_argument('-dw', '--desired-width', type=int, default=-1) parser.add_argument('-dh', '--desired-height', type=int, default=-1) @@ -65,10 +66,15 @@ def insert_before_output_path(args, elements): e = args.end_time d = args.duration if args.rotate: rotate_filters = "transpose=2," else: rotate_filters = "" filters = "fps={fps},scale={dw}:{dh}:flags=lanczos".format(fps = fps, dw = dw, dh = dh) output_filters = "{rotate}{filters} [x]; [x][1:v] paletteuse".format(filters = filters, rotate = rotate_filters) palette_filters = "{rotate}{filters},palettegen".format(filters = filters, rotate = rotate_filters) palette_path = get_palette_path() ffmpeg_args_palette = ['ffmpeg', @@ -92,10 +98,10 @@ def insert_before_output_path(args, elements): if d != -1: ffmpeg_args_gif = insert_before_output_path(ffmpeg_args_gif, ["-t", str(d)]) print "First pass: extracting colour palette, hang tight..." subprocess.call(ffmpeg_args_palette) print "Second pass: converting that nice video into a sweet, high quality gif..." subprocess.call(ffmpeg_args_gif) print "Done! Now go and show off to your friends and colleagues" -
rock3r revised this gist
Aug 5, 2016 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,8 +17,8 @@ def look_for_ffmpeg_or_abort(): ffmpeg_path = find_executable('ffmpeg') if ffmpeg_path == None: print("** ComputerSaysNoError **") print("You need to have ffmpeg installed on your system and on the path for Giffify to work" ) exit(1) def parse_cli_arguments(): @@ -92,10 +92,10 @@ def insert_before_output_path(args, elements): if d != -1: ffmpeg_args_gif = insert_before_output_path(ffmpeg_args_gif, ["-t", str(d)]) print("First pass: extracting colour palette, hang tight...") subprocess.call(ffmpeg_args_palette) print("Second pass: converting that nice video into a sweet, high quality gif...") subprocess.call(ffmpeg_args_gif) print("Done! Now go and show off to your friends and colleagues") -
rock3r revised this gist
Mar 3, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ # this notice you can do whatever you want with this stuff. If we meet some day, # and you think this stuff is worth it, you can buy us a beer in return. if ! which "ffmpeg" > /dev/null 2>&1; then echo "You need ffmpeg in your path to run giffify" >&2 exit 1 fi -
rock3r revised this gist
Mar 3, 2016 . 2 changed files with 78 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ #!/usr/bin/python # License for any modification to the original (linked below): # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ #!/bin/bash # License for any modification to the original (linked below): # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # Sebastiano Poggi and Daniele Conti wrote this file. As long as you retain # this notice you can do whatever you want with this stuff. If we meet some day, # and you think this stuff is worth it, you can buy us a beer in return. if ! hash "ffmpeg" > /dev/null 2>&1; then echo "You need ffmpeg in your path to run giffify" >&2 exit 1 fi show_usage() { echo "Usage:" echo "" echo "giffify -i input_path.mp4 -o output_path.gif [-w width] [-y height] [-f fps=15] [-h shows this message]" } input_path="" output_path="" dw=-1 dh=-1 fps=15 while getopts ":i:o:w:y:f:h" opt; do case $opt in i ) input_path=$OPTARG ;; o ) output_path=$OPTARG ;; w ) dw=$OPTARG ;; y ) dh=$OPTARG ;; f ) fps=$OPTARG ;; h ) show_usage exit 0 ;; \? ) echo "Argument $OPTARG not recognized." >&2 exit 1 ;; : ) echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; esac done if [[ -z "$input_path" ]]; then echo "You must specify an input file to process" echo "" show_usage exit 1 fi if [[ -z "$output_path" ]]; then output_path="$input_path.gif" fi palette="palette.png" filters="fps=$fps,scale=$dw:$dh:flags=lanczos" ffmpeg -v warning -i $input_path -vf "$filters,palettegen" -y $palette if [[ -f $palette ]]; then ffmpeg -v warning -i $input_path -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $output_path rm $palette fi -
rock3r revised this gist
Mar 3, 2016 . 1 changed file with 38 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,30 @@ import argparse, sys, subprocess, tempfile from os.path import splitext from distutils.spawn import find_executable def look_for_ffmpeg_or_abort(): ffmpeg_path = find_executable('ffmpeg') if ffmpeg_path == None: print "** ComputerSaysNoError **" print "You need to have ffmpeg installed on your system and on the path for Giffify to work" exit(1) def parse_cli_arguments(): parser = argparse.ArgumentParser(description='Processes a video into a gif.') parser.add_argument('video', type=str, help='The video to be processed') parser.add_argument('-o', '--outfile', type=str, help='Target path') parser.add_argument('-dw', '--desired-width', type=int, default=-1) parser.add_argument('-dh', '--desired-height', type=int, default=-1) parser.add_argument('-fps', type=int, default=15, help='Output frames per second. Default: 15 fps') parser.add_argument('-s', '--start-time', type=int, default=-1, help='Start timestamp, as [-][HH:]MM:SS[.m...] or [-]S+[.m...]') parser.add_argument('-e', '--end-time', type=int, default=-1, help='End timestamp, as [-][HH:]MM:SS[.m...] or [-]S+[.m...]. Overridden by -d') parser.add_argument('-d', '--duration', type=int, default=-1, help='Duration, as [-][HH:]MM:SS[.m...] or [-]S+[.m...]. Overrides -e') return parser.parse_args() def gif_path(path): return splitext(path)[0] + '.gif' @@ -23,34 +47,26 @@ def insert_before_output_path(args, elements): index = args.index('-y') return args[:index] + elements + args[index:] look_for_ffmpeg_or_abort() args = parse_cli_arguments() input_path = args.video output_path = gif_path(input_path) if args.outfile is None else args.outfile fps = args.fps dw = args.desired_width dh = args.desired_height s = args.start_time e = args.end_time d = args.duration filters = "fps={fps},scale={dw}:{dh}:flags=lanczos".format(fps = fps, dw = dw, dh = dh) palette_filters = "{filters},palettegen".format(filters = filters) output_filters = "{filters} [x]; [x][1:v] paletteuse".format(filters = filters) palette_path = get_palette_path() @@ -75,5 +91,10 @@ def insert_before_output_path(args, elements): if d != -1: ffmpeg_args_gif = insert_before_output_path(ffmpeg_args_gif, ["-t", str(d)]) print "First pass: extracting colour palette, hang tight..." subprocess.call(ffmpeg_args_palette) print "Second pass: converting that nice video into a sweet, high quality gif..." subprocess.call(ffmpeg_args_gif) print "Done! Now go and show off to your friends and colleagues" -
rock3r revised this gist
Mar 3, 2016 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -75,8 +75,5 @@ def insert_before_output_path(args, elements): if d != -1: ffmpeg_args_gif = insert_before_output_path(ffmpeg_args_gif, ["-t", str(d)]) subprocess.call(ffmpeg_args_palette) subprocess.call(ffmpeg_args_gif) -
rock3r revised this gist
Mar 3, 2016 . 1 changed file with 38 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,12 +19,19 @@ def get_palette_path(): finally: palette_file.close() def insert_before_output_path(args, elements): index = args.index('-y') return args[:index] + elements + args[index:] parser = argparse.ArgumentParser(description='Processes a video into a gif.') parser.add_argument('video', type=str, help='The video to be processed') parser.add_argument('-o', '--outfile', type=str, help='Target path') parser.add_argument('-dw', '--desired-width', type=int, default=-1) parser.add_argument('-dh', '--desired-height', type=int, default=-1) parser.add_argument('-fps', type=int, default=15, help='Output frames per second. Default: 15 fps') parser.add_argument('-s', '--start-time', type=int, default=-1, help='Start timestamp, as [-][HH:]MM:SS[.m...] or [-]S+[.m...]') parser.add_argument('-e', '--end-time', type=int, default=-1, help='End timestamp, as [-][HH:]MM:SS[.m...] or [-]S+[.m...]. Overridden by -d') parser.add_argument('-d', '--duration', type=int, default=-1, help='Duration, as [-][HH:]MM:SS[.m...] or [-]S+[.m...]. Overrides -e') args = parser.parse_args() @@ -37,11 +44,39 @@ def get_palette_path(): dw = args.desired_width dh = args.desired_height s=args.start_time e=args.end_time d=args.duration filters="fps={fps},scale={dw}:{dh}:flags=lanczos".format(fps=fps, dw=dw, dh=dh) palette_filters="{filters},palettegen".format(filters=filters) output_filters="{filters} [x]; [x][1:v] paletteuse".format(filters=filters) palette_path = get_palette_path() ffmpeg_args_palette = ['ffmpeg', '-v', 'warning', '-i', input_path, '-vf', palette_filters, '-y', palette_path] ffmpeg_args_gif = ['ffmpeg', '-v', 'warning', '-i', input_path, '-i', palette_path, '-lavfi', output_filters, '-y', output_path] if s != -1: ffmpeg_args_gif = insert_before_output_path(ffmpeg_args_gif, ["-ss", str(s)]) if e != -1: ffmpeg_args_gif = insert_before_output_path(ffmpeg_args_gif, ["-to", str(e)]) if d != -1: ffmpeg_args_gif = insert_before_output_path(ffmpeg_args_gif, ["-t", str(d)]) print(ffmpeg_args_palette) print(ffmpeg_args_gif) subprocess.call(ffmpeg_args_palette) subprocess.call(ffmpeg_args_gif) -
rock3r revised this gist
Jan 8, 2016 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,6 @@ # this notice you can do whatever you want with this stuff. If we meet some day, # and you think this stuff is worth it, you can buy us a beer in return. import argparse, sys, subprocess, tempfile from os.path import splitext @@ -42,7 +41,6 @@ def get_palette_path(): palette_filters="{filters},palettegen".format(filters=filters) output_filters="{filters} [x]; [x][1:v] paletteuse".format(filters=filters) palette_path = get_palette_path() subprocess.call(['ffmpeg', '-v', 'warning', '-i', input_path, '-vf', palette_filters, '-y', palette_path]) -
rock3r revised this gist
Jan 8, 2016 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -38,10 +38,6 @@ def get_palette_path(): dw = args.desired_width dh = args.desired_height filters="fps={fps},scale={dw}:{dh}:flags=lanczos".format(fps=fps, dw=dw, dh=dh) palette_filters="{filters},palettegen".format(filters=filters) output_filters="{filters} [x]; [x][1:v] paletteuse".format(filters=filters) -
rock3r revised this gist
Jan 8, 2016 . 2 changed files with 53 additions and 32 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ #!/usr/bin/python # License for any modification to the original (linked below): # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # Sebastiano Poggi and Daniele Conti wrote this file. As long as you retain # this notice you can do whatever you want with this stuff. If we meet some day, # and you think this stuff is worth it, you can buy us a beer in return. import argparse, sys, subprocess, tempfile from os.path import splitext def gif_path(path): return splitext(path)[0] + '.gif' def get_palette_path(): try: palette_file = tempfile.NamedTemporaryFile() return palette_file.name + '.png' finally: palette_file.close() parser = argparse.ArgumentParser(description='Processes a video into a gif.') parser.add_argument('video', type=str, help='The video to be processed') parser.add_argument('-o', '--outfile', type=str, help='Target path') parser.add_argument('-dw', '--desired-width', type=int, default=-1) parser.add_argument('-dh', '--desired-height', type=int, default=-1) parser.add_argument('-fps', type=int, default=15) args = parser.parse_args() input_path = args.video output_path = gif_path(input_path) if args.outfile is None else args.outfile fps = args.fps dw = args.desired_width dh = args.desired_height if dw is -1 and dh is -1: print >>sys.stderr, "You must choose at least one between height and width" exit(1) filters="fps={fps},scale={dw}:{dh}:flags=lanczos".format(fps=fps, dw=dw, dh=dh) palette_filters="{filters},palettegen".format(filters=filters) output_filters="{filters} [x]; [x][1:v] paletteuse".format(filters=filters) palette_path = get_palette_path() subprocess.call(['ffmpeg', '-v', 'warning', '-i', input_path, '-vf', palette_filters, '-y', palette_path]) subprocess.call(['ffmpeg', '-v', 'warning', '-i', input_path, '-i', palette_path, '-lavfi', output_filters, '-y', output_path]) 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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +0,0 @@ -
rock3r revised this gist
Jul 4, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,9 +2,9 @@ # License for any modification to the original (linked below): # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # Sebastiano Poggi wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return. # ---------------------------------------------------------------------------- # # Based upon http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html -
rock3r revised this gist
Jul 3, 2015 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,13 @@ #!/bin/sh # License for any modification to the original (linked below): # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # <[email protected]> wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp # ---------------------------------------------------------------------------- # # Based upon http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html # Usage: giffify.sh inputFile outputFile [targetHeight] [targetFps] # Defaults: defaultHeight = 500px, targetFps = 15 -
rock3r created this gist
Jul 3, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #!/bin/sh # Originally from http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html # Usage: giffify.sh inputFile outputFile [targetHeight] [targetFps] # Defaults: defaultHeight = 500px, targetFps = 15 inputFile="$1" outputFile="$2" desiredHeight=$3 if [[ -z $desiredHeight ]]; then desiredHeight=500 fi fps=$4 if [[ -z $fps ]]; then fps=15 fi palette="palette.png" filters="fps=$fps,scale=-1:$desiredHeight:flags=lanczos" ffmpeg -v warning -i $inputFile -vf "$filters,palettegen" -y $palette if [[ -f $palette ]]; then ffmpeg -v warning -i $inputFile -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $outputFile rm $palette fi