/
recvid
250 lines (198 loc) · 6.28 KB
/
recvid
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#/usr/bin/bash
# Record a video
# Used for importing a QR-Code parade being displayed on a smartphone
#Steps:
# Done: select an output directory: zenity dialog.
# Done: change to the selected directory: cd command
# Done: select an output file name: zenity dialog
# Done: concatenate directory and filename and set as output for -o or --output
# Done: select an amount of time to record and set as timeout for -t or --timeout
# Done: select the image width and set as width for - w or --width
# Done: select the image height and set as height for -h or --height
# Done: select the frames per second and set as framerate for -fsp or --framerate
# Done: select the bitrate and set as bitrate for -b or --bitrate
# Done: select the preview options x,y,w,h and set as preview for -p or --preview
# Done: Display a record button
# Done: display a stop button: `pkill raspivid`
# Done: convert the .h264 file to .MP4: `MP4Box -add pivideo.h264 pivideo.mp4`
# Done: remove the .264 file
# Done: prompt to play the recorded video: `omxplayer pivideo.mp4`
# Done: prompt to extract text from the video if desired.
# Done: prompt for the name of the converted text file.
# Done: extract the text from the video.
# Done: prompt to display the extracted text if desired.
# Done: display the extracted text.
clear;
# Prompt user for the directory where the output.h264 video file will be written to.
outputDirectory=$(zenity \
--title="Select the location where the outputed .h264 video file will be written" \
--file-selection \
--filename="/home/pi/" \
--directory \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
# Navigate to the selected directory.
cd $outputDirectory;
clear;
# Prompt user to specify the name of the output .h264 video file.
outputFileName=$(zenity \
--entry \
--title="Specify the name of the outputed .h264 video file" \
--entry-text="outputVideo" \
--width 600 \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
clear;
output=$outputDirectory/$outputFileName;
# select a maximum amount of time to record and set as timeout for -t or --timeout
timeout=$(zenity \
--entry \
--title="Specify the maximum amount of time that the video can record" \
--entry-text="30000" \
--width 600 \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
clear;
# select the image width and set as width for - w or --width
width=$(zenity \
--entry \
--title="Specify the width of the recorded video" \
--entry-text="640" \
--width 600 \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
clear;
# select the image height and set as height for -h or --height
height=$(zenity \
--entry \
--title="Specify the height of the recorded video" \
--entry-text="480" \
--width 600 \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
clear;
# select the frames per second and set as framerate for -fsp or --framerate
framerate=$(zenity \
--entry \
--title="Specify the framerate" \
--entry-text="10" \
--width 600 \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
clear;
# select the bitrate and set as bitrate for -b or --bitrate
bitrate=$(zenity \
--entry \
--title="Specify the bitrate" \
--entry-text="1200000" \
--width 600 \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
clear;
# select the preview options x,y,w,h and set as preview for -p or --preview
preview=$(zenity \
--entry \
--title="Specify the position and size of the preview window x,y,w,h" \
--entry-text="100,100,240,200" \
--width 600 \
2>/dev/null);
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
clear;
# display a record button
zenity \
--question \
--title "Record Video" \
--text "Would you like to start recording?" \
--ok-label "Start Recording" \
--cancel-label "No, Skip" \
2>/dev/null ;
# If the user presses the record button.
if [ $? == 0 ];
then \
# raspivid -t 30000 -w 640 -h 480 -fps 25 -b 1200000 -p 0,0,640,480 -o pivideo.h264;
raspivid \
--rotation 270 \
-t $timeout \
-w $width \
-h $height \
-fps $framerate \
-b $bitrate \
-p $preview \
-o $output.h264 \
2>/dev/null &
elif [ $? == 1 ];
then \
exit
fi
clear;
# display a stop button: `killall raspivid`
zenity \
--error \
--title "Stop Recording" \
--text='Stop Recording' \
--ok-label "Stop Recording" \
2>/dev/null;
if [ $? == 0 ]; then killall raspivid 2>/dev/null; fi
clear
# Convert the .h264 file to .MP4
MP4Box -add $output.h264 $output.MP4 2>/dev/null ;
# Remove the .h264 file
sudo rm $output.h264 2>/dev/null ;
# Play back the video if user wants
zenity \
--question \
--title "Play Video" \
--text "Would you like to play back the recording?" \
--ok-label "Play Video" \
--cancel-label "No, Skip" \
2>/dev/null ;
# If the user selects Play Video then play it.
if [ $? == 0 ]; then omxplayer $output.MP4; fi
clear;
# prompt to extract text from the video if desired.
zenity \
--question \
--title "Extract Text From the Video?" \
--text "Would you like to extract text from the video?" \
--ok-label "Extract the Text" \
--cancel-label "No, Skip" \
2>/dev/null ;
# If the user cancels the prompt action then exit this script.
if [ $? == 1 ]; then exit; fi
# If the user selects the Extract the Text button then prompt user for the name of the converted text file.
if [ $? == 0 ];
then \
extractedFileName=$(zenity \
--entry \
--title="Specify the name of the text file where extracted text will go" \
--entry-text="extractedTextFile" \
--width 600 \
2>/dev/null);
fi
clear;
# extract the text from the video.
python /usr/local/bin/QRCodeVideoToTextFile.py $output.MP4 $extractedFileName.txt;
clear;
# prompt to display the extracted text if desired.
zenity \
--question \
--title "View the text extracted from the video?" \
--text "Would you like to view the text extracted from the video?" \
--ok-label "View Extracted Text" \
--cancel-label "No, Skip" \
2>/dev/null ;
# If the user selects the View Extracted Text button.
# display the extracted text.
if [ $? == 0 ];
then \
leafpad $extractedFileName.txt;
fi
clear;