Skip to content

Instantly share code, notes, and snippets.

@jmwhittaker
Last active May 2, 2024 03:16
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jmwhittaker/8516514 to your computer and use it in GitHub Desktop.
Save jmwhittaker/8516514 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
@ameysgitrepository
Copy link

Hi ,

I used your all commands but everytime I am unable to convert my .mov video to either .mp4 or .webm

Its saying :

Unable to parse option value "-1" as pixel format

Error setting option pix_fmt to value -1

and even though I did set -pix_value as yuv420p or yuv422p and many more other value, but still I am unable to convert its giving same errors.

I am using latest version of ffmpeg

Please guide me...!!

@ob7
Copy link

ob7 commented Dec 21, 2015

You might need some kind of libraries or something ffmpeg is trying to use which you need to install. Just an idea, I'm not for sure though.

@Username256
Copy link

Use -2 instead of -1 and the error will go away

@Natim
Copy link

Natim commented Feb 7, 2019

It did not 😕 I got the following error:

Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height

Edit Actually I had to use : -codec:a copy for the webm with audio

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