Skip to content

Instantly share code, notes, and snippets.

@janily
Forked from jeffpamer/encode.sh
Created August 8, 2021 15:24
Show Gist options
  • Save janily/19e762ac9aab6a50350ede51b065eb53 to your computer and use it in GitHub Desktop.
Save janily/19e762ac9aab6a50350ede51b065eb53 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