Skip to content

Instantly share code, notes, and snippets.

@waimus
Last active January 7, 2023 07:06
Show Gist options
  • Save waimus/83e68887ffe9719e9f230525887c659d to your computer and use it in GitHub Desktop.
Save waimus/83e68887ffe9719e9f230525887c659d to your computer and use it in GitHub Desktop.
FFMPEG cheatsheet. FFMPEG is magnificent but I don't.

FFMPEG Cheatsheet

personal cheat bookmark of ffmpeg commands I've used. I may only add new cheat whenever I duck-searched ffmpeg commands to use, which I don't use ffmpeg everyday.

Convert video to GIF

ffmpeg -ss 2 -t 9 -i input.mkv -vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif

Retrieved from: https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality

Trim video

ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mp4 -c copy output.mp4

Retrieved from: https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg

Time format is hh:mm:ss.ms

Reduce video size (bitrate/quality)

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

Modify the -crf param. Or

ffmpeg -i input.mp4 -b 800k output.mp4

Modify the -b param

Retrieved from: https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg

Merge audio and video into one file

With re-encoding:

ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4 

Without re-encoding:

ffmpeg -i video.mp4 -i audio.wav -c copy output.mkv

Retrieved from: https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg

Extract audio from a video

ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac
  • -vn means no video
  • acodec copy means to copy audio encoding from what's already on the video, but sometimes it doesn't work for me so I just leave this option.

Retrieved from: https://stackoverflow.com/questions/9913032/how-can-i-extract-audio-from-video-with-ffmpeg

Strip audio from a video

ffmpeg -i input_file.mkv -c copy -an output_file.mkv
  • use the -an flag

Retrieved from: https://superuser.com/questions/268985/remove-audio-from-video-file-with-ffmpeg

Convert audio mp3 to ogg

ffmpeg -i input.mp3 output.ogg

Probably also works with other format

Add more stuff

This list is incomplete, you can expand by invading foreign country suggesting inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment