Last active
September 15, 2021 19:34
-
-
Save shoreline-chrism/59554ce2e2fdec1adbf003824b81be5c to your computer and use it in GitHub Desktop.
Optimize and convert MP4 videos to webm and mp4
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 | |
read -e -p 'Filename: ' filename | |
#Get extension and filename | |
originalfilename="$filename" | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
scale="1280:720" | |
read -e -p 'Scale: ' -i "$scale" scale | |
if [ $extension == 'mov' ] | |
then | |
mp4_audio_codec="mp3" | |
else | |
mp4_audio_codec="copy" | |
fi | |
read -e -p 'Remove Audio? (y/n): ' REMOVE_AUDIO | |
if [ $REMOVE_AUDIO == "y" ] | |
then | |
AUDIO_COMMAND_MP4="-an" | |
AUDIO_COMMAND_WEBM="-an" | |
else | |
AUDIO_COMMAND_MP4="-acodec ${mp4_audio_codec}" | |
AUDIO_COMMAND_WEBM="-c:a libvorbis" | |
fi | |
echo $mp4_audio_codec | |
echo $AUDIO_COMMAND_MP4 | |
echo "$filename" | |
echo "Converting to webm" | |
ffmpeg -i "$originalfilename" -c:v libvpx -crf 10 -b:v 1M -vf scale="$scale" $AUDIO_COMMAND_WEBM "$filename-optimized.webm" | |
echo "Converting to mp4" | |
ffmpeg -i "$originalfilename" -vcodec h264 $AUDIO_COMMAND_MP4 -vf scale="$scale" "$filename-optimized.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment