-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvideo_save_functions.sh
executable file
·223 lines (181 loc) · 7.02 KB
/
video_save_functions.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
function MAIN_VIDEO_SAVE_FUNCTION {
echo "================== SAVE FUNCTION (tty6) ==========================="
echo
# only run save function if we are RX
if [ "$CAM" == "0" ]; then
echo "Waiting some time until everything else is running ..."
sleep 30
echo "Waiting for USB stick to be plugged in ..."
KILLED=0
LIMITFREE=3000 # 3 mbyte
while true; do
if [ ! -f "/tmp/donotsave" ]; then
if [ -e "/dev/sda" ]; then
echo "USB Memory stick detected"
save_function
fi
fi
# check if tmp disk is full, if yes, kill cat process
if [ "$KILLED" != "1" ]; then
FREETMPSPACE=`nice df -P /wbc_tmp/ | nice awk 'NR==2 {print $4}'`
if [ $FREETMPSPACE -lt $LIMITFREE ]; then
echo "RAM disk full, killing cat video file writing process ..."
ps -ef | nice grep "cat /root/videofifo3" | nice grep -v grep | awk '{print $2}' | xargs kill -9
KILLED=1
fi
fi
sleep 1
done
fi
echo "Save function not enabled, we are TX"
sleep 365d
}
function save_function {
# let screenshot and check_alive function know that saving is in progrss
touch /tmp/pausewhile
# kill OSD so we can safeley start wbc_status
ps -ef | nice grep "osd" | nice grep -v grep | awk '{print $2}' | xargs kill -9
# kill video and telemetry recording and also local video display
ps -ef | nice grep "cat /root/videofifo3" | nice grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | nice grep "cat /root/telemetryfifo3" | nice grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | nice grep "$DISPLAY_PROGRAM" | nice grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | nice grep "cat /root/videofifo1" | nice grep -v grep | awk '{print $2}' | xargs kill -9
# kill video rx
ps -ef | nice grep "rx -p 0" | nice grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | nice grep "ftee /root/videofifo" | nice grep -v grep | awk '{print $2}' | xargs kill -9
# find out if video is on ramdisk or sd
source /tmp/videofile
echo "VIDEOFILE: $VIDEOFILE"
# start re-play of recorded video ....
nice /opt/vc/src/hello_pi/hello_video/hello_video.bin.player $VIDEOFILE $FPS &
killall wbc_status > /dev/null 2>&1
nice /home/pi/wifibroadcast-status/wbc_status "Saving to USB. This may take some time ..." 7 55 0 &
echo -n "Accessing file system.. "
# some sticks show up as sda1, others as sda, check for both
if [ -e "/dev/sda1" ]; then
USBDEV="/dev/sda1"
else
USBDEV="/dev/sda"
fi
echo "USBDEV: $USBDEV"
if mount $USBDEV /media/usb; then
TELEMETRY_SAVE_PATH="/telemetry"
SCREENSHOT_SAVE_PATH="/screenshot"
VIDEO_SAVE_PATH="/video"
RSSI_SAVE_PATH=/"rssi"
if [ -d "/media/usb$RSSI_SAVE_PATH" ]; then
echo "RSSI save path $RSSI_SAVE_PATH found"
else
echo "Creating RSSI save path $RSSI_SAVE_PATH.. "
mkdir /media/usb$RSSI_SAVE_PATH
fi
if [ -d "/media/usb$TELEMETRY_SAVE_PATH" ]; then
echo "Telemetry save path $TELEMETRY_SAVE_PATH found"
else
echo "Creating Telemetry save path $TELEMETRY_SAVE_PATH.. "
mkdir /media/usb$TELEMETRY_SAVE_PATH
fi
killall rssilogger
killall syslogger
killall wifibackgroundscan
gnuplot -e "load '/root/gnuplot/videorssi.gp'" &
gnuplot -e "load '/root/gnuplot/videopackets.gp'"
gnuplot -e "load '/root/gnuplot/telemetrydownrssi.gp'" &
gnuplot -e "load '/root/gnuplot/telemetrydownpackets.gp'"
if [ "$TELEMETRY_UPLINK" != "disabled" ]; then
gnuplot -e "load '/root/gnuplot/telemetryuprssi.gp'" &
gnuplot -e "load '/root/gnuplot/telemetryuppackets.gp'"
fi
if [ "$RC" != "disabled" ]; then
gnuplot -e "load '/root/gnuplot/rcrssi.gp'" &
gnuplot -e "load '/root/gnuplot/rcpackets.gp'"
fi
if [ "$DEBUG" == "Y" ]; then
gnuplot -e "load '/root/gnuplot/wifibackgroundscan.gp'" &
fi
cp /wbc_tmp/*.csv /media/usb$RSSI_SAVE_PATH/
if [ -s "/wbc_tmp/telemetrydowntmp.raw" ]; then
cp /wbc_tmp/telemetrydowntmp.raw /media/usb$TELEMETRY_SAVE_PATH/telemetrydown`ls /media/usb$TELEMETRY_SAVE_PATH/*.raw | wc -l`.raw
cp /wbc_tmp/telemetrydowntmp.txt /media/usb$TELEMETRY_SAVE_PATH/telemetrydown`ls /media/usb$TELEMETRY_SAVE_PATH/*.txt | wc -l`.txt
fi
killall tshark
cp /wbc_tmp/*.pcap /media/usb
cp /wbc_tmp/*.cap /media/usb
cp /wbc_tmp/airodump.png /media/usb
if [ "$ENABLE_SCREENSHOTS" == "Y" ]; then
if [ -d "/media/usb$SCREENSHOT_SAVE_PATH" ]; then
echo "Screenshots save path $SCREENSHOT_SAVE_PATH found"
else
echo "Creating screenshots save path $SCREENSHOT_SAVE_PATH.. "
mkdir /media/usb$SCREENSHOT_SAVE_PATH
fi
DIR_NAME_SCREENSHOT=/media/usb$SCREENSHOT_SAVE_PATH/`ls /media/usb$SCREENSHOT_SAVE_PATH | wc -l`
mkdir $DIR_NAME_SCREENSHOT
cp /wbc_tmp/screenshot* $DIR_NAME_SCREENSHOT > /dev/null 2>&1
fi
if [ -s "$VIDEOFILE" ]; then
if [ -d "/media/usb$VIDEO_SAVE_PATH" ]; then
echo "Video save path $VIDEO_SAVE_PATH found"
else
echo "Creating video save path $VIDEO_SAVE_PATH.. "
mkdir /media/usb$VIDEO_SAVE_PATH
fi
FILE_NAME_AVI=/media/usb$VIDEO_SAVE_PATH/video`ls /media/usb$VIDEO_SAVE_PATH | wc -l`.avi
echo "FILE_NAME_AVI: $FILE_NAME_AVI"
nice avconv -framerate $FPS -i $VIDEOFILE -vcodec copy $FILE_NAME_AVI > /dev/null 2>&1 &
AVCONVRUNNING=1
while [ $AVCONVRUNNING -eq 1 ]; do
AVCONVRUNNING=`pidof avconv | wc -w`
#echo "AVCONVRUNNING: $AVCONVRUNNING"
sleep 4
killall wbc_status > /dev/null 2>&1
nice /home/pi/wifibroadcast-status/wbc_status "Saving - please wait ..." 7 65 0 &
done
fi
#cp /wbc_tmp/tracker.txt /media/usb/
cp /wbc_tmp/debug.txt /media/usb/
cp /wbc_tmp/telemetrydowndebug.txt /media/usb$TELEMETRY_SAVE_PATH/
cp /wbc_tmp/telemetryupdebug.txt /media/usb$TELEMETRY_SAVE_PATH/
nice umount /media/usb
STICKGONE=0
while [ $STICKGONE -ne 1 ]; do
killall wbc_status > /dev/null 2>&1
nice /home/pi/wifibroadcast-status/wbc_status "Done - USB memory stick can be removed now" 7 65 0 &
sleep 4
if [ ! -e "/dev/sda" ]; then
STICKGONE=1
fi
done
killall wbc_status > /dev/null 2>&1
killall hello_video.bin.player > /dev/null 2>&1
rm /wbc_tmp/* > /dev/null 2>&1
rm /video_tmp/* > /dev/null 2>&1
sync
else
STICKGONE=0
while [ $STICKGONE -ne 1 ]; do
killall wbc_status > /dev/null 2>&1
nice /home/pi/wifibroadcast-status/wbc_status "ERROR: Could not access USB memory stick!" 7 65 0 &
sleep 4
if [ ! -e "/dev/sda" ]; then
STICKGONE=1
fi
done
killall wbc_status > /dev/null 2>&1
killall hello_video.bin.player > /dev/null 2>&1
fi
#killall tracker
# re-start video/telemetry recording
ionice -c 3 nice cat /root/videofifo3 >> $VIDEOFILE &
ionice -c 3 nice cat /root/telemetryfifo3 >> /wbc_tmp/telemetrydowntmp.raw &
killall wbc_status > /dev/null 2>&1
OSDRUNNING=`pidof /tmp/osd | wc -w`
if [ $OSDRUNNING -ge 1 ]; then
echo "OSD already running!"
else
killall wbc_status > /dev/null 2>&1
/tmp/osd >> /wbc_tmp/telemetrydowntmp.txt &
fi
# let screenshot function know that it can continue taking screenshots
rm /tmp/pausewhile
}