-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxstack
More file actions
149 lines (132 loc) · 4.34 KB
/
xstack
File metadata and controls
149 lines (132 loc) · 4.34 KB
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
#!/bin/bash
#: xstack
#: Copyright (c) 2024 DankoScientific
clear #: Clean slate, bayyybeeeeeeeeeeeeeeeee
any_key() {
echo "Any key to continue (CTRL + C to cancel)"
read -n 1 -s
echo ""
}
show_menu() {
echo -n "## NAME: "
IFS= read -r scene_name
echo -n "## SCALE: "
IFS= read -r scene_scale
echo -n "## CROP: "
IFS= read -r scene_crop
echo ""
}
final_destination="/YOUR/PATH/HERE/"
topleft=$1
topright=$2
bottomleft=$3
bottomright=$4
get_four=$(printf "%s\n" "$topleft" "$topright" "$bottomleft" "$bottomright")
time_compare() {
shortest_duration=999999.999999
for i in $get_four; do
duration=$(ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 $i | cut -d '.' -f 1,2) # removes milliseconds
echo "$i" | sed 's/^/-i /' # adds -i before each file for the FFMPEG part below
if [ $(echo "$duration < $shortest_duration" | bc -l) -eq 1 ]; then
shortest_duration="$duration"
fi
done
}
get_fnames() {
time_compare
echo $shortest_duration
}
get_bitrate() {
bit_vid=$(find . -type f -iname 'out*.mp4' -printf %"f\n" | head -n 1)
audio_bitrate=$(ffprobe -v error -show_entries format=bit_rate -of default=nw=1:nk=1 -i "$bit_vid")
echo "$audio_bitrate"
}
end_of_file=$(date +%s | cut -b 7-10) #: revolutionary file naming system
use_four=$(get_fnames) # used to run time_compare
use_four1=$(echo "$use_four" | head -n 4) # this removes shortest_duration out for the FFMPEG part below
use_fade=$(echo "$use_four" | cut -d " " -f1 | tail -n 1) # takes shortest_duration and then uses to subtract 1 below to fade out
use_bit=$(get_bitrate) # get audio bitrate
xstack_picker() {
echo "+------+------+"
echo "| | |"
echo "+---x-stack---+"
echo "| | |"
echo "+------+------+"
echo ""
echo "The lucky chosen: "
echo "$use_four"
echo ""
}
xstack_picker
any_key
show_menu
if [ "$scene_crop" = "qhd" ]; then
crop_filter="960:540:'(iw-ow)/2':0" #: center top video 960x540
elif [ "$scene_crop" = "" ]; then
crop_filter="iw:ih"
else
crop_filter="$scene_crop"
fi
#: FFMPEG Variables
err="-v 16 -stats -hwaccel vdpau"
scaler="scale=iw/$scene_scale:ih/$scene_scale"
cropper="crop=$crop_filter"
border_tl="fillborders=right=1:bottom=1:mode=fixed:color=black"
border_tr="fillborders=left=1:bottom=1:mode=fixed:color=black"
border_bl="fillborders=right=1:top=1:mode=fixed:color=black"
border_br="fillborders=left=1:top=1:mode=fixed:color=black"
make_stack="xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0|:shortest=1"
sardar="setsar=w/h,setdar=w/h"
font_loc="fontfile=/PATH/TO/FONT/FILE:fix_bounds=true"
font_opt="fontsize=h/36:x=3:y=(h-th-2):fontcolor_expr=FFFFFF%{eif\\\\: clip(255*(1*between(t\\, 0.0 + 1.0\\, 5.0 - 1.0) + ((t - 0.0)/1.0)*between(t\\, 0.0\\, 0.0 + 1.0) + (-(t - 5.0)/1.0)*between(t\\, 5.0 - 1.0\\, 5.0) )\\, 0\\, 255) \\\\: x\\\\: 2 }"
text_opt="text='Your text here!'"
text_draw="drawtext=$font_loc:$font_opt:$text_opt"
fade_duration="$(echo "$use_fade - 1" | bc -l)"
fadeout="fade=out:st=$fade_duration:d=1"
audio_join="amerge=inputs=4,afade=t=out:st=$fade_duration:d=1"
vcodec="-c:v libx264 -crf 21 -preset faster -tune film -pix_fmt yuv420p -movflags +faststart"
final_name="xstack-$scene_name-$end_of_file.mp4"
use_ffmpeg() {
ffmpeg $err \
$use_four1 \
-filter_complex " \
[0:v]$scaler,$cropper,$border_tl[v1]; \
[1:v]$scaler,$cropper,$border_tr[v2]; \
[2:v]$scaler,$cropper,$border_bl[v3]; \
[3:v]$scaler,$cropper,$border_br[v4]; \
[0:a][1:a][2:a][3:a]$audio_join[a]; \
[v1][v2][v3][v4]$make_stack,$sardar,$text_draw,$fadeout[out]" \
-map "[out]" -map "[a]" $vcodec $final_name
}
play_file() {
read -e -p "Play $final_name? Y/n " -n 3 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
play $final_name 0 1
play_file
else
move_file
return
fi
}
delete_file() {
read -e -p "Delete files? Y/n " -n 3 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm $use_four1
return
else
move_file
return
fi
}
move_file() {
read -e -p "Move to $final_destination Y/n " -n 3 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
rsync --remove-source-files --info=progress2 $final_name $final_destination/$final_name
delete_file
else
play_file
return
fi
}
use_ffmpeg
play_file