Created
October 24, 2018 23:49
-
-
Save sanmadjack/b647d0d089db4a8eb1242aa68ccccd54 to your computer and use it in GitHub Desktop.
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 | |
for key in "$@" | |
do | |
key="$1" | |
flipSubs=false | |
tenbit=false | |
case $key in | |
--flip-subs) | |
flipSubs=true | |
;; | |
--10-bit) | |
tenbit=true | |
;; | |
esac | |
done | |
rootFolder="/sharedfolders/transcoding" | |
inputFolder="$rootFolder/input" | |
outputFolder="$rootFolder/output" | |
doneFolder="$rootFolder/done" | |
if [ "$tenbit" = true ]; then | |
encoder="x265_10bit" | |
else | |
encoder="x265" | |
fi | |
if [ "$flipSubs" = true ]; then | |
subArgs="--subtitle 2,1" | |
else | |
subArgs="--subtitle-lang-list eng --all-subtitles --native-language eng" | |
fi | |
convert_file() { | |
filepath="$inputFolder/$1" | |
echo "Converting file: $filepath" | |
filename=$(basename -- "$filepath") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
subPath=$(dirname "${1}") | |
mkdir -p "$outputFolder/$subPath" | |
outputPath="$outputFolder/$subPath/$filename.mkv" | |
#echo "outputPath $outputPath" | |
flatpak run fr.handbrake.HandBrakeCLI --min-duration 0 --format av_mkv --markers \ | |
--encoder $encoder --encoder-preset slow --encoder-profile auto --quality 18 --two-pass --vfr \ | |
--audio-lang-list jpn,eng,und --all-audio --aencoder copy --audio-copy-mask aac,mp3 --audio-fallback aac --aq 8 \ | |
--auto-anamorphic --no-hqdn3d --no-nlmeans --no-unsharp --no-lapsharp --no-deblock \ | |
--comb-detect --decomb --detelecine \ | |
$subArgs \ | |
-i "$filepath" -o "$outputPath" | |
retVal=$? | |
donePath="$doneFolder/$1" | |
doneDir=$(dirname "${donePath}") | |
echo "donePath $donePath" | |
echo "doneDir $doneDir" | |
mkdir -p "$doneDir" | |
if [ $retVal -ne 0 ] | |
then | |
exit $retVal | |
else | |
mv "$filepath" "$donePath" | |
fi | |
} | |
crawl_folder() { | |
fullPath="$inputFolder/$1" | |
echo "Checking folder $fullPath" | |
for filepath in "$fullPath"/* | |
do | |
if [ -f "$filepath" ]; then | |
convert_file "$1/$(basename -- "$filepath")" | |
elif [ -d "$filepath" ]; then | |
crawl_folder "$(basename -- "$filepath")" | |
else | |
echo "Not a file: $filepath" | |
fi | |
done | |
} | |
crawl_folder "" | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment