Skip to content

Instantly share code, notes, and snippets.

@dill
Last active October 4, 2022 14:44
Show Gist options
  • Save dill/88cc9b997b82c6a1f624 to your computer and use it in GitHub Desktop.
Save dill/88cc9b997b82c6a1f624 to your computer and use it in GitHub Desktop.
imagemagick and ffmpeg cheatsheet
# convert mp4 to gif
# converts in.mp4 to out.gif, using 0-20s of the mp4 at resolution 640x480
ffmpeg -ss 00:00:00.000 -i in.mp4 -pix_fmt rgb24 -r 10 -s 640x480 -t 00:00:20.000 out.gif
# alternative mp4 to gif (using imagemagick for the second step)
ffmpeg -i input.mp4 -r 10 output%05d.png
convert output*.png output.gif
# strip audio out of a video file (to aac)
ffmpeg -i input_video.mp4 -vn -acodec copy output_audio.aac
# strip audio out of a video file (to mp3)
ffmpeg -i input_video.mp4 -vn output_audio.mp3
# make a PDF smaller
# https://www.reddit.com/r/RemarkableTablet/comments/8bh8gz/reducing_file_size_of_pdfs/
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=OUTPUTFILENAME.pdf INPUTFILENAME.pdf
# some recipes for imagemagick
# the * wildcard goes sequentially over files in order
# "stack" images one ontop of the other to make one long (height-wise) image
convert -append *.png out.png
# "stack" images side-by-side to make one long (width-wise) image
convert +append *.png out.png
# take a bunch of pngs and make a gif
convert -delay 5 -loop 0 *.png animated.gif
# trim the whitespace around a bunch of images (useful for plots)
mogrify -trim *.png
# trim around one image
convert image.png -fuzz 1% -trim +repage result.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment