-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_full.sh
executable file
·323 lines (286 loc) · 9.68 KB
/
build_full.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/bin/bash
# Video Channels Creator - Linux Edition
# Original version by [Rinnegatamante](http://rinnegatamante.it)
function usage() {
# shellcheck disable=SC2086
cat <<EOF
Usage: $(basename $0) [-cf] [-d [FILE]| -t [-l FILE [-r FILE]]] [-u UNIQUEID] [-n TITLE] [-b BANNER] [-i ICON] [-a AUDIO] [-g AUTHOR] [-q QUALITY] [-p FRAMERATE] [-h]
Can also be called without arguments. Script will go interactive for any missing arguments. All arguments are optional.
Run man ./docs/manpage or $(basename $0) -h for individual option coverage.
EOF
exit 0
}
#getopts parsing
while getopts ":cfhd:tl:r:u:n:b:i:a:q:p:g:" opt; do
case $opt in
c)
compression=1
;;
f)
FORCED=1
;;
h)
man './docs/manpage.1'
exit 0
;;
d)
VIDFILESET=1
threedeevid=2
videoname=$OPTARG
;;
t)
VIDFILESET=1
threedeevid=1
;;
l)
threedeeleft=$OPTARG
;;
r)
threedeeright=$OPTARG
;;
u)
uniqueid=$OPTARG
;;
n)
videotitle=$OPTARG
;;
i)
cicon=$OPTARG
;;
b)
ciabanner=$OPTARG
;;
a)
ciaudio=$OPTARG
;;
q)
quality=$OPTARG
;;
p)
framerate=$OPTARG
;;
g)
videoauthor=$OPTARG
;;
*)
usage
;;
esac
done
#Thank stackoverflow again. http://stackoverflow.com/a/2210386/4666756
if [[ -n $quality ]]; then
if [[ $quality =~ ^[0-9]+$ ]]; then
echo "Quality is a positive integer"
else
echo "Quality is not a positive integer. Exiting"
exit 1
fi
fi
if [[ -n $framerate ]]; then
if [[ $framerate =~ ^[0-9]+$ ]]; then
echo "Framerate is a positive integer"
else
echo "Framerate is not a positive integer. Exiting"
exit 1
fi
fi
if [[ -n $VIDFILESET && $VIDFILESET == 2 ]]; then
if [[ -z $threedeeleft || -z $threedeeright ]]; then
echo "3D video flag given, but no left and/or right video specified. Exiting"
exit 1
fi
fi
if [ -z "$FORCED" ]; then
# Command line checking. See http://stackoverflow.com/a/677212/4666756 for details.
command -v ffmpeg >/dev/null 2>&1 || { echo -e "\e[1;31mFFMpeg is not installed or it is not added to your PATH."; echo -e "Install FFMpeg or add it to your PATH, then rerun this script.\e[0m"; exit 1; }
command -v jpegtran >/dev/null 2>&1 || { echo -e "\e[1;33mjpegtran is not installed or it is not added to your PATH."; echo "jpegtran is required for video compression."; echo "jpegtran is in the libjpeg-turbo-progs package on Ubuntu systems."; echo -e "If it is not, you can get it from here and compile it yourself: http://jpegclub.org/jpegtran/ . \e[0m"; exit 1;}
command -v bannertool >/dev/null 2>&1 || { echo -e "\e[1;31mBannertool is not installed or it is not added to your PATH."; echo "Bannertool is required for VCC."; echo "Bannertool can be obtained here: https://github.com/Steveice10/bannertool/releases \e[0m"; exit 1; }
command -v 3dstool >/dev/null 2>&1 || { echo -e "\e[1;313dstool is not installed or it is not added to your PATH."; echo "3dstool is required for VCC."; echo -e "Install 3dstool or add it to your PATH, then rerun this script. 3dstool can be obtained from here: https://github.com/dnasdw/3dstool/releases \e[0m"; exit 1; }
command -v makerom >/dev/null 2>&1 || { echo -e "\e[1;31mmakerom is not installed or it is not added to your PATH."; echo "makerom is required for VCC."; echo -e "Install makerom or add it to your PATH, then rerun this script. 3dstool can be obtained from here: https://github.com/profi200/Project_CTR/releases \e[0m"; exit 1; }
echo "Command line appears to be correct. Continuing."
else
echo "Skipping commandline checks."
fi
# Get previous UniqueID - Note, this is currently stored in a serparate file, cuz I'm lazy.
initialuniqueid=$(cat "linuxstuffs/uniq")
# Convert a 3D video?
if [ -z "$VIDFILESET" ]; then
read -rp "Convert a 3D video? (1 = Yes, 2 = No) " threedeevid
case $threedeevid in
1)
touch romfs/three.txt
read -rp "Insert left channel video name (Example: left.mp4): " threedeeleft
read -rp "Insert right channel video name (Example: right.mp4): " threedeeright
;;
2)
read -rp "Insert video name (Example: video.mp4): " videoname
;;
esac
else
echo "Video Files already set"
fi
# Asking other questions
if [ -z "$framerate" ]; then
read -rp "Insert video framerate: " framerate
else
echo "Framerate set to $framerate."
fi
if [ -z "$quality" ]; then
read -rp "Insert video quality (From 1 to 32, lower = better quality, higher = better filesize): " quality
else
echo "Quality set to $quality"
fi
if [ -z "$compression" ]; then
read -rp "Do you want to apply extra compression (slow process and slight filesize reducing)? (1 = Yes, 2 = No): " compression
else
echo "Compression set to true."
fi
if [ -z "$uniqueid" ]; then
read -rp "Insert cia Unique ID [0-9, A-F] (Example: 0xAAAAAA): " uniqueid
else
echo "UniqueID set to $uniqueid."
fi
if [ -z "$ciabanner" ]; then
read -rp "Insert banner image (Example: banner.jpg): " ciabanner
else
echo "Banner image set to $ciabanner"
fi
if [ -z "$ciaudio" ]; then
read -rp "Insert banner audio: (Example: audio.wav): " ciaudio
else
echo "Banner audio set to $ciaudio"
fi
if [ -z "$cicon" ]; then
read -rp "Insert icon image: (Example: icon.png): " cicon
else
echo "Icon image set to $cicon"
fi
if [ -z "$videotitle" ]; then
read -rp "Insert video title: " videotitle
else
echo "Video title set to $videotitle"
fi
if [ -z "$videoauthor" ]; then
read -rp "Insert video author: " videoauthor
else
echo "Video author set to $videoauthor"
fi
# Converting video to JPGV format
case $threedeevid in
1)
ffmpeg -i "./files/$threedeeleft" -r "$framerate" -qscale:v "$quality" -vf "transpose=1" -s 240x400 "temp_left/output%d.jpg"
if [ $? != 0 ]; then
echo "An error occured in FFMpeg, conversion aborted."
exit 1
fi
ffmpeg -i "./files/$threedeeright" -r "$framerate" -qscale:v "$quality" -vf "transpose=1" -s 240x400 "temp_right/output%d.jpg"
if [ $? != 0 ];then
echo "An error occured in FFMpeg, conversion aborted."
exit 1
fi
;;
2)
ffmpeg -i "./files/$videoname" -r "$framerate" -qscale:v "$quality" -vf "transpose=1" -s 240x400 "temp/output%d.jpg"
if [ $? != 0 ]; then
echo "An error occured in FFMpeg, conversion aborted."
exit 1
fi
;;
esac
# Video compression
if [[ "1" == "$compression" ]]; then
if [[ $threedeevid == 1 ]]; then
echo "Starting left video optimization through jpegtran, please wait..."
# Left side compression
for leftrawjpgs in temp_left/*
do
jpegtran -optimize -outfile "$leftrawjpgs" "$leftrawjpgs"
done
# Right side compression
for rightrawjpgs in temp_right/*
do
jpegtran -optimize -outfile "$rightrawjpgs" "$rightrawjpgs"
done
fi
if [[ $threedeevid == 2 ]]; then
echo "Starting video optimization through jpegtran, please wait..."
for rawjpgs in temp/*
do
jpegtran -optimize -outfile "$rawjpgs" "$rawjpgs"
done
fi
fi
# Audio extraction
echo "Starting audio extraction through ffmpeg, please wait..."
if [[ "1" == "$threedeevid" ]]; then
ffmpeg -i "./files/$threedeeleft" -acodec: libvorbis -ac 2 -ar 24000 -vn temp/audio.ogg
fi
if [[ "2" == "$threedeevid" ]]; then
ffmpeg -i "./files/$videoname" -acodec: libvorbis -ac 2 -ar 24000 -vn temp/audio.ogg
fi
# Creating JPGV file
# We start with checking if the encoder is already compiled, and if not, we compile it. This is better because that way, it will always work, regardless of architecture.
if [ ! -f "linuxstuffs/jpgv_encoder_2d" ]; then
echo "Compiling 2D encoder"
gcc -o "linuxstuffs/jpgv_encoder_2d" "linuxstuffs/vid2jpgvsauce/main_m.c"
echo "Finished"
fi
if [ ! -f "linuxstuffs/jpgv_encoder_3d" ]; then
echo "Compiling 3D encoder"
gcc -o "linuxstuffs/jpgv_encoder_3d" "linuxstuffs/vid2jpgvsauce/main_s.c"
echo "Finished"
fi
# Now to actually create the jpgv
if [[ "1" == "$threedeevid" ]]; then
#shellcheck disable=SC2086
linuxstuffs/jpgv_encoder_3d $framerate
fi
if [[ "2" == "$threedeevid" ]]; then
#shellcheck disable=SC2086
linuxstuffs/jpgv_encoder_2d $framerate
fi
echo "Deleting temp files..."
rm -rf temp/* temp_left/* temp_right/*
mv output.jpgv romfs/video.jpgv
# Makerom prepping
echo "Creating icon and banner files..."
bannertool makebanner -i "files/$ciabanner" -a "files/$ciaudio" -o "tmp/banner.bin"
if [ $? != 0 ];then
echo "An error occured in bannertool, conversion aborted."
echo "The JPGV file has been backupped as saved.jpgv, use the build_jpgv.bat script to use this file instead of re-creating it."
mv romfs/video.jpgv saved.jpgv
exit 1
fi
bannertool makesmdh -s "$videotitle" -l "$videotitle" -p "$videoauthor" -i "files/$cicon" -o "tmp/icon.bin"
if [ $? != 0 ];then
echo "An error occured in bannertool, conversion aborted."
echo "The JPGV file has been backupped as saved.jpgv, use the build_jpgv.bat script to use this file instead of re-creating it."
mv romfs/video.jpgv saved.jpgv
exit 1
fi
# We start by generating the romfs for usage in makerom
echo "Creating romfs file..."
3dstool -cvtf romfs tmp/romfs.bin --romfs-dir romfs
if [ $? != 0 ];then
echo "An error occured in bannertool, conversion aborted."
echo "The JPGV file has been backupped as saved.jpgv, use the build_jpgv.bat script to use this file instead of re-creating it."
mv romfs/video.jpgv saved.jpgv
exit 1
fi
# Now we make a cia out of it
sed -i "s/$initialuniqueid/$uniqueid/g" "linuxstuffs/cia_workaround.rsf"
echo "$uniqueid" > "linuxstuffs/uniq"
echo "Generating CIA..."
makerom -f cia -o my_video.cia -elf "linuxstuffs/lpp-3ds.elf" -rsf "linuxstuffs/cia_workaround.rsf" -icon "tmp/icon.bin" -banner "tmp/banner.bin" -exefslogo -target t -romfs "tmp/romfs.bin"
if [ $? != 0 ];then
echo "An error occured in makerom, conversion aborted."
echo "The JPGV file has been backupped as saved.jpgv, use the build_jpgv.bat script to use this file instead of re-creating it."
mv romfs/video.jpgv saved.jpgv
exit 1
fi
# Removing temporary files
echo "Removing temporary files..."
rm -rf "tmp/*"
rm -rf "romfs/video.jpgv"
echo "Video converted succesfully!"
exit 0