-
Notifications
You must be signed in to change notification settings - Fork 3
/
vicor
executable file
·99 lines (83 loc) · 2.06 KB
/
vicor
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
#!/data/data/com.termux/files/usr/bin/bash
videodir="${VICOR_VIDEO_DIR:-/storage/0123-4567/DCIM/Camera}"
outputdir="${VICOR_OUTPUT_DIR:-${HOME}/vicor/data}"
maxsize="${VICOR_MAX_SIZE:-720}"
aacquality="${VICOR_AAC_QUALITY:-2.0}"
suffix="${VICOR_FILE_SUFFIX:-mp4}"
function is_termux() {
command -v termux-wake-lock > /dev/null 2>&1
}
if [ -n "$1" ]; then
file="$1"
else
cd "${videodir}"
ls *.${suffix}
for file in *.${suffix}; do
history -s "${file}"
done
read -e -p '> ' file
if [ -z "${file}" ]; then
last="$(ls *.${suffix} |tail -n 1)"
read -e -p '> ' -i "${last}" file
fi
file="${videodir}/${file}"
fi
if [ ! -e "${file}" ]; then
echo "File '${file}' does not exist, bailing out." >&2
exit 1
fi
outfile="${outputdir}/$(basename "${file}" .${suffix}).${suffix}"
while true; do
read -p "Video size: [o]original [s]mall " -n 1 ans
echo
case "${ans,,}" in
o) break ;;
s) break ;;
esac
done
if is_termux; then
termux-wake-lock
trap termux-wake-unlock EXIT
fi
if [[ "${ans,,}" == "s" ]] ; then
ffmpeg -i "${file}" \
-c:a aac -q:a ${aacquality} \
-filter:v scale="w=(trunc(min(a*$maxsize\,$maxsize)/2)*2):h=(trunc(min($maxsize/a\,$maxsize)/2)*2)" \
-c:v libx264 \
-profile:v high \
-preset medium \
-crf 23 \
"${outfile}"
elif [[ "${ans,,}" == "o" ]] ; then
ffmpeg -i "${file}" \
-acodec copy \
-vcodec libx264 \
-profile:v high \
"${outfile}"
else
exit 1
fi
if is_termux; then
termux-vibrate
termux-wake-unlock
trap - EXIT
open_command='termux-open'
send_command='termux-share -a send'
else
open_command='xdg-open'
send_command='xdg-email --attach'
fi
echo
echo "Old file: $(du -h "${file}")"
echo "New file: $(du -h "${outfile}")"
while true; do
read -p "[v]iew [s]end [r]emove [q]uit " -n 1 ans
echo
case "${ans,,}" in
v) $open_command "${outfile}" ;;
s) $send_command "${outfile}" ;;
r) rm "${outfile}"
break ;;
q) break ;;
esac
done