Skip to content

Commit d2334b9

Browse files
committed
added the gsnap.sh script
1 parent fc10073 commit d2334b9

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

gsnap.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/sh
2+
# gsnap.sh
3+
#
4+
# (c)2019 The Green Island Companies LLC
5+
# This Source Code Form is subject to the terms of the Mozilla Public
6+
# License, v. 2.0. If a copy of the MPL was not distributed with this
7+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
#
9+
# Designed for use on the Raspberry Pi. Find out more at
10+
# http://raspberrypimaker.com
11+
#
12+
# Developed by
13+
# Green Island Companies - http://greenislandcompanies.com
14+
#
15+
# Default values set here
16+
name=''
17+
netcam="1"
18+
skip="1"
19+
delay="3"
20+
while [ "$#" -gt 0 ]; do
21+
case "$1" in
22+
-n) name="$2"; shift 2;;
23+
-c) camera="$2"; shift 2;;
24+
-r) resolution="$2"; shift 2;;
25+
-s) skip="$2"; shift 2;;
26+
-d) delay="$2"; shift 2;;
27+
-R) rotate="$2"; shift 2;;
28+
-w) webcam="1"; netcam=""; shift 1;;
29+
-rc) raspicam="1"; webcam=""; netcam=""; shift 1;;
30+
-db) dropbox="1"; shift 1;;
31+
-DB) dropbox="1"; fdelete="1"; shift 1;;
32+
33+
--name=*) name="${1#*=}"; shift 1;;
34+
--camera=*) camera="${1#*=}"; shift 1;;
35+
--resolution=*) resolution="${1#*=}"; shift 1;;
36+
--rotate=*) rotate="${1#*=}"; shift 1;;
37+
--skip=*) skip="${1#*=}"; shift 1;;
38+
--delay=*) delay="${1#*=}"; shift 1;;
39+
--webcam) raspicam=""; webcam="1"; netcam=""; shift 1;;
40+
--raspicam) raspicam="1"; webcam=""; netcam=""; shift 1;;
41+
--dropbox=*) dropbox="1"; dropboxdir="${1#*=}/"; shift 1;;
42+
--DROPBOX=*) dropbox="1"; dropboxdir="${1#*=}/"; fdelete="1"; shift 1;;
43+
--name|--camera|--resolution|--skip|--delay|--rotate|--dropbox|--DROPBOX) echo "$1 requires an argument. type snap.sh --help for help" >&2; exit 1;;
44+
45+
--help) echo "gsnap.sh - take a since date coded image"; echo ;
46+
echo " -c, --camera - set the rtsp:// camera url or webcam path (required for rtsp and webcam)";
47+
echo " -w, --webcam - Capture from a web cam";
48+
echo " -rc, --raspicam - Capture from a raspicam cam";
49+
echo " -n, --name - set the filename prefix. If omitted just the datecode will be used";
50+
echo " -r, --resolution - sets the captured resolution (webcam and raspi cam only)";
51+
echo " -s, --skip - Skip n frames allowing the camera time to power on (webcam only)";
52+
echo " -d, --delay - delay n seconds before capture. Allows camera to set up auto white balance";
53+
echo " -R, --rotate - Rotate the image n degrees (webcam & raspicam only)";
54+
echo " -db - Copy jpg to DropBox default app directory";
55+
echo " -DB - Copy jpg to DropBox default app directory and then delete local copy";
56+
echo " --dropbox=dir - Copy jpg to DropBox 'dir' under app directory";
57+
echo " --DROPBOX=dir - Copy jpg to DropBox 'dir' under app directory and delete local copy";
58+
echo " --help - this help info"; exit 1;;
59+
60+
-*) echo "unknown option: $1" >&2; exit 1;;
61+
*) args="${args}$1 "; shift 1;;
62+
esac
63+
done
64+
65+
if [ -z "$raspicam" ]
66+
then
67+
if [ -z "$camera" ]; then echo 'ERROR - Camera loctation must be set'; exit 1; fi
68+
fi
69+
70+
if [ ! -z "$netcam" ]
71+
then
72+
if [ ! -z "$delay" ]; then delay="-ss $delay"; fi
73+
fi
74+
75+
if [ ! -z "$webcam" ]
76+
then
77+
if [ ! -z "$resolution" ]; then resolution="-r $resolution"; fi
78+
if [ ! -z "$rotate" ]; then rotate="--rotate $rotate"; fi
79+
if [ ! -z "$skip" ]; then skip="-S $skip"; fi
80+
if [ ! -z "$delay" ]; then delay="-D $delay"; fi
81+
fi
82+
83+
if [ ! -z "$raspicam" ]
84+
then
85+
if [ ! -z "$resolution" ]; then resolution="-w ${resolution%x*} -h ${resolution#*x}"; fi
86+
if [ ! -z "$rotate" ]; then rotate="-rot $rotate"; fi
87+
fi
88+
89+
DT=`date +%Y%m%d%H%M%S`
90+
if [ ! -z "$netcam" ]; then nice ffmpeg -rtsp_transport tcp -i $camera $delay -vframes 1 ./$name$DT.jpg; fi
91+
if [ ! -z "$webcam" ]; then fswebcam -d $camera $resolution $skip $delay $rotate -q ./$name$DT.jpg; fi
92+
if [ ! -z "$raspicam" ]; then raspistill $resolution $rotate -o ./$name$DT.jpg; fi
93+
94+
if [ ! -z "$dropbox" ]; then ./dropbox_uploader.sh upload ./$name$DT.jpg $dropboxdir$name$DT.jpg; fi
95+
if [ ! -z "$fdelete" ]; then rm ./$name$DT.jpg; fi
96+
97+
# fswebcam options
98+
# -d, --device
99+
# -r, --resolution
100+
# -F, --frames
101+
# -S, --skip
102+
# -D, --delay
103+
# --jpeg <factor>
104+
# --rotate <angle>
105+
# -q, --quiet

0 commit comments

Comments
 (0)