Last active
May 2, 2024 03:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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
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