Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sugardayfox/67c9d9ac5770a8bafe9f33198939d97e to your computer and use it in GitHub Desktop.
Save sugardayfox/67c9d9ac5770a8bafe9f33198939d97e to your computer and use it in GitHub Desktop.
Use FFmpeg to resize and generate .mp4 & .webm videos from any source video.
/**
Scaling
- Scale can be used as is which will set the height to 560 but keep aspect ratio for width.
- Other options include setting both with & height
- Watch out for sizing errors when not divisible by 2
**/
/** MP4 1st pass **/
ffmpeg -i input.mov -vcodec libx264 -vprofile high -preset veryslow -b:v 225k -maxrate 300k -bufsize 1000k -vf scale=-1:560 -threads 2 -pass 1 -an -f mp4 /dev/null
/** MP4 with audio 2nd pass **/
ffmpeg -i input.mov -vcodec libx264 -vprofile high -preset veryslow -b:v 225k -maxrate 300k -bufsize 1000k -vf scale=-1:560 -threads 2 -pass 2 -acodec libvo_aacenc -b:a 128k -f mp4 output_file.mp4
/** MP4 without audio 2nd pass **/
ffmpeg -i input.mov -vcodec libx264 -vprofile high -preset veryslow -b:v 225k -maxrate 300k -bufsize 1000k -vf scale=-1:560 -threads 2 -pass 2 -an -f mp4 output_file.mp4
/* Generate single image from first frame of video, scale and save as jpg */
ffmpeg -i input.mov -vframes 1 -vf scale=-1:560 testimg.jpg
/** webm 1st pass **/
ffmpeg -i input.mov -codec:v libvpx -quality good -cpu-used 0 -b:v 225k -qmin 10 -qmax 42 -maxrate 300k -bufsize 1000k -threads 2 -vf scale=-1:560 -an -pass 1 -f webm /dev/null
/** webm 2st pass with audio **/
ffmpeg -i input.mov -codec:v libvpx -quality good -cpu-used 0 -b:v 225k -qmin 10 -qmax 42 -maxrate 300k -bufsize 1000k -threads 2 -vf scale=-1:560 -codec:a libvorbis -b:a 128k -pass 2 -f webm output.webm
/** webm 2st pass without audio **/
ffmpeg -i input.mov -codec:v libvpx -quality good -cpu-used 0 -b:v 225k -qmin 10 -qmax 42 -maxrate 300k -bufsize 1000k -threads 2 -vf scale=-1:560 -pass 2 -f webm output.webm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment