Skip to content

Instantly share code, notes, and snippets.

@NanoSmasher
Created April 18, 2022 23:21
Show Gist options
  • Save NanoSmasher/b1df3a680e8365f658f2940da5f4d0d1 to your computer and use it in GitHub Desktop.
Save NanoSmasher/b1df3a680e8365f658f2940da5f4d0d1 to your computer and use it in GitHub Desktop.
FFMPEG commands that I use often when I just want to put out OBS recorded clips without much editing on my Windows machine

Personal FFMPEG notes for Windows Command Prompt

FFMPEG commands that I use often when I just want to put out OBS recorded clips without much editing.

Basic Conversion

No arguments

ffmpeg -i INPUT.mkv OUTPUT.mp4

Mass conversion

FOR %f IN (*.mkv) DO ffmpeg -i "%f" "%~nf.mp4"

For youtube

ffmpeg -i INPUT.mp4 -vf yadif,format=yuv420p -force_key_frames "expr:gte(t,n_forced/2)" -c:v libx264 -crf 31 -bf 2 -c:a aac -q:a 1 -ac 2 -ar 48000 -use_editlist 0 -movflags +faststart OUTPUT.mp4

Trimming/Splitting/Compressing/Everything to make it smaller

default, results in weirdness

ffmpeg -ss 00:01:00 -i INPUT.mkv -t 00:04:00 -c copy OUTPUT.mkv
ffmpeg -ss 00:01:00 -i INPUT.mkv -to 00:05:00 -c copy OUTPUT.mkv

MKV's and some other file format's don't like random cuts, and creates no video/black video/broken video in the first couple seconds. Instead use this to avoids -ss break: Put -ss in front, and add avoid_negative_ts

ffmpeg -ss 00:01:00 -i INPUT.mkv -t 00:04:00 -c copy -avoid_negative_ts make_zero OUTPUT.mkv

Cut just the audio

ffmpeg -i INPUT.mkv -vn -acodec copy output.mp3

resize video

ffmpeg -i INPUT.mp4 -vf scale=640:360 OUTPUT.mp4

crop video

ffmpeg -i INPUT.mp4 -filter:v "crop=1050:840:120:0" OUTPUT.mp4

crop=width,height,x,y

Drop Video quality

ffmpeg -i INPUT.mp4 -c:v libx264 -crf 31 OUTPUT.mp4

Default when converting is 23 31 for 1080p HD video, 32 for 720p, 33 for 480p If you want as lossless as possible, -crf 18

The nuclear compression, when you want to do math to make it exactly 8MB or 50MB or whatever

  1. Note how long is the video. For example 255 seconds.
  2. (50 MiB * 8192 [converts MiB to kBit]) / 255 seconds = ~1606 kBit/s total bitrate
  3. Determine a desired audio bitrate, 126k is nice because that's YT's maximum.
  4. 1606 - 126 kBit/s (desired audio bitrate) = 1480 kBit/s video bitrate
ffmpeg -y -i INPUT.mp4 -c:v libx264 -b:v 1480k -pass 1 -an -f null NUL && ffmpeg -i INPUT.mp4 -c:v libx264 -b:v 1480k -pass 2 -c:a aac -b:a 126k OUTPUT.mp4

-c:a aac is usually paried with -c:a aac -strict experimental but it happens to run without it so I dunno.

Should I H265? No. Probably not for another 5 years because of how slow everyone is.

Merging/Other edits

merging video and audio negative if audio is before click, positive if after click

ffmpeg -i INPUT.mp4 -itsoffset -00:00:00.5 -i INPUT.mp3 -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 -shortest OUTPUT.mp4

merging two or more videos of mp4

(echo file 'INPUT1.mp4' & echo file 'INPUT2.mp4' )>list.txt
ffmpeg -safe 0 -f concat -i list.txt -c copy OUTPUT.mp4

denoise (when trying to connect aux cable to aux cable like a madman)

ffmpeg -i INPUT.mkv -af "afftdn=nt=w" OUTPUT.mp4

create a gif

ffmpeg -i INPUT.mkv -filter_complex "[0:v] fps=12,split [a][b];[a] palettegen [p];[b][p] paletteuse" OUTPUT.gif

you can also scale with [0:v] fps=12,scale=480:-1,split [a][b];

add fade in, fade out to videos If you want to do anything more, than this, a properly GUI video editor is better. Better to crop/trim first, then do this, then the final conversion. The following puts a 3 second fade in and fade out on a 423 second video.

ffmpeg -i INPUT.mp4 -filter_complex "afade=t=in:ss=0:d=3,afade=t=out:st=420:d=3;fade=t=in:st=0:d=3,fade=t=out:st=420:d=3" OUTPUT.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment