1 | #!/bin/ksh |
---|
2 | # process_dvr_output - a script processing dvr steering + data files |
---|
3 | # $Id: process_dvr_output 261 2009-03-17 04:52:51Z raasch $ |
---|
4 | |
---|
5 | # This script determines the number of streams opened by the dvr software |
---|
6 | # and creates one single dvrs- and html-file which allow the dvr-plugin |
---|
7 | # to display all streams in one sequence. |
---|
8 | |
---|
9 | # Last changes: |
---|
10 | # 16/03/09 - Siggi - Generating the first version |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | # variable declarations + default values |
---|
15 | camera=false |
---|
16 | create_sequence_output=false |
---|
17 | data_catalog=`pwd` |
---|
18 | file_identifier=all_streams |
---|
19 | groundplate=false |
---|
20 | topography=false |
---|
21 | |
---|
22 | typeset -i i j nstream nscenes |
---|
23 | |
---|
24 | |
---|
25 | # read shellscript options |
---|
26 | while getopts :d:f:s option |
---|
27 | do |
---|
28 | case $option in |
---|
29 | (d) data_catalog=$OPTARG;; |
---|
30 | (f) file_identifier=$OPTARG;; |
---|
31 | (s) create_sequence_output=true;; |
---|
32 | (\?) printf "\n +++ unknown option $OPTARG \n" |
---|
33 | printf "\n allowed option are -d and -f \n" |
---|
34 | exit;; |
---|
35 | esac |
---|
36 | done |
---|
37 | |
---|
38 | |
---|
39 | # change to the given directory |
---|
40 | cd $data_catalog |
---|
41 | |
---|
42 | |
---|
43 | # find out the number of streams |
---|
44 | (( i = 0 )) |
---|
45 | while true |
---|
46 | do |
---|
47 | (( i = i + 1 )) |
---|
48 | if (( i < 10 )) |
---|
49 | then |
---|
50 | cstream=0$i |
---|
51 | else |
---|
52 | cstream=$i |
---|
53 | fi |
---|
54 | |
---|
55 | if [[ $(ls -1 *.* | grep -c $cstream) = 0 ]] |
---|
56 | then |
---|
57 | (( i = i - 1 )) |
---|
58 | break |
---|
59 | fi |
---|
60 | |
---|
61 | # find out the stream name |
---|
62 | streamname[$i]=`ls -1 ${cstream}_*-ge.dvrs | cut -f1 -d"-"` |
---|
63 | |
---|
64 | # get addres |
---|
65 | adr[$i]=`grep ADR= ${streamname[$i]}.dvrs | grep '*' | cut -f2 -d"="` |
---|
66 | |
---|
67 | # get maxbytes |
---|
68 | maxbytes[$i]=`head -1 ${streamname[$i]}.max` |
---|
69 | |
---|
70 | # get number of frames |
---|
71 | frames[$i]=`tail -1 ${streamname[$i]}.max` |
---|
72 | |
---|
73 | done |
---|
74 | |
---|
75 | nstream=$i |
---|
76 | nscenes=$nstream |
---|
77 | |
---|
78 | |
---|
79 | # Check, if there are files containing the camera data, the ground plate |
---|
80 | # and topography data. |
---|
81 | # Check the first stream only, because all streams have the same files. |
---|
82 | if [[ -f ${streamname[1]}_camera.max ]] |
---|
83 | then |
---|
84 | camera=true |
---|
85 | adr_camera=`grep ADR= ${streamname[1]}.dvrs | grep 'camera' | cut -f2 -d"="` |
---|
86 | maxbytes_camera=`head -1 ${streamname[1]}_camera.max` |
---|
87 | (( nscenes = nscenes + 1 )) |
---|
88 | fi |
---|
89 | if [[ -f ${streamname[1]}_groundplate.max ]] |
---|
90 | then |
---|
91 | groundplate=true |
---|
92 | adr_groundplate=`echo $adr_camera | sed "s/camera/groundplate/g"` |
---|
93 | maxbytes_groundplate=`head -1 ${streamname[1]}_groundplate.max` |
---|
94 | (( nscenes = nscenes + 1 )) |
---|
95 | fi |
---|
96 | if [[ -f ${streamname[1]}_topography.max ]] |
---|
97 | then |
---|
98 | topography=true |
---|
99 | adr_topography=`echo $adr_camera | sed "s/camera/topography/g"` |
---|
100 | maxbytes_topography=`head -1 ${streamname[1]}_topography.max` |
---|
101 | (( nscenes = nscenes + 1 )) |
---|
102 | fi |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | # start with writing the dvrs file for the combined streams |
---|
107 | dvr_file=${file_identifier}_streaming.dvrs |
---|
108 | |
---|
109 | echo "SCENES=$nscenes" > $dvr_file |
---|
110 | |
---|
111 | # first, add the static scenes |
---|
112 | if [[ $camera = true ]] |
---|
113 | then |
---|
114 | echo "MED=TCP" >> $dvr_file |
---|
115 | echo "ADR=$adr_camera" >> $dvr_file |
---|
116 | echo "MAXBYTES=$maxbytes_camera" >> $dvr_file |
---|
117 | echo "FRAMES=1" >> $dvr_file |
---|
118 | echo "FRAMES_P_SEC=0" >> $dvr_file |
---|
119 | echo "SCENEEND" >> $dvr_file |
---|
120 | fi |
---|
121 | |
---|
122 | if [[ $groundplate = true ]] |
---|
123 | then |
---|
124 | echo "MED=TCP" >> $dvr_file |
---|
125 | echo "ADR=$adr_groundplate" >> $dvr_file |
---|
126 | echo "MAXBYTES=$maxbytes_groundplate" >> $dvr_file |
---|
127 | echo "FRAMES=1" >> $dvr_file |
---|
128 | echo "FRAMES_P_SEC=0" >> $dvr_file |
---|
129 | echo "SCENEEND" >> $dvr_file |
---|
130 | fi |
---|
131 | |
---|
132 | if [[ $topography = true ]] |
---|
133 | then |
---|
134 | echo "MED=TCP" >> $dvr_file |
---|
135 | echo "ADR=$adr_topography" >> $dvr_file |
---|
136 | echo "MAXBYTES=$maxbytes_topography" >> $dvr_file |
---|
137 | echo "FRAMES=1" >> $dvr_file |
---|
138 | echo "FRAMES_P_SEC=0" >> $dvr_file |
---|
139 | echo "SCENEEND" >> $dvr_file |
---|
140 | fi |
---|
141 | |
---|
142 | |
---|
143 | # now add the streams |
---|
144 | (( i = 0 )) |
---|
145 | while (( i < nstream )) |
---|
146 | do |
---|
147 | |
---|
148 | (( i = i + 1 )) |
---|
149 | |
---|
150 | echo "MED=TCP" >> $dvr_file |
---|
151 | echo "ADR=${adr[$i]}" >> $dvr_file |
---|
152 | echo "MAXBYTES=${maxbytes[$i]}" >> $dvr_file |
---|
153 | echo "FRAMES=${frames[$i]}" >> $dvr_file |
---|
154 | echo "FRAMES_P_SEC=25" >> $dvr_file |
---|
155 | echo "SCENEEND" >> $dvr_file |
---|
156 | |
---|
157 | done |
---|
158 | |
---|
159 | |
---|
160 | # change path to the current file identifier |
---|
161 | sed "s/DATA_DVR/${file_identifier}_dvr/g" $dvr_file > tmp_file |
---|
162 | mv tmp_file $dvr_file |
---|
163 | |
---|
164 | |
---|
165 | # if there is a dvr configuration file, set the BASEDIR to the parent |
---|
166 | # directory of the above given path |
---|
167 | if [[ -f .dvrserver.config ]] |
---|
168 | then |
---|
169 | old_path=`grep BASEDIR .dvrserver.config` |
---|
170 | sed "s&${old_path}&BASEDIR=..&g" .dvrserver.config > .dvrserver.config.new |
---|
171 | mv .dvrserver.config.new .dvrserver.config |
---|
172 | fi |
---|
173 | |
---|
174 | |
---|
175 | # create the html file for the combined streames |
---|
176 | cp 01_*-ge.html tmp.html |
---|
177 | replace=$(echo `grep src= tmp.html`) |
---|
178 | sed "s&${replace}&src=\"${file_identifier}_streaming.dvrs\"&g" tmp.html > ${file_identifier}_streaming.html |
---|
179 | rm tmp.html |
---|
180 | |
---|
181 | |
---|
182 | # informative messages |
---|
183 | printf "\n\n *** processing local dvr stream output:" |
---|
184 | printf "\n number of detected streams = $nstream" |
---|
185 | printf "\n stream names:" |
---|
186 | |
---|
187 | (( i = 0 )) |
---|
188 | while (( i < nstream )) |
---|
189 | do |
---|
190 | |
---|
191 | (( i = i + 1 )) |
---|
192 | printf " ${streamname[$i]}" |
---|
193 | |
---|
194 | done |
---|
195 | printf "\n" |
---|
196 | |
---|
197 | |
---|
198 | # create output for viewing dvr data in sequence mode |
---|
199 | if [[ $create_sequence_output = true ]] |
---|
200 | then |
---|
201 | |
---|
202 | mkdir sequence_data |
---|
203 | |
---|
204 | # first, merge static scenes into one file |
---|
205 | if [[ $camera = true ]] |
---|
206 | then |
---|
207 | cat ${streamname[1]}/camera.dvr >> sequence_data/static_scenes.dvr |
---|
208 | fi |
---|
209 | |
---|
210 | if [[ $groundplate = true ]] |
---|
211 | then |
---|
212 | cat ${streamname[1]}/groundplate.dvr >> sequence_data/static_scenes.dvr |
---|
213 | fi |
---|
214 | |
---|
215 | if [[ $topography = true ]] |
---|
216 | then |
---|
217 | cat ${streamname[1]}/topography.dvr >> sequence_data/static_scenes.dvr |
---|
218 | fi |
---|
219 | |
---|
220 | |
---|
221 | # now, merge the data, frame by frame |
---|
222 | (( j = 0 )) |
---|
223 | while (( j < ${frames[1]} )) |
---|
224 | do |
---|
225 | |
---|
226 | nframe=`printf "%05d" $j` |
---|
227 | |
---|
228 | (( i = 0 )) |
---|
229 | while (( i < nstream )) |
---|
230 | do |
---|
231 | (( i = i + 1 )) |
---|
232 | cat ${streamname[$i]}/$nframe.dvr >> sequence_data/$nframe.dvr |
---|
233 | done |
---|
234 | |
---|
235 | (( j = j + 1 )) |
---|
236 | |
---|
237 | done |
---|
238 | |
---|
239 | |
---|
240 | # create the html file to be used for the sequence mode |
---|
241 | cp ${streamname[1]}.html tmp1.html |
---|
242 | sed "s/camera.dvr/static_scenes.dvr/g" tmp1.html > tmp2.html |
---|
243 | sed "s&${streamname[1]}&sequence_data&g" tmp2.html > ${file_identifier}_sequence.html |
---|
244 | rm tmp1.html tmp2.html |
---|
245 | |
---|
246 | printf " data for using sequence mode generated" |
---|
247 | |
---|
248 | fi |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | # change back to directory from where script has been called |
---|
253 | cd - > /dev/null |
---|