-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexport.sh
executable file
·130 lines (110 loc) · 2.75 KB
/
export.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
#!/bin/bash
## outputs usage
osx_screenshot_export_usage () {
echo "usage: osx-screenshot-export [-h]"
echo " or: osx-screenshot-export [-f fps] [-s scale] [-d delay] <src> <dest>"
echo
echo "options:"
echo " -f,--fps Frames per second (Default: 10)"
echo " -s,--scale Output scaling (Default: 320:-1)"
echo " -d,--delay Frame delay"
echo " -h,--help Show this message"
return 0
}
## main
osx_screenshot_export () {
local arg="${1}"
local scale="320:-1"
local fps="10"
local delay="5"
local src=""
local dest=""
local tmpdir=${TMPDIR:-/tmp}
local tmp=""
local fcmd=""
## enure dependencies exist or bail
osx_screenshot_dependencies || return $?
## parse opts
for arg in "${@}"; do
case "${arg}" in
-h|--help)
osx_screenshot_export_usage
return 0
;;
-s|--scale| \
-d|--delay| \
-f|--fps) \
shift
if [ -z "${1:0:1}" ]; then
echo >&2 "error: Missing value of \`${arg}'"
elif [ "-" = "${1:0:1}" ]; then
echo >&2 "error: Invalid option \`${1}'"
else
case "${arg}" in
-s|--scale) scale="${1}" ;;
-d|--delay) delay="${1}" ;;
-f|--fps) fps="${1}" ;;
esac
shift
continue
fi
osx_screenshot_export_usage
return 1
;;
*)
if [ "-" = "${arg:0:1}" ]; then
continue
fi
if [ -z "${src}" ]; then
src="${1}"
shift
elif [ -z "${dest}" ]; then
dest="${1}"
shift
fi
;;
esac
done
## ensure source
if [ -z "${src}" ]; then
echo >&2 "error: Missing source file"
osx_screenshot_export_usage
return 1
fi
## ensure destination
if [ -z "${dest}" ]; then
echo >&2 "error: Missing destination file"
osx_screenshot_export_usage
return 1
fi
## tmp frame dir
tmp="${tmpdir}/frames-${src}-${dest}"
## purge
rm -rf "${tmp}"
## create
mkdir -p "${tmp}"
## create frames with ffmpeg
echo >&2 "Transcoding frames..."
(
ffmpeg -i "${src}" -vf scale=${scale} -r ${fps} "${tmp}"/f%03d.png > /dev/null 2>&1
)
if (( $? > 0 )); then
echo >&2 "error: An error occured during frame transcoding"
return $?
fi
## convert and write to desired file
echo >&2 "Converting and writing to destination..."
(
convert -delay ${delay} -loop 0 "${tmp}"/f*.png "${dest}" > /dev/null 2>&1
)
if (( $? > 0 )); then
echo >&2 "error: An error occured during transcoding convert (${src} => ${dest})"
return $?
fi
printf >&2 'Ok! (%s => %s)\n' "${src}" "${dest}"
return 0
}
## export
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
export -f osx_screenshot_export
fi