github twitter email rss
FFmpeg ImageMagick
0001 Jun 1
6 minutes read

FFmpeg ImageMagick

ffmped -h full

extract subtitles

ffmpeg -i Movie.mkv -map 0:s:0

instagram settings

ffmpeg -i short.avi -r 30 -pix_fmt yuv420p -c:v libx264 -profile:v baseline -level 3.0 -preset slow short_inst1.mp4

video info

ffmpeg -i

transparendy, alpha channel, webm

ffmpeg -i %04d.png -c:v libvpx -pix_fmt yuva420p -metadata:s:v:0 alpha_mode="1" output.webm

ffmpeg -i video\ v2\ 50fps\ -c:v libvpx -quality good -b:v 1M -qmin 10 -qmax 42 -maxrate 1M -cpu-used 0 -bufsize 2M -threads 4 -c:a vorbis -b:a 128k -strict -2 video\ v2\ 50fps\ alpha_hq.webm

Cut video

ffmpeg -ss 00:10:25 -t 00:0:50 -noaccurate_seek -i Fatva_\[\].avi -c copy Fatva_\[\]2.avi

ffmpeg -i /Users/wolf/Downloads/vv/Tendres\ Cousines\ \(5\).m4v -vcodec copy -acodec copy -ss 01:25:25 -t 00:00:35 8.avi

video to image series

‘C:\Program Files\WinFF\ffmpeg.exe’ -i t:\test\test.mp4 -f image2 -qscale 1 -vf fps=fps=10 2out%d.jpg
ffmpeg -i MVI_3247.MOV -f image2 -vf fps=fps=1.6 out%d.jpg

Output a single frame from the video into an image file:

ffmpeg -i input.flv -ss 00:00:14.435 -vframes 1 out.png

stop processign after seconds

-t 9

crop video

ffmpeg -i video.avi -vf crop=width:height:x:y output.avi

start from 1 second, crop video, set framerate to 10, change size, convert to gif

ffmpeg -ss 00:00:01.000 -i -vf crop=1220:580:350:350
-r 10 -pix_fmt rgb24 -s 768x432 output2.gif

ffmpeg -ss 00:11:30 -t 00:1:10 -i in.avi -c:v libx264 -preset slow -crf 20 -pix_fmt yuv420p -c:a libmp3lame -b:a 128k out.avi

gifsicle –delay=10 –loop *.gif > anim.gif


ffmpeg -i input_file.avi -codec:v libvpx -quality good -cpu-used 0 -b:v 500k -qmin 10 -qmax 42 -maxrate 500k -bufsize 1000k -threads 4 -vf scale=-1:480 -codec:a libvorbis -b:a 128k output.webm

-quality good Sets encoding speed for the VP8 encoder. This works in concert with cpu-used parameter. Available values are best, good and realtime. The official libvpx documentation strongly advises against using best quality parameter, because good with cpu-used 0 offers almost identical quality for half the encoding time

-cpu-used [0-5] Sets “speed” of encoding “ lower value uses more CPU for processing and produces better quality. Larger values trade quality for faster encoding, with 4 and 5 enabling “rate distortion optimization”, which significantly speeds-up encoding with price of big quality hit.

-b:v [bitrate] Sets desired output video bitrate

-maxrate/-bufsize Set upper limits for stream bitrate, maxrate specifying maximum bitrate and bufsize specifying device buffer size. Buffer size tells the encoder how much it can overshoot the maximum bitrate when required. Good default is twice the maxrate for approx. 2sec of buffer.

-qmin 10 -qmax 42 This sets minimum and maximum quantization values. Since as of 0.9, FFmpeg sets those values wrong by default, adding these is required for a a decent video quality. Omitting these will produce blocky broken video.

For constant bitrate, b:v, maxrate and minrate to the same values ffmpeg -i -c:v libvpx -b:v 1900K -maxrate 1900K -minrate 1900K output.webm

For variable quality with upper bound for the bitrate, set both b:v and crf
Without crf, the specified bitrate will just be taken as an average.


convert -layers Optimize output.gif output_optimized.gif

split gif frames to pngs

convert -coalesce in.gif out.png

merge images to pdf

convert page*.png mydoc.pdf


convert ‘*.jpg’ -rotate 90 2out%03d.jpg

Crop images

convert ‘*.png’ -crop x++ OutputName-%03d.png

Join images vertically

convert file1.png file2.png file3.png -append result.png

find … -exec bash -c ‘convert «$@» -append result.png’ _ {} +

convert $(find thumb* -exec echo {} ‘;’ | shuf) -append result.png


convert ‘*.JPG’ -resize «2000x» -quality 90 %03d.jpg

resize nad sharp image

convert P1020592.jpg -resize «600x» -unsharp 2x0.5+0.7+0 -quality 98 iseran_s.jpg

ls *.jpg|while read i;do gm convert $i -resize «900x» -unsharp 2x0.5+0.5+0 -quality 98 basename $i .jpg_s.jpg;done

-unsharp RadiusxSigma+Amount+Threshold
Radius : that’s the maximum distance (in pixels) ImageMagick looks around a pixel while doing the sharpening. It should be a few pixels more than sigma. If it’s less, sharpening won’t work as expected. If it’s more, it will make everything a lot slower with nearly no benefits. Don’t overthink it, just choose sigma + 2.
Sigma : this is the size of the details you want to sharpen, in pixels. This works nearly the same way as the «radius» you find in Photoshop. For sharpening a photo for display, it should be around 0.4-1.0. Do a few tries and pick what you like best.
Amount : how much sharpening is done. That’s the most important setting. Pick something you like.
Threshold : that’s mainly used to avoid sharpening noise. Leave it at 0 unless the sky or other flat areas look too noisy.

ffmpeg -v quiet # no output
ffmpeg -v error # only errors
ffmpeg -y # overwrite existing files
ffmpeg -n # exit if an output file exists
ffmpeg -an # no audio
ffmpeg -c copy # -c:v copy -c:a copy
ffmpeg -formats # list supported formats
ffmpeg -codecs # list supported media bitstream formats
ffmpeg -ar 44100
ffmpeg -ac 1 # mono
ffmpeg -map_metadata -1 # remove metadata
ffmpeg -i file.flac -aq 1 file.mp3 # `-aq 1` corresponds to -V1 in lame (use `-b:a 320k` for 320 kb/s)
brew install ffmpeg --with-fdk-aac;ffmpeg -i input.flac -c libfdk_aac -vbr 4 output.m4a # libfdk_aac is better quality than libfaac
ffmpeg -i input.flac -c:a libfaac -q 150 output.m4a # -q 10 is lowest and -q 500 is highest
ffmpeg -ss 00:01:30 -t 0:0:20 -i input.mkv -c copy output.mkv # -ss = start seek
ffmpeg -i input.mp4 -c copy audio.m4a # extract audio
ffmpeg -i input.mkv -c copy output.mp4 # change container
ffmpeg -i -c:v libx264 -preset slow -crf 20 -pix_fmt yuv420p -c:a libfdk_aac -vbr 4 output.mkv
ffmpeg -c:v libx264 -preset slow # slower but better quality than the default medium preset
ffmpeg -c:v libx264 -crf # constant rate factor (0 is lossless, 51 is the lowest quality, the default is 23, and typical values are from 18 to 28)
ffmpeg -c:v libx264 -pix_fmt yuv420p # some video players don't support yuv444p (the default format)
ffmpeg -i input.mkv -vframes 1 -ss 0:5:23 frame.png
ffmpeg -i input.mkv -ss 0:37:55 -t 0:0:5 %06d.png # save every frame between 37:55 and 38:00
ffmpeg -t 10 -f s16le -i /dev/zero 10s-silence.wav
brew install ffmpeg --with-ffplay;ffplay file.mkv
ffmpeg -i input.mkv -r 0.05 %06d.png # save an image every 20 seconds
ffmpeg -i 1.mp3 -i 2.mp3 -i 3.mp3 -filter_complex concat=n=3:v=0:a=1 -aq 1 concatenated.mp3
ffmpeg -loop 1 -i image.png -i audio.m4a -c:a copy -c:v libx264 -crf 20 -pix_fmt yuv420p -shortest output.mp4
ffmpeg -i input.mkv -i input.m4a -c copy -map 0:0 -map 1:0 output.mkv
ffmpeg -i input.mkv -c copy -filter:v scale=-1:540 output.mkv # resize (-1 keeps aspect ratio)
ffprobe -i input.mp4 # like `ffmpeg -i input.mp4` but doesn't show an error about a missing output file
ffprobe -i input.mp4|&sed -n 's/^ *Duration: \([^,]*\).*/\1/p'
ffprobe -i input.mp4 -show_streams
ffprobe -v 0 -i input.mp4 -show_streams -of csv|head -n1|cut -d, -f10,11 # width and height
ffprobe -v 0 -i "$l" -show_streams|awk -F= '$1=="duration"{print $2}'
ffmpeg -i input.mkv -an -vn -map 0:s:0 subtitles.ass # extract subtitles
ffmpeg -f lavfi -i color=c=black:s=1280x720 # use a black background
ffmpeg -i input.mp4|&awk -F'[ :,]' '$3=="Duration"{print 3600*$1+60*$2+$3}'
ffmpeg -i input.mp4 -vn -f wav -|oggenc -o audio.ogg -
ffmpeg -encoders # list encoders
ffmpeg -h encoder=libmp3lame # show help for the libmp3lame encoder
ffmpeg -f concat -i <(for f in $PWD/*.avi;do echo "file '$f'";done) -c copy output.avi
ffmpeg -i input.mp3 -filter:a atempo=1.5 output.wav # time stretch audio
ffmpeg -i input.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav
ffmpeg -i left.wav -i right.wav -filter_complex amerge output.wav
while read f;do ffmpeg -i $f ${f%flac}m4a</dev/null;done # without </dev/null ffmpeg would read from STDIN
ffmpeg -i input.wav -af volume=0.7 output.wav

Back to posts

comments powered by Disqus