On mac:
- Download the latest release.
- Extract the binary and place it in
/usr/local/bin
.
Most basic conversion using Terminal: ffmpeg -i input.mov output.webm
.
Flag: -an
.
Example flag: -vf scale=1280:-2
.
-1
for the width or height will keep it in ratio to the other specified dimension.
-2
will keep it in ratio to the other specified dimension, but, to ensure it is divisible by 2 (a requirement for certain encodings such as yuv420p
) the width or height will be adjusted if necessary.
Docs here.
Flag: -threads 0
.
Allow your CPU to use an optimal number of threads.
Guide here.
ffmpeg -i input.mov -c:v libvpx -qmin 0 -qmax 25 -crf 4 -b:v 1M -vf scale=1280:-2 -c:a libvorbis -threads 0 output.webm
ffmpeg -i input.mov -c:v libvpx -qmin 0 -qmax 25 -crf 4 -b:v 1M -vf scale=1280:-2 -an -threads 0 output.webm
Guide here.
Flag: -pix_fmt yuv420p
.
Note: Requires dimensions to be divisible by 2.
Flag: -profile:v baseline -level 3.0
.
Android in particular doesn't support higher profiles.
Example flag: -crf 20
.
0
is lossless, 23
is default, and 51
is worst possible. 18
-28
is a sane range.
Flag: -movflags +faststart
.
Moves some data to the beginning of the file, allowing the video to be played before it is completely downloaded.
ffmpeg -i input.mov -c:v libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 -crf 22 -preset veryslow -vf scale=1280:-2 -c:a aac -strict experimental -movflags +faststart -threads 0 output.mp4
ffmpeg -i input.mov -c:v libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 -crf 22 -preset veryslow -vf scale=1280:-2 -an -movflags +faststart -threads 0 output.mp4
- In a folder, make sure your master videos are named how you want your exports to be named.
- Save the bash script below as
video4web.sh
in the folder. - In Terminal,
cd
to the folder. - Run
chmod +x video4web.sh
. - Run the script using the parameters documented. E.g.
./video4web.sh mov 1280
.
#!/bin/bash
# Generates a cover image along with mute web-ready WebM and MP4 files for each master video in a folder.
# See: https://gist.github.com/jaydenseric/220c785d6289bcfd7366.
# Parameter 1: Input video format (e.g. "mov").
# Parameter 2: Output width in pixels (e.g. "1280").
# Example use: "./video4web.sh mov 1280".
for i in *.$1
do
# Generate cover image
ffmpeg -i $i -vframes 1 -vf scale=$2:-2 -q:v 1 ${i%$1}jpg
# Generate WebM
ffmpeg -i $i -c:v libvpx -qmin 0 -qmax 25 -crf 4 -b:v 1M -vf scale=$2:-2 -an -threads 0 ${i%$1}webm
# Generate MP4
ffmpeg -i $i -c:v libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 -crf 22 -preset veryslow -vf scale=$2:-2 -an -movflags +faststart -threads 0 ${i%$1}mp4
done
Vimeo and Crunchyroll and Funimation uses x264 with CRF and a cap max rate. For pure streaming it's better to use HLS and web player that will implement an appropriate buffer size and a thread to make sure it's always filled, instead of relying on browser downloading and real time playback. For smallish videos or crf value that results in moderate rates, in practice VBR is not a problem for regular browser downloading and streaming since you're downloading the whole file at full speed anyways often much faster than the max bitrate of video.