Skip to content

Instantly share code, notes, and snippets.

@Jezzamonn
Last active November 15, 2019 03:00
Show Gist options
  • Save Jezzamonn/db0b24c389911c869e9c3d5f96e4eec4 to your computer and use it in GitHub Desktop.
Save Jezzamonn/db0b24c389911c869e9c3d5f96e4eec4 to your computer and use it in GitHub Desktop.
Clever image/video editing commands
# Resize pixel art images (permanently changes source images)
mogrify -filter point -resize 200% image*
# Take a vertical image and make it square with blurry letterbox things. Uses clever filter graph stuff
ffmpeg -i input.mp4 -vf 'split [original][copy]; [copy] crop=ih*9/16:ih:iw/2-ow/2:0, scale=1280:2282, gblur=sigma=20[blurred]; [blurred][original]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2' output.mp4
# Take a bunch of images and turn them into a gif with a good palette
# (see https://www.ffmpeg.org/ffmpeg-formats.html#image2-1 for the format of $frame_pattern)
ffmpeg -f image2 -i "$frame_pattern" -filter_complex "[0:v] palettegen" -y "$palette"
ffmpeg -f image2 -i "$frame_pattern" -framerate 30 -i $palette -filter_complex "[0:v][1:v] paletteuse" -y "${out_filename}"
# Optimise a gif with gifsicle
gifsicle --optimize --colors=16 "${out_filename}" -o "${out_filename}"
# Take a bunch of images and turn them into a mp4
ffmpeg -f image2 -i "$frame_pattern" -pix_fmt yuv420p -y "${out_filename}"
# Take a bunch of images, loop them into a movie that's 6 seconds long
ffmpeg -framerate 10 -f image2 -loop 1 -i frame-%d.png -pix_fmt yuv420p -t 00:00:06 -y animation.mp4
# Do the above, but crop to be square
ffmpeg -framerate 10 -f image2 -loop 1 -i frame-%d.png -pix_fmt yuv420p -t 00:00:06 -y -vf "crop=ih:ih:(iw-ih)/3:0" animation-crop.mp4
# Add images into a gif that's 1 sec long, also scale it so it's not too big.
ffmpeg -loop 1 -framerate 10 -f image2 -i frame-%d.png -i palette.png -filter_complex "[0:v] scale=544:-1 [scaled];[scaled][1:v] paletteuse" -y -t 00:00:09.9 out.gif
# Using images in ffmpeg that aren't named frame001.png, etc:
-pattern_type glob -i '*.png'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment