Skip to content

Instantly share code, notes, and snippets.

@TylerTemp
Created April 6, 2018 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylerTemp/36095340c37619e6c854ecb517449365 to your computer and use it in GitHub Desktop.
Save TylerTemp/36095340c37619e6c854ecb517449365 to your computer and use it in GitHub Desktop.
Converting video to webm/ogv by ffmpeg. You need to install ffmpeg first like `apt-get install ffmpeg`
#!/usr/bin/env bash
#-*- coding: utf-8 -*-
set -e
source_file="$1"
# echo "$source_file"
format="$2"
echo 1 "$format"
target_dir=$(dirname "$source_file")
filename=$(basename "$source_file")
echo "filename: $filename"
echo "folder: $target_dir"
# echo $filename
# # extension="${filename##*.}"
basename="${filename%.*}"
#
#echo "$source_file -> $basename.$format"
echo 2 $format
if [[ "$format" == "ogv" ]]; then
echo 3 ogv
elif [[ "$format" == "webm" ]]; then
echo 3 webm
fi
# exit
if [[ $format == "ogv" ]]; then
ffmpeg -i "$source_file" -c:v libtheora -c:a libvorbis -q:v 6 -q:a 5 "$target_dir/$basename.ogv"
elif [[ $format == "webm" ]]; then
ffmpeg -i "$source_file" -codec:v libvpx -quality good -cpu-used 0 -b:v 500k -qmin 10 -qmax 42 -maxrate 500k -bufsize 1000k -threads 4 -vf scale=-1:-1 -codec:a libvorbis -b:a 128k "$target_dir/$basename.webm"
else
echo "Usage: $0 <file> (ogv|webm)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment