Skip to content

Examples

Matt McManis edited this page May 30, 2020 · 18 revisions
TOC

Video

Video CRF

ffmpeg

-i input.avi 

-c:v libx264 
-preset slow -crf 16 -pix_fmt yuv420p -qcomp 0.8 
-vf scale=trunc(iw/2)*2:trunc(ih/2)*2 
-map 0:v? -map_chapters 0 

-c:s copy 
-map 0:s? 

-c:a ac3 
-b:a 320k 
-map 0:a? 

-map_metadata 0 
 
output.mkv

Video One-Pass

ffmpeg

-i input.avi 

-c:v libx264 
-preset medium -b:v 3M -maxrate 3M -pix_fmt yuv420p -qcomp 0.8 
-vf scale=trunc(iw/2)*2:trunc(ih/2)*2 
-map 0:v? -map_chapters 0 

-c:s copy 
-map 0:s? 

-c:a ac3 
-b:a 320k 
-map 0:a? 

-map_metadata 0 

output.mkv

Video Two-Pass

ffmpeg

-i input.avi 

-c:v libx264 
-preset medium -b:v 3M -pix_fmt yuv420p 
-vf scale=trunc(iw/2)*2:trunc(ih/2)*2 
-pass 1 

-sn -an  

-f matroska 

NUL

&& 

ffmpeg

-i input.avi  

-c:v libx264 
-preset medium -b:v 3M -pix_fmt yuv420p 
-vf scale=trunc(iw/2)*2:trunc(ih/2)*2 
-map 0:v? -map_chapters 0 
-pass 2 

-c:s copy 
-map 0:s? 

-c:a ac3 
-b:a 320k 
-map 0:a? 

-map_metadata 0 

output.mkv

Video to MP4 x264

ffmpeg

-i input.avi 

-c:v libx264 
-preset slow -crf 16 -pix_fmt yuv420p -qcomp 0.8 
-vf scale=trunc(iw/2)*2:trunc(ih/2)*2 
-map 0:v:0? -map_chapters 0 

-c:s mov_text 
-map 0:s? 

-c:a ac3 
-b:a 320k 
-map 0:a? 

-map_metadata 0 

output.mp4

Video to HEVC x265

ffmpeg

-i input.mp4 

-c:v libx265 
-preset slow -x265-params crf=20 -pix_fmt yuv420p 
-vf scale=trunc(iw/2)*2:trunc(ih/2)*2 
-map 0:v? -map_chapters 0 

-c:s copy 
-map 0:s? 

-c:a aac 
-b:a 400k 
-map 0:a? 

-map_metadata 0 

output.mkv

Video to AV1

ffmpeg

-i input.mp4 

-c:v libaom-av1 -strict experimental 
-cpu-used 1 -crf 16 -pix_fmt yuv420p 
-map 0:v? -map_chapters 0 

-c:s copy 
-map 0:s? 

-c:a aac 
-b:a 400k 
-map 0:a? 

-map_metadata 0 

output.mkv

Video to WEBM

ffmpeg

-i input.mp4 

-c:v libvpx 
-quality good -cpu-used 0 -b:v 2M -crf 12 -pix_fmt yuv420p 
-movflags faststart 
-map 0:v:0? -map_chapters -1 
-sn 

-c:a libvorbis 
-rematrix_maxval 1.0 -ac 2 -ar 44100 -q:a 6 
-map 0:a:0? 

-map_metadata 0 

output.webm

Video to OGV

ffmpeg

-i input.mp4 

-c:v libtheora -q:v 10 -pix_fmt yuv420p 
-map 0:v? -map_chapters 0 
-sn 

-c:a libvorbis 
-q:a 9 
-map 0:a? 

-map_metadata 0 

output.ogv

Video to MP3

ffmpeg

-i input.mp4 

-vn -sn 

-c:a libmp3lame 
-ac 2 -ar 44100 -b:a 320k -joint_stereo 1 
-map 0:a:0? 

-map_metadata 0 -id3v2_version 3 

output.mp3

Video Batch

cd /d "C:\Input\" 

&& for %f in (*.avi) do (

ffmpeg

"C:\Input\%~f" 

-c:v libx264 
-preset slow -crf 16
-vf scale=trunc(iw/2)*2:trunc(ih/2)*2 
-map 0:v:0? -map_chapters 0 

-c:s mov_text 
-map 0:s? 

-c:a aac 
-b:a 320k 
-map 0:a? 

-map_metadata 0 

"C:\Output\%~nf.mp4"
)

Image

Screenshot

JPG

ffmpeg

-i input.mp4 

-c:v mjpeg
-pix_fmt yuvj444p 
-q:v 2 
-vframes 1 
-sn 
-an 

-ss 00:08:32.000 

output.jpg

PNG

ffmpeg

-i input.mp4 

-c:v png 
-pix_fmt rgb24 
-vframes 1 
-sn 
-an 

-ss 00:08:32.000 

output.png

Image Sequence

ffmpeg

-i input.mp4 

-c:v mjpeg 
-q:v 4 
-pix_fmt yuvj444p 
-sn 
-an 

-ss 00:00:00.000 -to 00:00:30.000 

image-%03d.jpg

Audio

Audio to MP3

ffmpeg

-i input.flac 

-c:a libmp3lame 
-ac 2 -ar 44100 -b:a 320k -joint_stereo 1 

-map_metadata 0 -id3v2_version 3 

output.mp3

VBR

-ac 2 -ar 44100 -q:a 0 -joint_stereo 1

Audio to M4A

ffmpeg

-i input.mp3

-c:a aac 
-b:a 320k -ar 44100 -ac 2 

-map_metadata 0 

output.m4a

VBR

-ac 2 -q:a 2 -ar 44100

Audio to OGG

ffmpeg

-i input.mp3

-c:a libopus 
-ac 2 -b:a 320k 

-map_metadata 0 

output.ogg

VBR

-ac 2 -vbr on -compression_level 10 -b:a 256k

Audio to FLAC

ffmpeg

-i input.wav

-c:a flac 

-map_metadata 0 

output.flac

Audio to Apple Lossless

ffmpeg

-i input.flac 

-c:a alac 

-map_metadata 0 

output.m4a

Audio Batch

cd /d "C:\Input\" 

&& for %f in (*.wav) do (

ffmpeg

"C:\Input\%~f" 

-c:a libmp3lame 
-ac 2 -ar 44100 -b:a 320k -joint_stereo 1 
-map 0:a:0? 

-map_metadata 0 -id3v2_version 3 

"C:\Output\%~nf.mp3"
)