forked from larsdehlwes/highspeed-raspiraw_rpi4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw2ogg2anim
executable file
·128 lines (95 loc) · 3.03 KB
/
raw2ogg2anim
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
#!/bin/bash
# needs: dcraw, double, netpbm tools, gstreamer, gifenc.sh
#Determining the model of Raspberry Pi we're running on, to set an appropriate number of parallell processes
if [ "`lscpu | grep 'Model' | grep -o 'A72'`" = "A72" ]; then
num_processes=40
echo "Model 4, running 40 parallell processes"
else
if [ "`lscpu | grep 'Model' | grep -o 'A53'`" = "A53" ]; then
num_processes=20
echo "Model 3, running 20 parallell processes"
else
num_processes=10
echo "couldn't determine model, running 10 parallell processes"
fi
fi
#The following three code blocks define functions to be called later
#1. converts raw frames to png format
dcraw_conversion() {
dcraw $f
echo -en "$f \r"
}
#2. stretches lines so that videos recorded with line skips look better
line_doubling() {
if [ "$5" = "" ]; then
ln -s $f $f.d
else
if [ "$5" = "d" ]; then
double $f > $f.d
else
double $f > $f.D
double $f.D > $f.d
fi
fi
echo -en "$f \r"
}
#3. converts from intermediary format ppm to final image format png
ppmtopng_conversion() {
pnmtopng $f > $f.png
echo -en "$f \r"
}
# Taking user inputs
if [ "$4" = "" ]; then echo "format: `basename $0` vname first last fps [-t] [-k] [d[d]]"; exit; fi
# If the user inputs "-t" as parameter 5, then we append the current date and time to the filename
if [ "$5" = "-t" ]; then
echo "appending date and time to filename"
momentOfCapture=`date +%m.%d_T%H:%M:%S`
fi
# if the user adds the command line option -c or --count, ls | grep $1 is run in cwd,
# and the new filename is incremented by one in relation to the highest numbered similar filename.
#ls | grep $1
echo "removing old auxiliary files"
rm -f out.*.raw out.*.ppm out.*.ppm.[dDT] out.*.ppm.d.png
# this command appears to be slower when parallellized, so it's a single process for the time being.
echo "copying /dev/shm/out.????.raw files"
for((f=$2; f<=$3; ++f))
do
cat /dev/shm/hd0.32k /dev/shm/out.$(printf "%04d" $f).raw >out.$(printf "%04d" $f).raw
echo -en "$f \r"
done
echo "dcraw each .raw file (to .ppm)"
for f in out.*.raw
do
((i=i%num_processes)); ((i++==0)) && wait
dcraw_conversion &
done
wait
echo ".ppm -> .ppm.d"
for f in out.*.ppm
do
((i=i%num_processes)); ((i++==0)) && wait
line_doubling &
done
wait
echo ".ppm.d -> .ppm.d.png"
for f in out.*.ppm.d
do
((i=i%num_processes)); ((i++==0)) && wait
ppmtopng_conversion &
done
wait
echo "now creating $1.ogg"
gst-launch-1.0 multifilesrc location="out.%04d.ppm.d.png" index=$2 caps="image/png,framerate=\(fraction\)$4/1" ! pngdec ! videorate ! videoconvert ! videorate ! theoraenc ! oggmux ! filesink location="$1.ogg"
if [ "$5" = "-T" ]; then
echo "now creating $1-$momentOfCapture.gif"
gifenc.sh $1.ogg $1-$momentOfCapture.gif
else
echo "now creating $1.gif"
gifenc.sh $1.ogg $1.gif
fi
#comment the following two line if you want to keep individual image frames and other files in the current directory
if [ "$6" != "-k" ]; then
echo "removing new auxiliary files"
rm -f out.*
fi
echo "done"