-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera
executable file
·87 lines (78 loc) · 2.76 KB
/
camera
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
#!/usr/bin/env bash
# Camera startup script
# Note: front camera is port 8 and back camera is port 11
# Networking
IPH="192.168.88.2" # Topsides ip address
IPF="192.168.88.4" # Front camera ip address
IPB="192.168.88.5" # Back camera ip address
PORTF="5002" # Front camera port
PORTB="5003" # Back camera port
PORTO="5004" # OpenCV camera port
# Defaults
FPS="30" # Open with lower fps for stability
HEIGHT="720" # Use 720p video
WIDTH="1280"
ORIENTATIONB="" # Back camera orientation
ORIENTATIONF="-vf -hf" # Front camera orientation
# Handle command line arguments
for i in "$@"
do
case $i in
# Run for image recognition
-cv*|--opencv*)
FPS="10"
HEIGHT="480"
WIDTH="640"
shift
;;
# Change video fps
-f=*|--fps=*)
FPS="${i#*=}"
shift
;;
# Change video height
-h=*|--height=*)
HEIGHT="${i#*=}"
shift
;;
# Change video width
-w=*|--width=*)
WIDTH="${i#*=}"
shift
;;
# Flip back camera orientation
-bo*|--backorientation*)
ORIENTATIONB="-vf -hf"
shift
;;
# Flip front camera orientation
-fo*|--frontorientation*)
ORIENTATIONF=""
shift
;;
*)
# Unknown option
;;
esac
done
# Open topsides camera capture if it is not already running
if ps ax | grep -v grep | grep "gst-launch-1.0 udpsrc port=${PORTF} ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink" > /dev/null
then
echo "Topsides capture is already running."
else
setsid xterm -geometry 93x31+0+0 -e gst-launch-1.0 udpsrc port=${PORTF} ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink &
fi
if ps ax | grep -v grep | grep "gst-launch-1.0 udpsrc port=${PORTB} ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink" > /dev/null
then
echo "Topsides capture is already running."
else
setsid xterm -geometry 93x31+0+0 -e gst-launch-1.0 udpsrc port=${PORTB} ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink &
fi
# Start back camera
sshpass -p raspberry ssh pi@${IPB} raspivid -t 0 ${ORIENTATIONB} -n -h ${HEIGHT} -w ${WIDTH} -fps ${FPS} -b 3000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse config-interval=1 ! rtph264pay ! udpsink host=${IPH} port=${PORTB} &
# Start front camera with split streams
sshpass -p raspberry ssh pi@${IPF} raspivid -t 0 ${ORIENTATIONF} -n -h ${HEIGHT} -w ${WIDTH} -fps ${FPS} -b 3000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse config-interval=1 ! rtph264pay ! tee name=t \
t. ! queue ! udpsink host=${IPH} port=${PORTF} \
t. ! queue ! udpsink host=${IPH} port=${PORTO} &
# Keep running till closed
read -n1 -r -p "Press any key to close..." key