Created
June 16, 2018 15:18
-
-
Save mrTimofey/45c7d600dc4ffe5a0f5d3a8aad1365ba to your computer and use it in GitHub Desktop.
Convert audio for web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -eq 0 ]; then | |
echo "File name required" | |
exit | |
fi | |
echo -n "Bitrate (2000k): " | |
read bitrate | |
if [ "$bitrate" == "" ]; then | |
bitrate='2000' | |
fi | |
echo -n "Size (1280x720): " | |
read size | |
if [ "$size" == "" ]; then | |
size='1280x720' | |
fi | |
echo -n "Cut out audio? (y/n, default n): " | |
read audiocodec | |
if [ "$audiocodec" == "y" ]; then | |
audiocodec_mp4='-an' | |
audiocodec_mov='-an' | |
audiocodec_webm='-an' | |
audiocodec_ogv='-an' | |
else | |
audiocodec_mp4='-acodec libvo_aacenc' | |
audiocodec_mov='-acodec libvo_aacenc' | |
audiocodec_webm='-acodec libvorbis' | |
audiocodec_ogv='-acodec libvorbis' | |
fi | |
common='-threads 4 -qmin 0 -qmax 30 -q:v 4 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -trellis 0'; | |
options="-y -s $size -b:v ${bitrate}K" | |
echo "${options}" | |
for file in "$@" | |
do | |
DIR="${file}_${bitrate}k_${size}" | |
mkdir -p "$DIR" 2> /dev/null | |
rm "$DIR/*" | |
ffmpeg -i "${file}" -vcodec h264 ${options} -vf format=yuv420p ${audiocodec_mp4} "${DIR}/${file}.mp4" | |
ffmpeg -i "${file}" -c:v libtheora ${options} ${audiocodec_ogv} "${DIR}/${file}.ogv" | |
ffmpeg -i "${file}" -c:v libvpx ${options} ${audiocodec_webm} "${DIR}/${file}.webm" | |
ffmpeg -i "${DIR}/${file}.webm" -vcodec libx264 ${options} ${audiocodec_mov} "${DIR}/${file}.mov" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment