Skip to content

Instantly share code, notes, and snippets.

@chucksplatt
Last active February 7, 2024 16:50
Show Gist options
  • Save chucksplatt/3d779dcc2bc96d0559424e25eaf81c82 to your computer and use it in GitHub Desktop.
Save chucksplatt/3d779dcc2bc96d0559424e25eaf81c82 to your computer and use it in GitHub Desktop.
ffmpeg cheat sheet
ffmpeg Cheat Sheet
-------------------------------------------
Lossless x264 compression (archive):
ffmpeg -i capture1.00.avi -c:v libx264 -preset slow -crf 0 -c:a flac -compression_level 8 capture1.mkv
Lossless x264 compression (extreme):
ffmpeg -i capture1.00.avi -c:v libx264 -preset veryslow -crf 0 -c:a flac -compression_level 12 capture1.mkv
Lossless compress audio in a video file:
ffmpeg -i capture1.00.avi -c:v copy -c:a flac -compression_level 8 capture1.mkv
Cutting file:
ffmpeg -i input.mp4 -ss 01:10:27 -to 02:18:51 -c:v copy -c:a copy output.mp4
ffmpeg -i input.mp4 -ss 01:10:27 -t 01:00:00 -c:v copy -c:a copy output.mp4
Concat files:
ffmpeg -i input-1.mkv -i input-2.avi -filter_complex "[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -c:v libx264 -preset veryslow -crf 0 -c:a flac -compression_level 8 concat_video.mkv
Transcoding to VP9:
ffmpeg -i "file.wmv" -c:v libvpx-vp9 -crf 24 -threads 2 -b:v 0 -c:a libopus -b:a 96k test-2.mkv
Keep chapters in conversion:
ffmpeg -i file.mkv -map_chapters 0 -c:v copy -c:a copy newfile.mp4
Upscale video:
ffmpeg -i input.mp4 -vf scale=1920x1080:flags=lanczos -c:v libx264 -crf 0 -c:a copy output_compress_1080p.mp4
ffmpeg -i input.mp4 -vf scale=-2:720:flags=spline -c:v libx264 -crf 0 -c:a copy output_compress_1080p.mp4
Interpolate video:
ffmpeg -i input.lowfps.hevc -vf "minterpolate=fps=60000/1001:mi_mode=blend" output.hevc
ffmpeg -i input.lowfps.hevc -vf "minterpolate=fps=60:mi_mode=mci:mc_mode=aobmc:me_mode=bidir:vsbmc=1" output.hevc
Extract audio from video:
ffmpeg -i input.mp4 -vn -c:a copy output.mka
Extract front channels audio:
ffmpeg -i 6channels.wav -af "pan=stereo|c0=FL|c1=FR" stereo.wav
Mixdown audio to stereo:
ffmpeg -i 6channels.wav -ac 2 stereo.wav
Timelapse:
ffmpeg -i input.mp4 -vf framestep=30,setpts=N/15/TB,fps=60 -c:v libx264 -an output.mp4
mkvtoolnix Commands
-------------------------------------------
Setting Aspect Ratio:
mkvpropedit.exe messing.about.with.camera.mkv -e track:1 -s display-unit=3 -s display-width=4 -s display-height=3
Batch Commands
-------------------------------------------
FOR /F "tokens=*" %G IN ('dir /b *.flac') DO ffmpeg -i "%G" -acodec mp3 "%~nG.mp3"
FOR /F "tokens=*" %G IN ('dir /b *.mka') DO ffmpeg -i "%G" -map_chapters -1 -c:a copy "%~nG.m4a"
References
-------------------------------------------
VP9 Encoding guide: http://wiki.webmproject.org/ffmpeg/vp9-encoding-guide
Google Recommended VP9 Settings: https://developers.google.com/media/vp9/settings/vod
Multi-thread Encoding: https://stackoverflow.com/questions/41372045/vp9-encoding-limited-to-4-threads
FFMpeg Audio Channel Extraction: https://trac.ffmpeg.org/wiki/AudioChannelManipulation
FFMpeg Motion Interpolation: https://ffmpeg.org/ffmpeg-filters.html#minterpolate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment