Skip to content

Instantly share code, notes, and snippets.

@JamesDunne
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesDunne/96bbf53f15b921f88b8e to your computer and use it in GitHub Desktop.
Save JamesDunne/96bbf53f15b921f88b8e to your computer and use it in GitHub Desktop.
Creating animated GIFs from videos using ffmpeg and imagemagick
@echo off
rem http://i.bittwiddlers.org/b/KHh
rem goto extract
goto annotate
rem goto combine
:extract
rem Extract frames:
rem del /f /q glass.avi
rem ffmpeg -ss 16:29 -i "..\Rick and Morty S01E07 Raising Gazorpazorp.mkv" -ss 0:00.10 -t 0:13.90 glass.avi
ffmpeg -ss 16:29 -i "..\Rick and Morty S01E07 Raising Gazorpazorp.mkv" -ss 0:00.10 -t 0:13.90 fr%%d.png
rem goto end
:annotate
del /f /q v*.txt 2>NUL
rem I suppose
for /L %%d in (1,1,28) DO echo fr%%d.png >> v0.txt
rem ...
for /L %%d in (29,1,44) DO echo fr%%d.png >> v1.txt
rem But first,
for /L %%d in (45,1,63) DO echo fr%%d.png >> v2.txt
rem a deep sip
for /L %%d in (64,1,80) DO echo fr%%d.png >> v3.txt
rem from a very
for /L %%d in (81,1,105) DO echo fr%%d.png >> v4.txt
rem tall glass of
for /L %%d in (106,1,129) DO echo fr%%d.png >> v5.txt
rem "I told you so"
for /L %%d in (130,1,160) DO echo fr%%d.png >> v6.txt
rem ...
for /L %%d in (161,1,197) DO echo fr%%d.png >> v7.txt
rem *gulp*
for /L %%d in (198,1,208) DO echo fr%%d.png >> v8.txt
rem ...
for /L %%d in (209,1,220) DO echo fr%%d.png >> v9.txt
rem *gulp*
for /L %%d in (221,1,230) DO echo fr%%d.png >> v10.txt
rem ...
for /L %%d in (231,1,240) DO echo fr%%d.png >> v11.txt
rem *gulp*
for /L %%d in (241,1,250) DO echo fr%%d.png >> v12.txt
rem ...
for /L %%d in (251,1,260) DO echo fr%%d.png >> v13.txt
rem *gulp*
for /L %%d in (261,1,270) DO echo fr%%d.png >> v14.txt
rem ...
for /L %%d in (271,1,282) DO echo fr%%d.png >> v15.txt
rem 283,1,292 J:*gulp* M:"OH MY GOD!"
for /L %%d in (283,1,292) DO echo fr%%d.png >> v16.txt
rem 293,1,303 J:... M:"OH MY GOD!"
for /L %%d in (293,1,303) DO echo fr%%d.png >> v17.txt
rem 304,1,306 J:... M:"PLEASE, DAD!"
for /L %%d in (304,1,306) DO echo fr%%d.png >> v18.txt
rem 307,1,310 J:*gulp* M:"PLEASE, DAD!"
for /L %%d in (307,1,310) DO echo fr%%d.png >> v19.txt
rem 311,1,315 J:*gulp* M:"PLEASE, DAD!"
for /L %%d in (311,1,315) DO echo fr%%d.png >> v20.txt
rem 316,1,334 J:... M:"COME ON!"
for /L %%d in (316,1,334) DO echo fr%%d.png >> v21.txt
set CROP=-gravity southwest -crop 512x496+358+75 +repage
set ANNJ=-gravity south -fill white -stroke black -strokewidth 3 -font impact -weight bold -pointsize 58 -annotate +0+50
set ANNM=-gravity south -fill yellow -stroke black -strokewidth 3 -font impact -weight bold -pointsize 58 -annotate +0+106
SET SCALE=-scale 50.0%%
echo J:I suppose.
convert %CROP% %ANNJ% "I SUPPOSE." %SCALE% @v0.txt v0.mng
echo J:...
convert %CROP% %SCALE% @v1.txt v1.mng
echo J:But first,
convert %CROP% %ANNJ% "BUT FIRST," %SCALE% @v2.txt v2.mng
echo J:a deep sip
convert %CROP% %ANNJ% "A DEEP SIP" %SCALE% @v3.txt v3.mng
echo J:from a very
convert %CROP% %ANNJ% "FROM A VERY" %SCALE% @v4.txt v4.mng
echo J:tall glass of
convert %CROP% %ANNJ% "TALL GLASS OF" %SCALE% @v5.txt v5.mng
echo J:"I told you so."
convert %CROP% %ANNJ% """I TOLD YOU SO.""" %SCALE% @v6.txt v6.mng
echo J:...
convert %CROP% %SCALE% @v7.txt v7.mng
echo J:*gulp*
convert %CROP% %ANNJ% "*gulp*" %SCALE% @v8.txt v8.mng
echo J:...
convert %CROP% %SCALE% @v9.txt v9.mng
echo J:*gulp*
convert %CROP% %ANNJ% "*gulp*" %SCALE% @v10.txt v10.mng
echo J:...
convert %CROP% %SCALE% @v11.txt v11.mng
echo J:*gulp*
convert %CROP% %ANNJ% "*gulp*" %SCALE% @v12.txt v12.mng
echo J:...
convert %CROP% %SCALE% @v13.txt v13.mng
echo J:*gulp*
convert %CROP% %ANNJ% "*gulp*" %SCALE% @v14.txt v14.mng
echo J:...
convert %CROP% %SCALE% @v15.txt v15.mng
echo J:*gulp* M:"OH MY GOD!"
convert %CROP% %ANNJ% "*gulp*" %ANNM% "OH MY GOD!" %SCALE% @v16.txt v16.mng
echo J:... M:"OH MY GOD!"
convert %CROP% %ANNM% "OH MY GOD!" %SCALE% @v17.txt v17.mng
echo J:... M:"PLEASE, DAD!"
convert %CROP% %ANNM% "PLEASE, DAD!" %SCALE% @v18.txt v18.mng
echo J:*gulp* M:"PLEASE, DAD!"
convert %CROP% %ANNJ% "*gulp*" %ANNM% "PLEASE, DAD!" %SCALE% @v19.txt v19.mng
echo J:*gulp* M:"PLEASE, DAD!"
convert %CROP% %ANNJ% "*gulp*" %ANNM% "PLEASE, DAD!" %SCALE% @v20.txt v20.mng
echo J:... M:"COME ON!"
convert %CROP% %ANNM% "COME ON!" %SCALE% @v21.txt v21.mng
goto combine
:combine
echo Combine
convert -delay 1x24 -depth 8 -colors 255 -quantize YCbCr +dither -coalesce -layers optimize-transparency -loop 0 v0.mng v1.mng v2.mng v3.mng v4.mng v5.mng v6.mng v7.mng v8.mng v9.mng v10.mng v11.mng v12.mng v13.mng v14.mng v15.mng v16.mng v17.mng v18.mng v19.mng v20.mng v21.mng glass-v3.gif
:end
@echo off
rem http://i.bittwiddlers.org/b/KH9
rem Extract frames:
ffmpeg -ss 15:30 -i "..\Rick and Morty S01E05 Meeseeks and Destroy.mkv" -ss 0:06.61 -t 0:02.70 "fr%%02d.png"
rem Produce GIF:
convert -shave 300x0 -chop x48 -gravity south -fill yellow -stroke black -strokewidth 3 -font impact -weight bold -pointsize 52 -annotate +0+12 "OH WE'RE WELL PAST THAT, JERRY!" -resize 50%% +repage -delay 1x24 -quantize YCbCr +dither +remap -coalesce -layers optimize-transparency -depth 8 -colors 256 -loop 0 "fr*.png" meeseeks-jerry.gif
@echo off
rem http://i.bittwiddlers.org/b/KHX
rem goto extract
rem goto annotate
goto combine
:extract
rem Extract frames:
rem del /f /q retarded.avi
rem ffmpeg -i "..\S04E06 - Petarded.avi" -ss 16:21.0 -t 0:03.30 retarded.avi
ffmpeg -i "..\S04E06 - Petarded.avi" -ss 16:21.0 -t 0:03.30 "fr%%d.png"
:annotate
del /f /q part1.txt part2.txt part3.txt part4.txt part5.txt 2>NUL
for /L %%d in (6,1,7) DO echo fr%%d.png >> part1.txt
for /L %%d in (7,1,25) DO echo fr%%d.png >> part2.txt
for /L %%d in (26,1,55) DO echo fr%%d.png >> part3.txt
for /L %%d in (53,1,78) DO echo fr%%d.png >> part4.txt
for /L %%d in (79,1,80) DO echo fr%%d.png >> part5.txt
rem part 1
echo Part 1
convert -gravity southwest -crop 224x320+56+0 +repage @part1.txt part1.mng
rem "This plan"
echo Part 2
convert -gravity southwest -crop 224x320+56+0 -scale 200%% +repage -gravity south -fill yellow -stroke black -strokewidth 3 -font impact -weight bold -pointsize 52 -annotate +0+12 "THIS PLAN" -scale 50%% @part2.txt part2.mng
rem "is so perfect"
echo Part 3
convert -gravity southwest -crop 224x320+56+0 -scale 200%% +repage -gravity south -fill yellow -stroke black -strokewidth 3 -font impact -weight bold -pointsize 52 -annotate +0+12 "IS SO PERFECT" -scale 50%% @part3.txt part3.mng
rem "it's retarded"
echo Part 4
convert -gravity southwest -crop 224x320+56+0 -scale 200%% +repage -gravity south -fill yellow -stroke black -strokewidth 3 -font impact -weight bold -pointsize 52 -annotate +0+12 "IT'S RETARDED" -scale 50%% @part4.txt part4.mng
echo Part 5
convert -gravity southwest -crop 224x320+56+0 +repage @part5.txt part5.mng
:combine
echo Combine
convert -delay 1x24 -depth 8 -colors 255 -quantize YCbCr +dither -coalesce -layers optimize-transparency -loop 0 part1.mng part2.mng part3.mng part4.mng part5.mng retarded.gif
:end
@echo off
rem http://i.bittwiddlers.org/b/KHt
goto annotate
rem goto combine
:extract
rem Extract frames:
rem ffmpeg -ss 17:40 -i "..\Rick and Morty S01E05 Meeseeks and Destroy.mkv" -ss 0:03.20 -t 0:05.70 stickler.avi
ffmpeg -ss 17:40 -i "..\Rick and Morty S01E05 Meeseeks and Destroy.mkv" -ss 0:03.20 -t 0:05.70 "fr%%d.png"
:annotate
del /f /q part1.txt part2.txt part3.txt part4.txt 2>NUL
for /L %%d in (1,1,47) DO echo fr%%d.png >> part1.txt
for /L %%d in (48,1,80) DO echo fr%%d.png >> part2.txt
for /L %%d in (81,1,91) DO echo fr%%d.png >> part3.txt
for /L %%d in (92,1,137) DO echo fr%%d.png >> part4.txt
rem fr01 starts "I'm a bit of a stickler Meeseeks."
echo Part 1
convert -gravity southwest -crop 895x600+475+0 +repage -gravity south -fill yellow -stroke black -strokewidth 3 -font impact -weight bold -pointsize 52 -annotate +0+12 "I'M A BIT OF A STICKLER MEESEEKS..." -resize 50%% @part1.txt part1.mng
rem fr48 starts "What about your short game?"
echo Part 2
convert -gravity southwest -crop 895x600+475+0 +repage -gravity south -fill yellow -stroke black -strokewidth 3 -font impact -weight bold -pointsize 52 -annotate +0+12 "WHAT ABOUT YOUR SHORT GAME?!" -resize 50%% @part2.txt part2.mng
rem fr81 starts hostage part
echo Part 3
convert -gravity southwest -crop 895x600+475+0 +repage -resize 50%% @part3.txt part3.mng
rem fr92 starts "Oh my God! Oh my God!"
echo Part 4
convert -gravity southwest -crop 895x600+475+0 +repage -gravity south -fill pink -stroke black -strokewidth 3 -font impact -weight bold -pointsize 52 -annotate +0+12 "OH MY GOD! OH MY GOD!" -resize 50%% @part4.txt part4.mng
:combine
echo Combine
convert -delay 1x24 -quantize YCbCr +dither +remap -coalesce -layers optimize-transparency -depth 8 -colors 256 -loop 0 part1.mng part2.mng part3.mng part4.mng stickler.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment