Created
September 12, 2014 08:21
-
-
Save teranex/9781c343f18c5d8c380f to your computer and use it in GitHub Desktop.
Convert a video file to a MKV playable directly on a Chromecast. Usage: `./convert-to-chromecast /path/to/video.file`
This file contains hidden or 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 ffmpeg -i "$1" 2>&1 | grep Video: | grep h264 #check video codec | |
then | |
vcodec=copy | |
else | |
vcodec=libx264 | |
fi | |
if ffmpeg -i "$1" 2>&1 | grep Video: | grep "High 10" #10 bit H.264 can't be played by Hardware. | |
then | |
vcodec=libx264 | |
fi | |
if ffmpeg -i "$1" 2>&1 | grep Audio: | grep aac || | |
ffmpeg -i "$1" 2>&1 | grep Audio: | grep mp3 || | |
ffmpeg -i "$1" 2>&1 | grep Audio: | grep vorbis #check audio codec | |
then | |
acodec=copy | |
else | |
acodec=aac | |
fi | |
echo "==================" | |
echo "vcodec: $vcodec" | |
echo "acodec: $acodec" | |
echo "==================" | |
if [ "$acodec" == "copy" ] && [ "$vcodec" == "copy" ] && ( [[ $1 == *.mkv ]] || [[ $1 == *.mp4 ]] ) | |
then | |
echo "no conversion needed" | |
exit 2 | |
fi | |
if [ "$vcodec" != "copy" ] && [ "$2" == "--disable-video-conversion" ] | |
then | |
echo "video conversion is necessary, but it was disabled" | |
exit 3 | |
fi | |
src=$1 | |
if [[ $1 == *.mkv ]] | |
then | |
echo "converting MKV to another MKV, so first renaming the original MKV" | |
mv "$1" "${1}.orig" | |
src=${1}.orig | |
fi | |
echo "let's start converting!" | |
ffmpeg -i "$src" -c:a $acodec -c:v $vcodec -q:a 0 -q:v 0 -strict -2 "${1%.*}.mkv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment