Skip to content

Instantly share code, notes, and snippets.

@jamespantalones
Forked from jeffpamer/encode.sh
Created April 3, 2020 18:20
Show Gist options
  • Save jamespantalones/7e19ed338874458e868de8659ed3e823 to your computer and use it in GitHub Desktop.
Save jamespantalones/7e19ed338874458e868de8659ed3e823 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment