Skip to content

Instantly share code, notes, and snippets.

@jeffpamer
Created March 16, 2018 19:38
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jeffpamer/f3134c5145238d0fd4752221b2d75eb7 to your computer and use it in GitHub Desktop.
Save jeffpamer/f3134c5145238d0fd4752221b2d75eb7 to your computer and use it in GitHub Desktop.
Smooth Scrubbing Web Video FFMPEG Mega Command
ffmpeg -i input.mp4 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 -an -vf "scale=-1:1440, reverse" -preset veryslow -g 2 output.mp4
// -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3
// Encode for web with a good balance of browser compatibility and compression ratio
// -an
// Strip audio tracks
// -vf "scale=-1:1440, reverse"
// Scale video to 1440px wide, maintaining aspect ratio
// And reverse the video (remove if not necessary)
// -preset veryslow
// Longer encode time on machine, better quality output
// -g 2
// SUPER IMPORTANT
// -g specifies the interval of Key Frames, in this case make every 2nd frame a Key Frame
// Standard compressed videos that just play through normally or continuously loop
// should have a low Key Frame count to save on file size. But a high number of keyframes
// is crucial for smooth scrubbing and forward/reverse playback.
// -g 1, meaning every single frame is a KeyFrame would be the smoothest, but basically doubles the file size.
// -g 2, seems like a good balance of very smooth playback with decent file size.
// -g values much higher than two will start to produce noticeable lag between key frames when scrolling.
@ryandoss
Copy link

ryandoss commented Feb 6, 2019

Glorious... bless you for this!

@yehudamakarov
Copy link

i feel like this came from a high place. thank you

@daveballan
Copy link

A very high place indeed! Thanks very much!

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