-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvscript.sh
executable file
·135 lines (101 loc) · 3.15 KB
/
tvscript.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
#
# Copyright (c) 2017 Marc Young
#
# encode for playback on Roku or Chromcast
#
#This script takes the titles in a DVD and rips them as individual files
#
IAM=$(whoami)
INFO_SRC="/media/$IAM"
DVD_NAME=$(ls $INFO_SRC)
VOB=$INFO_SRC/$DVD_NAME/VIDEO_TS/VIDEO_TS.VOB
INPUT=/dev/sr0
handbrake="HandBrakeCLI"
mediainfo="mediainfo"
echo $handbrake
handbrake_options="--markers --large-file --encoder x264 --encopts vbv-maxrate=25000:vbv-bufsize=31250:ratetol=inf --crop 0:0:0:0 --strict-anamorphic"
width="$(mediainfo --Inform='Video;%Width%' "$VOB")"
height="$(mediainfo --Inform='Video;%Height%' "$VOB")"
echo $width
echo $height
if (($width > 1280)) || (($height > 720)); then
max_bitrate="5000"
elif (($width > 720)) || (($height > 576)); then
max_bitrate="4000"
else
max_bitrate="1800"
fi
min_bitrate="$((max_bitrate / 2))"
bitrate="$(mediainfo --Inform='Video;%BitRate%' "$input")"
if [ ! "$bitrate" ]; then
bitrate="$(mediainfo --Inform='General;%OverallBitRate%' "$input")"
bitrate="$(((bitrate / 10) * 9))"
fi
if [ "$bitrate" ]; then
bitrate="$(((bitrate / 5) * 4))"
bitrate="$((bitrate / 1000))"
bitrate="$(((bitrate / 100) * 100))"
if (($bitrate > $max_bitrate)); then
bitrate="$max_bitrate"
elif (($bitrate < $min_bitrate)); then
bitrate="$min_bitrate"
fi
else
bitrate="$min_bitrate"
fi
echo $bitrate
handbrake_options="$handbrake_options --vb $bitrate"
frame_rate="$(mediainfo --Inform='Video;%FrameRate_Original%' "$VOB")"
if [ ! "$frame_rate" ]; then
frame_rate="$(mediainfo --Inform='Video;%FrameRate%' "$VOB")"
fi
frame_rate_file="$(basename "$VOB")"
frame_rate_file="${frame_rate_file%\.[^.]*}.txt"
if [ -f "$frame_rate_file" ]; then
handbrake_options="$handbrake_options --rate $(cat "$frame_rate_file")"
elif [ "$frame_rate" == '29.970' ]; then
handbrake_options="$handbrake_options --rate 23.976"
else
handbrake_options="$handbrake_options --rate 30 --pfr"
fi
channels="$(mediainfo --Inform='Audio;%Channels%' "$VOB" | sed 's/[^0-9].*$//')"
if (($channels > 2)); then
handbrake_options="$handbrake_options --aencoder ca_aac,copy:ac3"
elif [ "$(mediainfo --Inform='General;%Audio_Format_List%' "$VOB" | sed 's| /.*||')" == 'AAC' ]; then
handbrake_options="$handbrake_options --aencoder copy:aac"
fi
if [ "$frame_rate" == '29.970' ]; then
handbrake_options="$handbrake_options --detelecine"
fi
lsdvd > dvdinfo.txt
sed -i '/Disc Title:/d' dvdinfo.txt
sed -i '/Longest track:/d' dvdinfo.txt
echo "What is the name of the show?"
read show_name
if [ ! -d "$show_name" ]; then
mkdir $show_name
fi
echo "What season is it?"
read season
echo "What is the first episode of the disc?"
read episode
echo $episode
echo "Encoding: $VOB" >&2
cat dvdinfo.txt | while read line
do
if echo $line | grep -Eq 'Length: 00:0'
then
echo 'Crap!'
else
echo $line
title=$(echo $line | awk '{print $2}' | sed 's/^0*//' | tr -dc '[:alnum:]\n\r')
output=$show_name/$show_name"_s"$season"_e"$title".mp4"
time "$handbrake" -t $title \
echo $handbrake_options \
--input "$INPUT" \
--output "$output" \
2>&1 | tee -a "${output}.log"
fi
done
echo "Done."