-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo2binary
executable file
·62 lines (52 loc) · 1.3 KB
/
video2binary
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
#!/usr/bin/env bash
usage_and_exit () {
echo "Usage: video2binary [-v] infile outfile"
exit $1
}
check_executable_or_exit() {
if [ ! -x $1 ]; then
echo "error: no $(basename $1) at $gzip"
exit 2
fi
}
if [ \( $# -eq 1 \) -a \( "$1" = '--help' \) ]; then
usage_and_exit 0
fi
# check needed binaries
gzip=/usr/bin/gzip
check_executable_or_exit $gzip
ffmpeg=/usr/bin/ffmpeg
check_executable_or_exit $ffmpeg
# check parameters
verbose=0
while getopts 'v' option; do
case "$option" in
v) verbose=1;;
?) usage_and_exit 1;;
esac
done
shift $(($OPTIND - 1))
if [ $# != 2 ]; then
usage_and_exit 1
fi
if [ ! -r "$1" ]; then
echo "error: file '$1' does not exist or is not readable"
exit 4
fi
tmpfile_gzipped=$(mktemp --tmpdir video2binary.gz.XXXXXXXXXX)
infile="$1"
outfile="$2"
pixel_format=rgb24
$ffmpeg -y -hide_banner -loglevel error \
-i "${infile}" -f rawvideo -pix_fmt rgb24 "${tmpfile_gzipped}"
size_gzipped=$(stat --format=%s ${tmpfile_gzipped})
if [ $verbose = 1 ]; then
echo "gzipped file has $size_gzipped bytes"
fi
$gzip -d -c "${tmpfile_gzipped}" > "${outfile}"
if [ $verbose = 1 ]; then
echo "output file has $(stat --format=%s "${outfile}") bytes"
echo -n "output file MD5: "
md5sum "${outfile}" | cut -d\ -f1
fi
rm ${tmpfile_gzipped}