-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLooper.sh
516 lines (466 loc) · 11.2 KB
/
Looper.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
#!/bin/bash
# ::: ... ... ::::::::::. .,:::::: :::::::..
# ;;; .;;;;;;;. .;;;;;;;. `;;;```.;;;;;;;'''' ;;;;``;;;;
# [[[ ,[[ \[[,,[[ \[[,`]]nnn]]' [[cccc [[[,/[[['
# $$' $$$, $$$$$$, $$$ $$$"" $$"""" $$$$10334c
# o88oo,.__"888,_ _,88P"888,_ _,88P 888o 888oo,__ 888b "88bo,
# """"YUMMM "YMMMMMP" "YMMMMMP" YMMMb """"YUMMMMMMM "W""
# FFmpeg Automate By Kuro-Code
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~ Looper ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Type: Multimedia
# CoDeD: bY KURO-CODE
# DaTe: 9/15/2018
# Dev: Bash
# Ver: 1.1
#
#~~~~~~~~~~~~~~~~~ INFO ~~~~~~~~~~~~~~~~~~~~
#
# Automate FFmpeg.
#
# + Video to gif
# + Video to Mp3
# + Screenshot
# + Screenshot and sound
# + Video cut
# + Sound off
# + Add sound
# + Mp3 compiling
#
# *** Requirements ***
# - FFmpeg
# - Mp3Wrap
#
#********************************************
#**** Version ****
Ver="1.1"
DATE="9/15/2018"
#**** Colors ****
W="\033[1;37m"
R="\033[1;31m"
G="\033[1;32m"
Y="\033[1;33m"
EC="\033[0m"
#~~~~ VAR ~~~~
SCRIPT="Checker"
FFMPG="ffmpeg"
#~~~~ Logo ~~~~
LOGO() {
echo -e "
${Y} ::: ... ... ::::::::::. .,:::::: :::::::..
;;; .;;;;;;;. .;;;;;;;. \`;;;\`\`\`.;;;;;;;'''' ;;;;\`\`;;;;
[[[ ,[[ \[[,,[[ \[[,\`]]nnn]]' [[cccc [[[,/[[['
$\$' $\$$, $\$$\$$\$, $\$$ $\$$\"\" $\$\"\"\"\" $\$$\$$$c
o88oo,.__\"888,_ _,88P\"888,_ _,88P 888o 888oo,__ 888b \"88bo,
\"\"\"\"YUMMM \"YMMMMMP\" \"YMMMMMP\" YMMMb \"\"\"\"YUMMMMMMM \"W\"\"
${G} Multimedia Automate${W} By${R} Kuro${W}-${R}Code${Y} Version${W}: $Ver\n"
}
#~~~~ Menus ~~~~
function Main() {
Place="Main"
clear
LOGO
echo -e "${W}
[ M A I N M E N U ]
[1]${G} Video To Gif${W} [5]${G} Screenshot${W}
[2]${G} Video To MP3${W} [6]${G} Screenshot + sound${W}
[3]${G} Video Cut${W} [7]${G} Add Sound${W}
[4]${G} Sound Off${W} [8]${G} MP3 Compiling${W}
[${R}0${W}]${R} Exit${EC} [${Y}9${W}]${Y} Info${W}\n"
read -p " Select: " OPT
case $OPT in
1) Video_To_Gif;;
2) Video_To_MP3;;
3) Video_Cut;;
4) Sound_Off;;
5) Screenshot;;
6) Screenshot;;
7) Add_Sound;;
8) Mp3_Compile;;
9) INFO;;
0) EXIT;;
esac
}
#~~~~ Video to Gif ~~~~
function Video_To_Gif() {
Place="Video_To_Gif"
clear
LOGO
read -p " Video file: " FVideo
Check_Video_File
Script
clear
LOGO
CHECKER_Video
echo -e "${R}▶${Y} Video Time${W}: $V"
echo -e "${Y} Example${W}:${G} 00${W}:${G}00${W}:${G}00${Y} (Hours:Minutes:Seconds)${W}"
read -p " Timer start: " Start_Timer
clear
LOGO
echo -e "${Y} Durée du Gif${W},${Y} Example${W}:${G} 10${W}"
read -p " Gif Timer: " Timer
clear
LOGO
echo -e "${Y} Size${W},${Y} Example${W}:${G} 500${W}"
read -p " Size of Gif: " SIZE
clear
LOGO
echo -e "${Y} Output file${W},${Y} Example${W}:${G} Image${W}"
read -p " Output: " OUT
clear
LOGO
Gif_Extract
Kill
rm -f $SCRIPT
Main
}
#~~~~ Video to MP3 ~~~~
function Video_To_MP3() {
Place="Video_To_MP3"
clear
LOGO
read -p " Video file: " FVideo
Check_Video_File
Script
clear
LOGO
CHECKER_Video
echo -e "${G}▶${Y} Video Time${W}: $V"
echo -e "${Y} Output file${W},${Y} Example${W}:${G} Music${W}"
read -p " Output: " OUT
Sound_Extract
Kill
rm -f $SCRIPT
Main
}
#~~~~ Video Cut ~~~~
function Video_Cut() {
Place="Video_Cut"
clear
LOGO
read -p " Video file: " FVideo
Check_Video
Script
clear
LOGO
CHECKER_Video
echo -e "${G}▶${Y} Video Time${W}: $V"
echo -e "${Y} Example${W}:${G} 00${W}:${G}00${W}:${G}00${W}.${G}00${Y} (Hours:Minutes:Seconds.Miliseconds)${W}"
read -p " Timer start: " Start_Timer
clear
LOGO
echo -e "${G}▶${Y} Video Time${W}: $V"
echo -e "${Y} Example${W}:${G} 00${W}:${G}00${W}:${G}00${W}.${G}00${Y} (Hours:Minutes:Seconds.Miliseconds)${W}"
read -p " Timer End: " End_Timer
clear
LOGO
echo -e "${Y} Output file${W},${Y} Example${W}:${G} Video.mp4${W}"
read -p " Output: " OUT
clear
LOGO
VCut
Kill
rm -f $SCRIPT
Main
}
#~~~~ Sound Off ~~~~
function Sound_Off() {
Place="Sound_Off"
clear
LOGO
read -p " Video file: " FVideo
Check_Video
clear
LOGO
echo -e "${Y} Output file, Example${W}:${G} Video.mp4${W}"
read -p " Output: " OUT
clear
LOGO
OFF
Kill
Main
}
#~~~~ Add Sound ~~~~
function Add_Sound() {
Place="Add_Sound"
clear
LOGO
read -p " Audio file: " FAudio
Check_Audio
clear
LOGO
read -p " Video file: " FVideo
Check_Video
Script
CHECKER_Audio
CHECKER_Video
clear
LOGO
echo -e "${G}▶${Y} Audio Time${W}: $A"
echo -e "${R}▶${Y} Video Time${W}: $V"
echo -e "${W}▷${Y} Example${W}:${G} 00${W}:${G}00${W}:${G}00${W}.${G}00${Y} (Hours:Minutes:Seconds.Miliseconds)${W}\n"
read -p " Start: " Start_Timer
clear
LOGO
echo -e "${Y} Output file, Example${W}:${Y} Video.mp4${W}"
read -p " Output: " VOUT
VSOUT="NewVideo.mp4"
VCut
}
#~~~~ Video Cut ~~~~
function VCut() {
if [ "$OPT" -eq "3" ]; then
xterm -T "Video Cut" -geometry 70x06+0+0 -e "$FFMPG -i $FVideo -ss $Start_Timer -t $End_Timer -c:v copy -c:a copy $OUT"
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Recording Completed${W} [${Y}!${W}]"
sleep 3
Main
fi
if [ "$OPT" -eq "7" ]; then
xterm -T "Video Cut" -geometry 70x06+0+0 -e "$FFMPG -i $FVideo -ss $Start_Timer -t $A -c:v copy -c:a copy $VSOUT"
Kill
sleep 3
Add
Kill
rm -f $VSOUT
rm -f $SCRIPT
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Recording Completed${W} [${Y}!${W}]"
sleep 3
Main
fi
}
#~~~~ Sound Off ~~~~
function OFF() {
xterm -T "Sound Off" -geometry 70x06+0+0 -e "$FFMPG -i $FVideo -c copy -an $OUT"
}
#~~~~ Screenshot ~~~~
function Screenshot() {
Place="Screenshot"
SR=`xdpyinfo | grep dimensions |awk '{print $2}'`
if [ "$OPT" -eq "5" ]; then
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Screenshot Window${W}:${R} Stop Recording${W}: [${G}Ctrl+C${W}]"
xterm -T "Screenshot" -geometry 70x06+0+0 -e "$FFMPG -f x11grab -r 30 -s $SR -i :0.0 -vcodec libx264 Screenshot.mkv"
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Recording Completed${W} [${Y}!${W}]"
sleep 3
Main
elif [ "$OPT" -eq "6" ]; then
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Screenshot Window${W}:${R} Stop Recording${W}: [${G}Ctrl+C${W}]"
xterm -T "Screenshot + Sound" -geometry 70x06+0+0 -e "$FFMPG -f alsa -ac 2 -i pulse -f x11grab -r 30 -s $SR -i :0.0 -acodec pcm_s16le -vcodec libx264 ScreenshotSound.mkv"
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Recording Completed${W} [${Y}!${W}]"
sleep 3
Main
fi
}
#~~~~ Compiling ~~~~
function Mp3_Compile() {
Place="Mp3_Compile"
clear
LOGO
read -p " Folder: " Folder
clear
LOGO
read -p " Output name: " OUT
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Process in progress, please wait${W} [${Y}!${W}]"
Compilation
Kill
NoTag
Kill
rm -f ${OUT}_MP3WRAP.mp3
Bitrate
Kill
clear
LOGO
echo -e "${W} [${Y}!${W}]${G} Compiling Completed${W} [${Y}!${W}]"
rm -f No_Tags.mp3
sleep 3
Main
}
#~~~~ Automation ~~~~
function Gif_Extract() {
xterm -T "Gif Extract" -geometry 70x06+0+0 -e "$FFMPG -ss $Start_Timer -t $Timer -i $FVideo -vf scale=$SIZE:-1 $OUT.gif"
}
function Sound_Extract() {
xterm -T "Extract" -geometry 70x06+0+0 -e "$FFMPG -i $FVideo -vn -ar 44100 -ac 2 -ab 256k -f mp3 $OUT.mp3"
}
#~~~~ Add Sound ~~~~
function Add() {
xterm -T "Insertion" -geometry 70x06+0+0 -e "$FFMPG -i $VSOUT -i $FAudio -c copy -map 0:0 -map 1:0 $VOUT"
}
#~~~~ Check Files ~~~~
function Check_Video_File() {
if [ ! -f "$FVideo" ]; then
echo -e " [${R}x${W}]$GR...$R""N$W""ot Exist$EC"
sleep 2
Main
fi
}
function Check_Audio_File() {
if [ ! -f "$FAudio" ]; then
echo -e " [${R}x${W}]$GR...$R""N$W""ot Exist$EC"
sleep 2
Main
fi
}
#~~~~ Check Dep ~~~~
function Check_Dep() {
clear
LOGO
echo -ne "FFmpeg....."
if ! hash ffmpeg 2>/dev/null; then
echo -e "Not installed [${R}x${W}]${EC}"
sleep 3
else
echo -e "[${G}✔${W}]${EC}"
fi
sleep 0.25
echo -ne "Mp3Wrap...."
if ! hash mp3wrap 2>/dev/null; then
echo -e "Not installed [${R}x${W}]${EC}"
sleep 3
EXIT
else
echo -e "[${G}✔${W}]${EC}"
fi
sleep 0.25
echo -ne "Xterm......"
if ! hash xterm 2>/dev/null; then
echo -e "Not installed [${R}x${W}]${EC}"
sleep 3
EXIT
else
echo -e "[${G}✔${W}]${EC}"
fi
sleep 3
}
#~~~~ Check Time ~~~~
function CHECKER_Video() {
V=`perl $SCRIPT $FVideo | grep duration: |awk '{print $2}' |sed 's/increasing/ /g'`
}
function CHECKER_Audio() {
A=`perl $SCRIPT $FAudio |grep duration: |awk '{print $2}'`
}
#~~~~ Compiling ~~~~
function Compilation() {
xterm -T "Compiling" -geometry 70x06+0+0 -e "mp3wrap $OUT.mp3 $Folder/*.mp3"
}
#~~~~ NoTag ~~~~
function NoTag() {
xterm -T "No Tag" -geometry 70x02+0+0 -e "ffmpeg -i ${OUT}_MP3WRAP.mp3 -map 0:a -map_metadata -1 No_Tags.mp3"
}
#~~~~ Bitrate ~~~~
function Bitrate() {
xterm -T "Bitrate" -geometry 70x02+0+0 -e "ffmpeg -i No_Tags.mp3 -vn -ar 44100 -ac 2 -ab 192k -f mp3 $OUT.mp3"
}
#~~~~ Kill ~~~~
function Kill() {
pkill xterm
}
#~~~~ Script ~~~~
function Script() {
echo "#!/usr/bin/perl -w
use strict;
use warnings;
use IPC::Open3;
# example
my \$filename = \$ARGV[0];
my %videoInfo = videoInfo(\$filename);
print \"duration: \" . \$videoInfo{'duration'} . \"\n\";
#
# returns media information in a hash
sub videoInfo {
# ffmpeg command
my \$ffmpeg = '/usr/bin/ffmpeg';
my %finfo = (
'duration' => \"00:00:00.00\",
);
my \$file = shift;
# escaping characters
\$file =~ s/(\W)/\\\\\$1/g;
open3( \"</dev/null\", \">/dev/null\", \*ERPH, \"\$ffmpeg -i \$file\" ) or die \"can't run \$ffmpeg\n\";
my @res = <ERPH>;
# parse ffmpeg output
foreach (@res) {
print;
# duration
if (m!Duration: ([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])!) {
\$finfo{'duration'} = \$1;
}
}
my \$tenths = substr( \$finfo{'duration'}, 9, 2 );
my \$seconds = substr( \$finfo{'duration'}, 6, 2 );
my \$minutes = substr( \$finfo{'duration'}, 3, 2 );
my \$hours = substr( \$finfo{'duration'}, 0, 2 );
return %finfo;
}" > $SCRIPT
}
#~~~~ Info ~~~~
function INFO() {
clear
LOGO
echo -e "
${W} ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃${G} Name${W}: Looper ┃
┃${G} Date${W}: $DATE ┃
┃${G} Type${W}: Multimedia ┃
┃${G} Dev${W}: Shell ┃
┃${G} Ver${W}: $Ver ┃
┃${G} Coder${W}: Kuro-Code ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
${Y} Return to Main menu, press ${R}[ENTER]${W}."
read -p ""
Main
}
#~~~~ EXIT ~~~~
function EXIT() {
clear
if [ ! -f "$SCRIPT" ]; then
LOGO
echo -e "${W} Thanks for using Looper\n"
sleep 1
echo -e " [${R}✔${W}]${G} Closing ${W}[${R}✔${W}]${EC}"
sleep 3
clear
exit
else
rm -f $SCRIPT
EXIT
fi
}
#~~~~ Hard Exit ~~~~
function cap_traps() {
case $Place in
"Main") EXIT;;
"Video_To_Gif") EXIT;;
"Video_To_MP3") EXIT;;
"Screenshot") EXIT;;
"Video_Cut") EXIT;;
"Sound_Off") EXIT;;
"Add_Sound") EXIT;;
"Mp3_Compile") EXIT;;
"INFO") EXIT;;
esac
}
for x in SIGINT SIGHUP INT SIGTSTP; do
trap_cmd="trap \"cap_traps $x\" \"$x\""
eval "$trap_cmd"
done
#~~~~ START ~~~~
Check_Dep
Main