ffmpeg and convert (imagemagick) crib sheet

Assembled by Paul Bourke
Started June 2018, ongoing ...

A small collection of helpful command lines for ffmpeg and convert (imagemagick). Certainly not trying to be comprehensive but a note to myself for things I seem to need to do regularly. Collated here to save myself digging around on-line and/or through the respective manuals. Hopefully others may find them useful also. If you think the following are incomplete, can be improved, or if you would like to add your own please drop me an email.


Convert mp4 to mov.

   ffmpeg -i inputmoviename -acodec copy -vcodec copy -f mov outputmoviename
Convert frames to movie using Apple animation codec
   ffmpeg -framerate 30 -i inputframes%04d.png -vcodec qtrle outputmoviename
Convert from mov to mp4
   ffmpeg -i inputmoviename -vcodec copy -acodec copy outputmoviename
Used for making mp4 for Gear VR, this was 2015, may have changed now.
   ffmpeg -framerate 30 -i inputframename%04d.png -c:v libx264 -profile:v high 
      -crf 18 -pix_fmt yuv420p outputmoviename
Extract frames
   ffmpeg -i inputmoviename -q:v 1 directoryname/outputframename%04d.tga
Extract 16 bit from greater than 8 bit movies, eg: GH5
   ffmpeg -i inputmoviename -vf "format=pix_fmts=rgb48" directoryname/outputframename%04d.png
Extract frames and scale
   ffmpeg -i inputmoviename -vf scale=2048:1080 -q:v 1 directoryname/outputframename%04d.tga
Extract frames and rotate by multiples of 90 degrees (see transpose options)
   ffmpeg -i inputmoviename -vf transpose=2 -q:v 1 directoryname/outputframename%04d.tga
Build mp4 movie from frames
   ffmpeg -r 30 -i inputframedirectory/inputframename%04d.tga -f mp4 -q:v 0 
      -vcodec mpeg4 -r 30 -b:v 5000k outputmoviename
Convert and apply remap filter
   ffmpeg -i inputmoviename -i 0001_x.pgm -i 0001_y.pgm -lavfi remap outputmoviename
Convert and apply cropping
   ffmpeg -i inputmoviename -filter:v "crop=out_w:out_h:x:y" outputmoviename
Movie encoding from frames, proposed for fulldome video using Watchout
   ffmpeg -threads auto -r 30 -i "inputframedirectory/inputframename%04d.png" -f vob 
      -vcodec mpeg2video -b:v 30000k -minrate 30000k -maxrate 30000k -g 15 -bf 2 -an 
      -trellis 2 "outputmoviename.m2v"
Movie encoding from frames with HAP codec, proposed for Vioso Wings fulldome playback.
Ensure ffmpeg is installed "with-snappy".
   ffmpeg -r 30 -i "inputframedirectory/inputframename%04d.tga" -vcodec hap 
      -format hap -r 30 outputmoviename
Movie information.
   ffmpeg -i moviename
Scale a movie.
   ffmpeg -i inputmoviename -filter:v scale=640:480 -c:a copy outputmoviename
Extract a time segment from a movie.
   ffmpeg -i inputmoviename -ss 00:00:30 -t 00:00:50 -codec copy outputmoviename
QuickTime movie to animated gif. (Contributed by Jordi VallverdĂș Alcover)
ffmpeg -ss 00:00:00.000 -i input.mov -pix_fmt rgb24 -r 10 -s 320x240 -t 00:00:10.000 output.gif
convert -layers Optimize output.gif output_optimized.gif

convert (imagemagick)

Crop, supply size and origin

   convert -crop 256x256+1024+0 inputfilename.exr outputfilename.jpg
Concatenate 2 images horizontally
   convert inputfilename1.jpg inputfilename2.jpg +append outputfilename.jpg
Concatenate 2 images vertically
   convert inputfilename1.jpg inputfilename2.jpg -append outputfilename.jpg
Specify jpeg compression quality
    convert -quality 90 -verbose inputfilename.tga outputfilename.jpg
Create pyramidal tiff
   convert inputimagename.tif -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:outputfilename.ptif'
Create an animated gif.
   convert -delay 120 -loop 0 inputframesequence*.png outputfilename.gif