Skip to content

Instantly share code, notes, and snippets.

@jhenkens
Last active December 13, 2018 15:26
Show Gist options
  • Save jhenkens/11074705 to your computer and use it in GitHub Desktop.
Save jhenkens/11074705 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
DATE=$(date +"%Y-%m-%d_%H%M")
FILEDIR=$1
FILE=$DATE.jpg
if [[ "$FILEDIR" != "" ]]; then
FILE="$FILEDIR"/"$FILE"
fi
shift;
NOT_DONE=true
TRY=0
while [[ "$NOT_DONE" == "true" ]]; do
RESULT=$(fswebcam -q -r 1920x1080 --no-banner "$@" "$FILE" 2>&1 | grep -q 'JPEG library reports unrecoverable error')
if [[ "$RESULT" == "0" ]]; then
rm "$FILEDIR/$DATE.jpg"
TRY=$((TRY+1))
if [[ $TRY > 5 ]]; then
echo "Failed 5 times, exiting with error"
NOT_DONE=false
exit 1
else
echo "Failed, going to try again."
fi
else
NOT_DONE=false
fi
done
device /dev/video0
resolution 1280x720
no-banner
jpeg 90
loop 10
background
save /tmp/last.jpg
delay 2
skip 30
#! /bin/bash
mkdir -p $HOME/transfer
mv $HOME/timelapses/*.jpg $HOME/transfer
I spent some time messing around getting Time Lapse and HTTP Live streaming
working on my Raspberry Pi
I'm using a raspberry pi, Logitech C920 webcam and some powered 4 port hub from amazon
Had a lot of problems with firmware (Make sure you update to the, as of April
18th 2014, beta firmware and set the USB concurrency flags to 0x7 (or something
like that).)
I also had problems with shitty USB cables, but now its pretty stable.
#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H.%M.%S")
FILEDIR=/home/pi/timelapses
FILE=$DATE.jpg
if [[ "$FILEDIR" != "" ]]; then
FILE="$FILEDIR"/"$FILE"
fi
TMPFILE=/tmp/last.jpg
if [[ -f "$TMPFILE" ]]; then
mv "$TMPFILE" "$FILE"
fi
#! /bin/bash
FPS=30
WIDTH=1920
HEIGHT=1080
PORT=8080
DEVICE=/dev/video0
v4l2-ctl --device=$DEVICE --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=1
v4l2-ctl --set-parm=$FPS
cvlc v4l2://$DEVICE:chroma=h264:width=$WIDTH:height=$HEIGHT:fps=$FPS --sout '#standard{access=http,mux=ts,dst=0.0.0.0:$PORT,name=stream,mime=video/ts}' -vv
#! /bin/bash
FPS=30
WIDTH=1280
HEIGHT=720
PORT=8080
DEVICE=/dev/video0
v4l2-ctl --device=$DEVICE --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=1
v4l2-ctl --set-parm=$FPS
cvlc v4l2://$DEVICE:chroma=h264:width=$WIDTH:height=$HEIGHT:fps=$FPS --sout '#standard{access=http,mux=ts,dst=0.0.0.0:$PORT,name=stream,mime=video/ts}' -vv
#! /bin/bash
FPS=30
WIDTH=1280
HEIGHT=720
PORT=8080
DEVICE=/dev/video0
v4l2-ctl --device=$DEVICE --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=1
v4l2-ctl --set-parm=$FPS
SEGLEN=5
NUMSEGS=5
URL=<YOURURLHERE>8080/stream
FILELOC=/usr/share/nginx/www/stream
EXTRAPARAMS="--live-caching 100"
cvlc v4l2://$DEVICE:chroma=h264:width=$WIDTH:height=$HEIGHT:fps=$FPS --sout "#std{access=livehttp{seglen=$SEGLEN,delsegs=true,numsegs=$NUMSEGS, index=$FILELOC/stream.m3u8, index-url=$URL/stream-########.ts}, mux=ts{use-key-frames}, dst=$FILELOC/stream-########.ts}" -vv
#! /bin/bash
set -x
HOURS=$1; if [[ "$HOURS" == "" ]]; then HOURS=1; fi; HOURS=$((HOURS*3600))
screen -dm -t timelapse bash -c "fswebcam -c fswebbin/fswebcam.conf --exec fswebbin/renamer; sleep $HOURS; killall fswebcam"
@peter-kraker
Copy link

"""
Had a lot of problems with firmware (Make sure you update to the, as of April
18th 2014, beta firmware and set the USB concurrency flags to 0x7 (or something
like that).)
"""

What firmware are you talking about? The camera? the Raspberry Pi? Also, how do you set the USB concurrency flags?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment