Bash scripts to help automate common
ffmpeg
video-conversion commands that I'm always using for work!
- A Linux-like environment with a
bash
version that supports theread
command:read
is abash
builtin that may not exist in older versions of bash — check by running:help read
orman read
- A working
ffmpeg
installation with the necessary libraries for MP4, OGV, & WEBM formats:- I use Homebrew to install ffmpeg — the latest homebrew installation and info can be found at: https://brew.sh/:
- Once
brew
is working installffmpeg
and libraries using:brew install ffmpeg --with-fdk-aac --with-libass --with-libvpx --with-openssl
- Once
- OTHERWISE,
ffmpeg
can now be installed as a standalone software/tool: https://ffmpeg.org/download.html
- I use Homebrew to install ffmpeg — the latest homebrew installation and info can be found at: https://brew.sh/:
Check out more information about ffmpeg at the official website: https://ffmpeg.org.
This section is provided as a convenience and is not necessary — especially if you have a brand new ffmpeg
install of the latest version. The scripts in this section are used to verify your ffmpeg
installation and configuration settings.
If you installed ffmpeg
a long time ago, you may want to run these scripts and make sure your install can handle the video conversions.
Use the bash script ./scripts/ffmpeg-version.sh
to figure out what version of ffmpeg you are using:
sh ./scripts/ffmpeg-version.sh
It uses the output from running ffmpeg -version
to get your version number.
At the time of writing this, I am using ffmpeg version 4.4 which is not the latest (version 5.)
Run this command to make sure you have the libtheora
, libvorbis
, libvpx
, & libopus
libraries installed and enabled in ffmpeg
:
sh ./scripts/ffmpeg-enabled-libraries.sh
It checks for each of the libraries in your ffmpeg configuration and will let you know if any are missing.
It uses the output from the ffmpeg -buildconf
command to check for the correct --enable-lib*
settings.
- Copy your source
*.mp4
video-file into the local./scripts/IN/
folder - Run desired bash script:
- E.g.
sh ./scripts/mp4-to-ogv.sh
- E.g.
- Answer any prompts (to set your quality settings,) or press return to accept defaults.
- The converted video will be output to the local
./scripts/OUT/
folder afterffmpeg
has completed running (which may take several minutes depending on file size.)
This repository contains the following bash scripts in the (./scripts/
folder):
./scripts/
|---- ffmpeg-enabled-libraries.sh
|---- ffmpeg-version.sh
|---- mp4-to-ogv.sh
|---- mp4-to-webm.sh
|
|---- IN/
| |____ *.mp4 ## Source MP4 files here ##
|
|____ OUT/
|____ *.{ogv,webm,mp4} ## Converted video files here ##
ffmpeg-version.sh
— bash script to verifyffmpeg
is installed and return ffmpeg version numberffmpeg-enabled-libraries.sh
— bash script to check iflibtheora
,libvorbis
,libvpx
, &libopus
are installed and enabled in ffmpeg. These libraries are necessary to run most of the ffmpeg scripts in the project.
Script | Description | Features | File Naming |
---|---|---|---|
mp4-to-ogv.sh |
bash script to convert MP4 file into OGV format | Video & audio quality are set when prompted | <SOURCE_FILENAME>_v<#>-a<#>.ogv — where <#> represents an integer corresponding to the chosen video and audio quality settings |
mp4-to-webm.sh |
bash script to convert MP4 file into WEBM | Video & audio quality are set when prompted | <SOURCE_FILENAME>_crf<#>-a<#>.webm — where <#> represents the video and audio quality settings |
Use this script to convert an MP4 video file into OGV.
It uses libtheora
and libvorbis
to convert the audio and video streams from your source MP4 file.
Default video and audio settings are as follows:
- Video quality: 6
- Audio quality: 3
Press return when prompted for video and quality settings to accept the default values. If these quality settings produce a video file that is too large, reduce the quality settings and run the command again.
Use this script to convert an MP4 video file to WEBM.
It uses libvpx-vp9
and libopus
to convert the audio and video streams.
- Video quality is set using the
-crf
flag (default is set to30
.) - Audio quality is set using the
-b:a
flag (value should be specified as a bitrate e.g.128k
— which is the set default.)