forked from davecrump/hdmisource
-
Notifications
You must be signed in to change notification settings - Fork 1
/
camera.sh
executable file
·318 lines (253 loc) · 7.9 KB
/
camera.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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/bin/bash
# This script uses vlc to display the video from the C920.
# set -x
############ Function to Read value with - from Config File ###############
get-config_var() {
lua - "$1" "$2" <<EOF
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
for line in file:lines() do
local val = line:match("^#?%s*"..key.."=[+-]?(.*)$")
if (val ~= nil) then
print(val)
break
end
end
EOF
}
# Put a black background up
sudo fbi -T 1 -noverbose -a /home/pi/hdmisource/images/1080_Black.jpg >/dev/null 2>/dev/null
CONFIGFILE=/boot/hdmisource_config.txt
CAMERA=$(get-config_var camera $CONFIGFILE)
DEBUG=no # set to yes for diagnostics
if [ "$DEBUG" != "yes" ]; then
clear
fi
if [ "$CAMERA" == "auto" ]; then
CAMERA=$1
if [ ${#CAMERA} -lt 2 ]; then
CAMERA=auto
fi
fi
############ IDENTIFY USB VIDEO DEVICES #############################
WEBCAM_TYPE="None"
ECCONTRAST=" "
############ Auto Camera selection #########################
lsusb | grep -q "046d:082d"
if [ $? == 0 ] && [ "$CAMERA" == "auto" ]; then
WEBCAM_TYPE="OldC920"
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:0892"
if [ $? == 0 ]; then
WEBCAM_TYPE="OrbicamC920"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:08e5"
if [ $? == 0 ]; then
WEBCAM_TYPE="NewerC920"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:0843"
if [ $? == 0 ]; then
WEBCAM_TYPE="C930e"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:082b"
if [ $? == 0 ]; then
WEBCAM_TYPE="C170"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:0825"
if [ $? == 0 ]; then
WEBCAM_TYPE="C270"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:0821"
if [ $? == 0 ]; then
WEBCAM_TYPE="C910"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:0823"
if [ $? == 0 ]; then
WEBCAM_TYPE="B910"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:0826"
if [ $? == 0 ]; then
WEBCAM_TYPE="C525"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ]; then
lsusb | grep -q "046d:0823"
if [ $? == 0 ]; then
WEBCAM_TYPE="C310"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "auto" ]; then
lsusb | grep -q "095d:3001"
if [ $? == 0 ]; then
WEBCAM_TYPE="EagleEye"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "auto" ]; then
lsusb | grep -q "1b71:3002"
if [ $? == 0 ]; then
WEBCAM_TYPE="USBTV007"
ECCONTRAST="contrast=380"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "auto" ]; then
lsusb | grep -q "534d:0021"
if [ $? == 0 ]; then
WEBCAM_TYPE="MS210x"
ECCONTRAST="contrast=105"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "auto" ]; then
lsusb | grep -q "Webcam"
if [ $? == 0 ]; then
WEBCAM_TYPE="Webcam"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "auto" ]; then
libcamera-hello --list-cameras | grep -q "No cameras available"
if [ $? != 0 ] && [ "$CAMERA" == "auto" ]; then
WEBCAM_TYPE="PiCam"
fi
fi
################### Manual Camera Selection #######################
EAGLEEYES=0
lsusb | grep -q "046d:082d"
if [ $? == 0 ] && [ "$CAMERA" == "c920" ]; then
WEBCAM_TYPE="OldC920"
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "eagleeye" ]; then
lsusb | grep -q "095d:3001"
if [ $? == 0 ]; then
WEBCAM_TYPE="EagleEye"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "eagleeye2" ]; then
lsusb | grep -q "095d:3001"
if [ $? == 0 ]; then
EAGLEEYES="$(lsusb | grep -c "095d:3001")"
if [ $EAGLEEYES == 2 ]; then
WEBCAM_TYPE="EagleEye2"
fi
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "easycap" ]; then
lsusb | grep -q "1b71:3002"
if [ $? == 0 ]; then
WEBCAM_TYPE="USBTV007"
ECCONTRAST="contrast=380"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "easycap" ]; then
lsusb | grep -q "534d:0021"
if [ $? == 0 ]; then
WEBCAM_TYPE="MS210x"
ECCONTRAST="contrast=105"
fi
fi
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "picam" ]; then
libcamera-hello --list-cameras | grep -q "No cameras available"
if [ $? != 0 ] && [ "$CAMERA" == "picam" ]; then
WEBCAM_TYPE="PiCam"
fi
fi
########### Report Camera ##############################################
if [ "$DEBUG" == "yes" ]; then
if [ "$WEBCAM_TYPE" == "None" ]; then
printf "No Webcam identified\n"
else
printf "Found Webcam of type $WEBCAM_TYPE\n"
fi
fi
############## Look up USB Parameters ################################
# List the video devices, select the 2 lines for the USB device, then
# select the line with the device details and delete the leading tab
if [ "$WEBCAM_TYPE" == "OldC920" ]; then
VID_USB="$(v4l2-ctl --list-devices 2> /dev/null | \
sed -n '/C920/,/dev/p' | grep 'dev' | tr -d '\t')"
fi
if [ "$VID_USB" == '' ]; then
VID_USB="$(v4l2-ctl --list-devices 2> /dev/null | \
sed -n '/C930e/,/dev/p' | grep 'dev' | tr -d '\t')"
fi
if [ "$WEBCAM_TYPE" == "USBTV007" ]; then
if [ "$VID_USB" == '' ]; then
VID_USB="$(v4l2-ctl --list-devices 2> /dev/null | \
sed -n '/usbtv/,/dev/p' | grep 'dev' | tr -d '\t')"
fi
fi
if [ "$WEBCAM_TYPE" == "MS210x" ]; then
if [ "$VID_USB" == '' ]; then
VID_USB="$(v4l2-ctl --list-devices 2> /dev/null | \
sed -n '/AV TO USB2.0/,/dev/p' | grep 'dev' | tr -d '\t')"
fi
fi
if [ "$WEBCAM_TYPE" == "EagleEye" ]; then
if [ "$VID_USB" == '' ]; then
VID_USB="$(v4l2-ctl --list-devices 2> /dev/null | \
sed -n '/EagleEye/,/dev/p' | grep 'dev' | tr -d '\t' \
| head -n 1)"
fi
fi
if [ "$WEBCAM_TYPE" == "EagleEye2" ]; then
if [ "$VID_USB" == '' ]; then
VID_USB="$(v4l2-ctl --list-devices 2> /dev/null | \
sed -n '/EagleEye/,/dev/p' | grep 'dev' | tr -d '\t' \
| tail -n 1)"
fi
fi
if [ "$VID_USB" == '' ]; then
VID_USB="/dev/video0"
if [ "$DEBUG" == "yes" ]; then
printf "VID_USB was not found, setting to /dev/video0\n"
fi
fi
if [ "$DEBUG" == "yes" ]; then
printf "The USB device string is $VID_USB\n"
fi
###########################################################################
sudo killall vlc >/dev/null 2>/dev/null
sudo killall libcamera-hello >/dev/null 2>/dev/null
sudo killall fbi >/dev/null 2>/dev/null
if [ "$WEBCAM_TYPE" == "OldC920" ]; then
cvlc -I rc --rc-host 127.0.0.1:1111 -f --mmal-display hdmi-1 --no-video-title-show \
v4l2:///"$VID_USB":width=1920:height=1280:chroma=H264 >/dev/null 2>/dev/null
fi
if [ "$WEBCAM_TYPE" == "EagleEye" ] || [ "$WEBCAM_TYPE" == "EagleEye2" ]; then
cvlc -I rc --rc-host 127.0.0.1:1111 -f --mmal-display hdmi-1 --no-video-title-show \
v4l2:///"$VID_USB":width=1920:height=1080:chroma=MJPG:fps=25 >/dev/null 2>/dev/null
fi
if [ "$WEBCAM_TYPE" == "USBTV007" ]; then
# Set the EasyCap to PAL
v4l2-ctl -d $VID_USB --set-standard=6
# Reduce the contrast to prevent crushed whites
(sleep 0.7; v4l2-ctl -d $VID_USB --set-ctrl $ECCONTRAST >/dev/null 2>/dev/null) &
cvlc -I rc --rc-host 127.0.0.1:1111 -f --mmal-display hdmi-1 \
--no-video-title-show --aspect-ratio=16:9 \
v4l2:///"$VID_USB":width=720:height=576:chroma=I420:fps=25 >/dev/null 2>/dev/null
fi
if [ "$WEBCAM_TYPE" == "MS210X" ]; then
# Reduce the contrast to prevent crushed whites
(sleep 0.7; v4l2-ctl -d $VID_USB --set-ctrl $ECCONTRAST >/dev/null 2>/dev/null) &
cvlc -I rc --rc-host 127.0.0.1:1111 -f --mmal-display hdmi-1 \
--no-video-title-show --aspect-ratio=16:9 \
v4l2:///"$VID_USB":width=720:height=576:chroma=I420:fps=25 >/dev/null 2>/dev/null
fi
if [ "$WEBCAM_TYPE" == "PiCam" ]; then
libcamera-hello --viewfinder-mode 16:1920:1080:P \
--viewfinder-width 1920 --viewfinder-height 1080 -t 0 >/dev/null 2>/dev/null
fi