Skip to content

Instantly share code, notes, and snippets.

@evan-sm
Last active April 17, 2016 17:27
Show Gist options
  • Save evan-sm/406d85dd68c793df6f8f8253fe812a80 to your computer and use it in GitHub Desktop.
Save evan-sm/406d85dd68c793df6f8f8253fe812a80 to your computer and use it in GitHub Desktop.
Simple WebM converter with automatic bitrate settings for 6 mb output depending on the duration
#!/bin/sh
# Install needed tools:
# brew install sox --with-libvorbis
# brew install ffmpeg --with-libvpx --with-libvorbis --with-opus --with-faac
echo "=== Простой WebM конвертер с автоматическим вычислением битрейта под размер файла ==="
echo "=== Simple WebM converter with automatic bitrate settings for 6 mb output depending on the duration ==="
# Example ./webm.sh 1.mp4 00:01:05 00:01:30
#############################################
ts_get_sec()
{
read -r h m s <<< $(echo $1 | tr ':' ' ' )
echo $(((h*60*60)+(m*60)+s))
}
#############################################
START=$(ts_get_sec $start_ts)
STOP=$(ts_get_sec $stop_ts)
DURATION=$((STOP-START))
echo Файл: "$1"
echo Продолжительность: "$DURATION" секунд
file_size_limit=6229483
echo Лимит файла: "$file_size_limit" байт "("`expr $file_size_limit / 1024` КБ")"
videobitrate=`expr $file_size_limit \* 8 / $DURATION / 1024 - 80`
echo "Вычислен нужный размер битрейта:" "$videobitrate" kbps
ffmpeg -i "$1" -fs $file_size_limit -c:v libvpx -cpu-used 4 -threads 4 -minrate 2000k -maxrate 2000k -b:v 2000k -c:a libvorbis "$1".webm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment