Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pub
cams
Commits
9eb39a3a
Commit
9eb39a3a
authored
Jan 02, 2018
by
Neil Gershenfeld
Browse files
switch to ffmpeg
parent
25cde88e
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
9eb39a3a
...
...
@@ -4,7 +4,7 @@ to reinitialize: ./init
to run: node cams.js
uses f
swebcam
for screen capture
uses f
fmpeg
for screen capture
uses convert to make thumbnails
...
...
@@ -12,8 +12,6 @@ uses compare to measure activity
can use uvcdynctrl -f to list resolutions
can use fswebcam --list-controls to list controls
can use sudo guvcview to adjust camera
can use http-server-with-auth to serve:
...
...
@@ -23,7 +21,7 @@ index is at http://this_address:this_port
last image is at http://this_address:this_port/oldimage.jpg
can use Ubuntu MATE on Raspberry Pi 3:
sudo apt-get install nodejs-legacy npm f
swebcam
imagemagick guvcview
sudo apt-get install nodejs-legacy npm f
fmpeg
imagemagick guvcview
sudo npm install -g http-server-with-auth
System -> Administration -> Time and Date -> Keep synchronized with internet servers
...
...
cams.js
View file @
9eb39a3a
...
...
@@ -9,24 +9,10 @@
var
image_width
=
1600
var
image_height
=
1200
var
thumbnail_size
=
200
var
compression
=
50
var
video_filter
=
'
vflip,hflip
'
var
difference_threshold
=
.
05
var
millisecond_image_delay
=
15000
var
days_to_save
=
150
var
flip
=
"
--flip h,v
"
var
settings
=
'
\
--set "Focus, Auto"=False
\
--set "Focus (absolute)"=0%
\
--set "White Balance Temperature, Auto"=False
\
--set "White Balance Temperature"=50%
\
--set "Exposure, Auto"="Manual Mode"
\
--set "Exposure, Auto Priority"=False
\
--set "Exposure (Absolute)"=15%
\
--set Brightness=50%
\
--set Contrast=50%
\
--set Saturation=50%
\
--set Gain=0%
\
--set Sharpness=100%
'
//
// requires
//
...
...
@@ -52,14 +38,16 @@ function update() {
// take new image
//
console
.
log
(
'
\n
capture
'
+
name
)
while
(
true
)
{
execSync
(
'
fswebcam --jpeg
'
+
compression
+
'
--resolution
'
+
image_width
+
'
x
'
+
image_height
+
'
'
+
flip
+
'
--save image.jpg
'
)
//
// check that taking image was successful
//
if
(
fs
.
existsSync
(
'
image.jpg
'
))
break
var
success
=
true
do
{
try
{
execSync
(
'
ffmpeg -y -f v4l2 -s
'
+
image_width
+
'
x
'
+
image_height
+
'
-i /dev/video0 -vframes 1 -vf
'
+
video_filter
+
'
image.jpg
'
)
}
catch
(
err
)
{
success
=
false
}
}
while
(
success
!=
true
)
//
// remove prior images
//
...
...
@@ -123,7 +111,16 @@ function update() {
//
// take initial image
//
execSync
(
'
fswebcam --jpeg
'
+
compression
+
'
--resolution
'
+
image_width
+
'
x
'
+
image_height
+
'
'
+
flip
+
'
'
+
settings
+
'
--save oldimage.jpg
'
)
var
success
=
true
do
{
try
{
execSync
(
'
ffmpeg -y -f v4l2 -s
'
+
image_width
+
'
x
'
+
image_height
+
'
-i /dev/video0 -vframes 1 -vf
'
+
video_filter
+
'
oldimage.jpg
'
)
}
catch
(
err
)
{
success
=
false
}
}
while
(
success
!=
true
)
//
// start update
//
...
...
cams1.js
deleted
100644 → 0
View file @
25cde88e
//
// cams.js
// shopcam activity monitor
// Neil Gershenfeld
// 12/11/17
//
// settings
//
var
image_width
=
1600
var
image_height
=
1200
var
thumbnail_size
=
200
var
video_filter
=
'
vflip,hflip
'
var
difference_threshold
=
.
05
var
millisecond_image_delay
=
15000
var
days_to_save
=
150
//
// requires
//
const
fs
=
require
(
'
fs
'
)
const
exec
=
require
(
'
child_process
'
).
exec
const
execSync
=
require
(
'
child_process
'
).
execSync
//
// image update function
//
function
update
()
{
//
// name image with time
//
var
date
=
new
Date
()
var
year
=
date
.
getFullYear
()
var
month
=
(
'
0
'
+
(
1
+
parseInt
(
date
.
getMonth
()))).
slice
(
-
2
)
var
day
=
(
'
0
'
+
date
.
getDate
()).
slice
(
-
2
)
var
hour
=
(
'
0
'
+
date
.
getHours
()).
slice
(
-
2
)
var
minute
=
(
'
0
'
+
date
.
getMinutes
()).
slice
(
-
2
)
var
second
=
(
'
0
'
+
date
.
getSeconds
()).
slice
(
-
2
)
var
name
=
year
+
'
-
'
+
month
+
'
-
'
+
day
+
'
-
'
+
hour
+
'
-
'
+
minute
+
'
-
'
+
second
+
'
.jpg
'
//
// take new image
//
console
.
log
(
'
\n
capture
'
+
name
)
var
success
=
true
do
{
try
{
execSync
(
'
ffmpeg -y -f v4l2 -s
'
+
image_width
+
'
x
'
+
image_height
+
'
-i /dev/video0 -vframes 1 -vf
'
+
video_filter
+
'
image.jpg
'
)
}
catch
(
err
)
{
success
=
false
}
}
while
(
success
!=
true
)
//
// remove prior images
//
date
.
setDate
(
date
.
getDate
()
-
days_to_save
)
var
oldyear
=
date
.
getFullYear
()
var
oldmonth
=
(
'
0
'
+
(
1
+
parseInt
(
date
.
getMonth
()))).
slice
(
-
2
)
var
oldday
=
(
'
0
'
+
date
.
getDate
()).
slice
(
-
2
)
var
oldhour
=
(
'
0
'
+
date
.
getHours
()).
slice
(
-
2
)
var
oldminute
=
(
'
0
'
+
date
.
getMinutes
()).
slice
(
-
2
)
var
prefix
=
oldyear
+
'
-
'
+
oldmonth
+
'
-
'
+
oldday
+
'
-
'
+
oldhour
+
'
-
'
+
oldminute
+
'
*
'
console
.
log
(
'
remove
'
+
prefix
)
execSync
(
'
rm -f images/
'
+
prefix
+
'
*
'
)
execSync
(
'
rm -f thumbnails/
'
+
prefix
+
'
*
'
)
//
// check if image has changed beyond threshold
//
try
{
execSync
(
'
compare -metric RMSE image.jpg oldimage.jpg null: 2>&1
'
)
}
catch
(
err
)
{
var
ret
=
String
(
err
.
stdout
).
split
(
'
'
)
var
ptrl
=
ret
[
1
].
indexOf
(
'
(
'
)
var
ptrr
=
ret
[
1
].
indexOf
(
'
)
'
)
var
diff
=
parseFloat
(
ret
[
1
].
slice
(
ptrl
+
1
,
ptrr
))
console
.
log
(
'
image difference:
'
+
diff
)
}
if
(
diff
>
difference_threshold
)
{
//
// size has changed, keep image
//
console
.
log
(
'
activity detected, save image
'
)
execSync
(
'
convert image.jpg -resize
'
+
thumbnail_size
+
'
x
'
+
thumbnail_size
+
'
thumbnails/
'
+
name
)
execSync
(
'
cp image.jpg images/
'
+
name
)
//
// rebuild day's index
//
console
.
log
(
'
reindex day
'
)
execSync
(
"
echo '<html><body>' > index/newindex.html
"
)
execSync
(
"
echo '<script src=../display.js></script>' > index/newindex.html
"
)
execSync
(
'
ls images | awk
\'
/^
'
+
year
+
'
-
'
+
month
+
'
-
'
+
day
+
'
/ { print "<img src=
\\
"../thumbnails/" $1 "
\\
" id=
\\
"" $1 "
\\
" style=
\\
"width:20%;height:auto;cursor:pointer;
\\
" onmousedown=display(
\\
"" $1 "
\\
")>" }
\'
>> index/newindex.html
'
)
execSync
(
"
mv index/newindex.html index/
"
+
month
+
"
-
"
+
day
+
"
.html
"
)
//
// delay before next image
//
console
.
log
(
'
delay before next image
'
)
execSync
(
'
mv image.jpg oldimage.jpg
'
)
setTimeout
(
update
,
millisecond_image_delay
)
}
else
{
//
// size hasn't changed
//
console
.
log
(
'
no activity detected, don
\'
t save image
'
)
//
// no delay before next image
//
execSync
(
'
mv image.jpg oldimage.jpg
'
)
setTimeout
(
update
,
0
)
}
}
//
// take initial image
//
var
success
=
true
do
{
try
{
execSync
(
'
ffmpeg -y -f v4l2 -s
'
+
image_width
+
'
x
'
+
image_height
+
'
-i /dev/video0 -vframes 1 -vf
'
+
video_filter
+
'
oldimage.jpg
'
)
}
catch
(
err
)
{
success
=
false
}
}
while
(
success
!=
true
)
//
// start update
//
update
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment