-
Notifications
You must be signed in to change notification settings - Fork 1
/
VideoConverter.sh
214 lines (179 loc) · 4.34 KB
/
VideoConverter.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
METADATALOOP=true
INSTALLFFMPEGLOOP=true
ARTLOOP=true
ARTDIRLOOP=true
SUBTITLELOOP=true
TMPLEVEL=0
TMPCHANGE=false
echo ""
echo "============================"
echo "Video Converter using FFmpeg"
echo "============================"
if [ "$1" = "-h" ]; then
echo ""
echo "DESCRIPTION"
echo "A video converter Script using FFmpeg for Linux."
echo "Can add metadata, subtitles and cover art to the video."
echo ""
echo "COMMAND LAYOUT"
echo "./VideoConverter.sh"
echo ""
echo "NEEDED SCRIPTS"
echo "Metadata.sh for adding metadata"
echo "Subtitles.sh for adding subtitles"
echo "CoverArt.sh for adding subtitles"
echo "RemoveFiles.sh to remove temp files"
echo "BulkConvert.sh in order to convert multiple files in a folder"
echo ""
echo "EXIT/ERROR CODES"
echo "0 - No errors"
echo "1 - Can't find FFmpeg"
echo "2 - Can't find the BulkConvert.sh script for bulk conversion"
echo ""
exit 0
fi
if ! FFMPEGLOCATION="$(command -v ffmpeg)" || [ -z $FFMPEGLOCATION ]; then
echo ""
echo "FFmpeg is not installed"
echo "Do you want install it? (yes/no)"
while [ "$INSTALLFFMPEGLOOP" = true ]; do
read INSTALLFFMPEGANSWER
case $INSTALLFFMPEGANSWER in
[Yy]* )
sudo apt install ffmpeg -y
INSTALLFFMPEGLOOP=false
;;
[Nn]* )
echo "Sadly you can't use this script without FFmpeg"
exit 1
;;
* ) echo "Please answer yes or no.";;
esac
done
fi
echo ""
read -p "Working directory (full path or . to use current directory): " DIRECTORY
if [ "$DIRECTORY" = "." ]; then
echo "Using current directory"
else
echo "This is now the working directory: $DIRECTORY"
fi
if [ "$1" = "-b" ]; then
if [ -f "./BulkConvert.sh" ]; then
echo ""
echo "Bulk conversion"
read -p "Convert from file format: " $INPUTFORMAT
read -p "Convert to file format: " $OUTPUTFORMAT
./BulkConvert.sh $DIRECTORY $INPUTFORMAT $OUTPUTFORMAT
echo ""
echo "DONE!"
echo ""
exit 0
else
echo ""
echo "Could not find the BulkConvert.sh file"
echo "Bulk conversion does not work without that script"
exit 2
fi
fi
echo ""
read -p "Input file: " INPUTFILE
echo ""
echo "Do you want to add metadata? (yes/no)"
while [ "$METADATALOOP" = true ]; do
read METADATAANSWER
case $METADATAANSWER in
[Yy]* )
echo ""
read -p "Title: " TITLE
read -p "Release date (number): " DATE
read -p "Genre: " GENRE
read -p "Show name: " SHOW
read -p "Season number (number): " SEASON
read -p "Episode number (number): " EPISODE
read -p "Language: " LANGUAGE
read -p "Resolution (SD=0, 720p=1, 1080p=2, 2160p=3): " QUALTIY
USEMETADATA=true
METADATALOOP=false
TMPLEVEL=$((TMPLEVEL+1))
TMPCHANGE=true
;;
[Nn]* )
METADATALOOP=false
;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Do you want to add subtitles? (yes/no)"
while [ "$SUBTITLELOOP" = true ]; do
read SUBTITLEANSWER
case $SUBTITLEANSWER in
[Yy]* )
./Subtitles.sh -a 0 - $DIRECTORY
USESUBTITLES=true
SUBTITLELOOP=false
TMPLEVEL=$((TMPLEVEL+1))
;;
[Nn]* )
SUBTITLELOOP=false
;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Do you want to add cover art? (yes/no)"
while [ "$ARTLOOP" = true ]; do
read ARTANSWER
case $ARTANSWER in
[Yy]* )
echo ""
echo "Is the cover art in the same directory as: $DIRECTORY? (yes/no)"
while [ "$ARTDIRLOOP" = true ]
do
read ARTDIRANSWER
case $ARTDIRANSWER in
[Yy]* )
ARTDIR=$DIRECTORY
ARTDIRLOOP=false
;;
[Nn]* )
echo ""
read -p "Directory for cover art: " ARTDIR
ARTDIRLOOP=false
;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
read -p "Cover art file: " ARTFILE
ARTLOCATION=$ARTDIR/$ARTFILE
USEART=true
ARTLOOP=false
TMPLEVEL=$((TMPLEVEL+1))
;;
[Nn]* )
ARTLOOP=false
;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
read -p "Output file: " OUTPUTFILE
echo ""
echo "Converting file..."
echo ""
if [ "$USEMETADATA" = true ]; then
./Metadata.sh $TMPLEVEL $DIRECTORY $INPUTFILE $OUTPUTFILE $TITLE $DATE $GENRE $SHOW $SEASON $EPISODE $LANGUAGE $QUALTIY
fi
if [ "$USESUBTITLES" = true ]; then
./Subtitles.sh -x $TMPLEVEL $TMPCHANGE $DIRECTORY $INPUTFILE $OUTPUTFILE
fi
if [ "$USEART" = true ]; then
./CoverArt.sh $TMPLEVEL $DIRECTORY $INPUTFILE $ARTLOCATION $OUTPUTFILE
fi
./RemoveFiles.sh $DIRECTORY $OUTPUTFILE
echo ""
echo "DONE!"
echo ""