kesto.de Cheatsheets

ffmpeg

Convert WAV to MP3 with ffmpeg

ffmpeg -i example.wav -ab 192k example.mp3

Cut a video with ffmpeg

ffmpeg -sameq -ss 209 -t 26 -i XMjcCAkCNGM.flv postbank.flv

Images to video and add audio

avconv -framerate 25 -f image2 -i reverse/%05d.png -i ../out.wav -c:a libmp3lame out.mp4

Images to video using glob pattern

ffmpeg -f image2 -pattern_type glob -i '*.jpg' out.mp4

Find silence

ffmpeg -i input.mp4 -af silencedetect=noise=0.05:duration=5 -f null -

Deinterlacing + No Audio + H.264

ffmpeg -i input.dv -vcodec libx264 -filter:v yadif -an output.avi

Deinterlacing + Cropping + No Audio + H.264

ffmpeg -i dvgrab-2016.02.06_16-28-04--00\:10\:32\:18.avi -vcodec libx264 -filter:v "crop=576:576:0:0, yadif=1" -an out.avi

Cutting + Deinterlacing + Cropping + No Audio + H.264

ffmpeg -i float.avi -ss 00:00:16 -t 00:00:59 -vcodec libx264 -crf 10 -filter:v "crop=540:540:0:0, yadif=1" -an out/float.avi

Side by side with black space etc...

ffmpeg -i tmp/float_cut_dv.avi -f lavfi -i color=c=black:size=20x535 -i tmp/float_cut_dv.avi -filter_complex "[0:v:0]pad=535*2+20:ih,yadif=1[bg]; [bg][1:v:0]overlay=535[bg2]; [bg2][2:v:0]overlay=555,yadif=1" -vcodec libx264 -crf 10 -preset ultrafast test3.avi
ffmpeg -i tmp/float_cut_dv.avi -f lavfi -i color=c=black:size=20x535 -i tmp/float_cut_dv.avi -filter_complex "[0:v:0]pad=535*2+20:ih,yadif=1[bg]; [bg][1:v:0]overlay=535[bg2]; [bg2][2:v:0]overlay=555,yadif=1,crop=535*2+20:535" -vcodec libx264 -crf 10 -preset ultrafast test3.avi

Concatenation

ffmpeg -i "concat:input.avi|input.avi" -vc copy -an output.avi

Concatenation + Cutting

ffmpeg -i "concat:input.avi|input.avi" -ss 00:00:30 -t 00:01:00 -vc copy -an output.avi

Get Image from video (first frame)

ffmpeg -i input.mp4 -vframes 1 output.png

Overlay with opacity (transparency)

ffmpeg -i 1.MTS -i 2.MTS -filter_complex '[0:v][1:v] blend=shortest=1:all_mode=overlay:all_opacity=0.5' -vcodec libx264 -crf 30 -an -y result.mp4

Scaling

ffmpeg -i in.mp4 -filter:v "scale=1920:1012" out.mp4

Extract Audio

ffmpeg -i input.mp4 -vn -acodec copy audio.mp3

Capture frame from webcam

ffmpeg -y -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 -frames 1 "output_$(date '+%Y%m%d_%H%M%S').jpg"

No Audio

ffmpeg ... -an ...

Fix DV AVI with wrong audio sample rate using ffmpeg and sox:

ffmpeg -i "$1" -vn -c:a copy /tmp/dv_audio.wav
sox -r 48k /tmp/dv_audio.wav /tmp/dv_audio_48k.wav
ffmpeg -i "$1" -i /tmp/dv_audio_48k.wav -c:v copy -c:a copy -map 0:v:0 -map 1:a:0 "$1.fixed.avi"

Videostill

ffmpeg -ss 0:48 -i 00034.MTS -frames 1 34_00-48.jpg

Encode video using H.264 + AAC + 420

ffmpeg -i input.mov -c:v libx264 -c:a aac -pix_fmt yuv420p output.yuv420p.h264.aac.mp4

Encode video using deinterlacing + H.264 + AAC + 420

ffmpeg -i in.mp4 -filter:v yadif -c:a aac -c:v libx264 -pix_fmt yuv420p out.aac.h264.mp4