A basic shell script to encode HTML5 video.
- FFMPEG executable with at least the following libraries
- libx264
- libfdk_aac
- libvpx
- libvorbis
To install via Homebrew:
brew install ffmpeg --with-fdk-aac --with-libvorbis --with-libvpx
webvideo [-m] [-w] [-f] [-na] *files*
- -m | --mp4
- encode and output an mp4 format file
- -w | --webm
- encode and output a webm format file
- -f | --flv
- encode and output a flv format file
- -na | --no-audio
- disable encoding of audio
I wrote this script mostly for myself, because I wasn't satisfied with using a GUI video encoder to encode my web videos properly.
Most modern browsers support the HTML5
- mp4 = H.264 baseline profile video codec, AAC audio codec, MPEG-4 container
- webm = VP8 video codec, Vorbis audio codec, WebM container
Feel free to change them to your needs. If you want to know more, there's good reading here, here, here, and a good support chart here.
Video files can be big, and you don't want the user to have to wait for the whole video to download to their computer. You want the video to start playing as soon as enough of it has been downloaded to get started. In order to do this, mp4 files need to be organized so that certain data is at the beginning of the file. This script sets the "faststart" option to make sure that encoded videos are streamable.
These are adjustable variables at the top of the script. I didn't make them script arguments because usually I like to stick to a particular quality and size for a given project, and I didn't want to overcomplicate the script. Here's my rationale for the defaults: I certainly like me some HD video, but I wanted to find a best-balance between quality and streaming speed without having to encode multiple files. I think 480p is fine for most in that regard. For 16:9 aspect ratios, that means 854x480. At that size, 800k video bitrate is sufficient to make it look decent without making the file size too large.