Created
April 1, 2012 18:30
-
-
Save lad1337/2277551 to your computer and use it in GitHub Desktop.
reencode 10-bit anime mkvs into 10-bit versions using HandBrakeCli and this only when needed
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 | |
# ---------- | |
# This script uses HandBrakeCLI to convert any mkv x264 video to 8-bit (high @ 4.1 Profile) | |
# and this only when needed!! | |
#----------- | |
# based on the script by enolive located here http://pastebin.com/2rCh13Pk | |
# ---------- | |
# Needed tools: | |
# HandBrakeCLI get it here http://handbrake.fr/downloads2.php | |
# ---------- | |
# Usage: | |
# <this_file> -i FILE | |
# ---------- | |
NO_ARGS=0 | |
E_OPTERROR=85 | |
USAGE="$(basename $0) [-i file] [-o file] [-d] [-t] [-t] [-h] -- reencode 10-bit anime mkvs into 10-bit versions using HandBrakeCli | |
where: | |
-h print this help and exit | |
-i input file | |
-o output file. if it is ommited output will be the <input_file_basename>[8-bit].mkv | |
-r replace. replace the input file. a temp file is writen and then replaced with the temp file. -o is irgnored | |
-d debug. show final CMD, HandBreak output and keep scan.txt file | |
-t test. only transcode the first 30s | |
-p profile. currently only \"magao\" | |
- magao: high quality profile. from http://forum.xbmc.org/showthread.php?tid=106051&pid=1061440#pid1061440" | |
if [ $# -eq "$NO_ARGS" ] # Script invoked with no command-line args? | |
then | |
echo "$USAGE" | |
exit $E_OPTERROR # Exit and explain usage. | |
# Usage: scriptname -options | |
# Note: dash (-) necessary | |
fi | |
#defaults | |
REPLACE=0 | |
INPUT='' | |
OUTPUT='' | |
TEST=false | |
DEBUG=0 | |
PROFILE='' | |
# initialize variables | |
while getopts ":ro:i:tdp:h" Option | |
do | |
case $Option in | |
o ) output="$OPTARG";; | |
i ) input="$OPTARG";; | |
t ) test=1;; | |
d ) debug=1;; | |
p ) profile="$OPTARG";; | |
r ) replace=1;; | |
h ) echo "$USAGE"; exit $E_OPTERROR;; | |
* ) echo "Unimplemented option chosen.";; # Default. | |
esac | |
done | |
if [ ${replace:-0} == 0 ] | |
then | |
if [ "$output" = "" ] | |
then | |
output=$input | |
output=${output##*/} | |
output=${output%.mkv}[8-bit].mkv | |
fi | |
else | |
output=$input | |
output=${output##*/} | |
output=${output%.mkv}temp.mkv | |
fi | |
# TODO: find a way to save HandBrakes output int a var ... problem is it does not use stdout | |
HandBrakeCLI --scan -i "$input" &>scan.txt # save scan result in scan.txt | |
if cat scan.txt | grep -q "High 10" | |
then | |
echo "Processing $input -> $output ..." | |
# mux subtitels 1-3 ... ther is no way to say mux all subtitels sry for stuff with more then 3 subs | |
# set default sub to teh first | |
# passthru audio | |
# constant framerate | |
CMD="HandBrakeCLI -f mkv -s \"1,2,3\" --subtitle-default 1 -E copy:* -e x264 --x264-tune animation --x264-profile high --cfr -o \"$output\" -i \"$input\"" | |
if [ $test == 1 ] | |
then | |
echo "test run first 30s" | |
CMD="$CMD --stop-at duration:30" | |
fi | |
if [ "$profile" != "" ] | |
then | |
echo "Profile choosen: $profile" | |
fi | |
# add new profiles here | |
case $profile in | |
# from http://forum.xbmc.org/showthread.php?tid=106051&pid=1061440#pid1061440 .. well thats what i think it is :3 | |
magao ) CMD="$CMD -x ref=6:weightp=1:rc-lookahead=10:trellis=0:8x8dct=0:bframes=5:b-adapt=2:me=umh:merange=9:psy-rd=0.5,0.00";; | |
* ) ;; # Default. use HandBrakes Defaults | |
esac | |
if [ ${debug:-0} == 0 ] | |
then | |
CMD="$CMD &>/dev/null" | |
else | |
echo "Final CMD: $CMD" | |
fi | |
echo "Processing in progress, this can take very long, plz wait..." | |
# run transcoding | |
# use eval beacuse of spaces in file names ... | |
eval $CMD | |
if [ $replace == 1 ] | |
then | |
rm -f "$input" | |
mv "$output" "$input" | |
output=$input | |
fi | |
echo | |
echo "########################" | |
echo "Processing DONE ^_^" | |
echo "8bit file at: $output" | |
echo "########################" | |
else | |
echo | |
echo "########################" | |
echo "NOT processing $input its not 10bit :3" | |
echo "########################" | |
fi | |
if [ ${debug:-0} == 0 ] | |
then | |
if [ -e "scan.txt" ] | |
then | |
rm -f "scan.txt" | |
fi | |
fi | |
# all done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To save in var redirect stderr to stdout 2>&1
scan=$(HandBrakeCLI --scan -i "$input" 2>&1)