forked from Shell-Company/QRExfil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode.sh
executable file
·60 lines (49 loc) · 1.17 KB
/
encode.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
#!/bin/bash
# requires qrencode and ffmpeg
# get file from input
file="$1"
output="$2"
# check if 2nd argument is provided
if [ -z "$output" ]; then
output = "output.gif"
fi
# check if the file exists
if [ ! -f "$file" ]; then
echo "File not found"
exit 1
fi
# get size of file in bytes
# filesize=$(stat -f "%z" "$file" || stat -c%s "$file")
if [ "$(uname)" == "Darwin" ]; then
filesize=$(stat -f "%z" "$file")
else
filesize=$(stat -c%s "$file")
fi
# calculate size of each chunk
chunksize=64
# determine number of chunks
nchunks=$((filesize/chunksize))
# create chunks
echo "Creating chunks..."
for i in $(seq 0 $nchunks); do
dd if="$file" of=chunk_"$i" bs="$chunksize" skip="$i" count=1
echo "Created chunk $i"
done
# generate qrcode images
echo "Generating qrcodes..."
for i in $(seq 0 $nchunks); do
qrencode -t png -o frame_"$i".png < chunk_"$i" -s 8 -8
echo "Generated qrcode $i"
done
# combine qrcode images into gif
echo "Creating gif..."
if [ "$(uname)" == "Darwin" ]; then
ffmpeg -y -r 10 -i frame_%d.png $output
else
ffmpeg -i frame_%d.png $output -y -r 10
fi
# clean up
echo "Cleaning up..."
rm -f chunk_*
rm -f frame_*
echo "Done!"