-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpi-cam.sh
executable file
·76 lines (65 loc) · 1.79 KB
/
rpi-cam.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
#!/bin/bash
# @package rpi-cam
# @author Zachary Segal <[email protected]>
# @version 1.0
# This script will setup a ram disk and start a "ring recording" type video
# stream. To display the video stream point a html5 video tag at this path:
# /mnt/rpi-cam-ramdisk/stream.m3u8
RAMDISK_TYPE="tmpfs"
# You may override any of the default configurations by setting environment
# variables in the rpi-cam.service file for any of the below variables. You
# will find some are already set in there to the same defaults as an example.
RAMDISK="${RPICAM_RAMDISK_PATH:-/mnt/rpi-cam-ramdisk}"
RAMDISK_SIZE="${RPICAM_RAMDISK_SIZE:-32M}"
VIDEO_WIDTH="${RPICAM_VIDEO_WIDTH:-720}"
VIDEO_HEIGHT="${RPICAM_VIDEO_HEIGHT:-420}"
VIDEO_FPS="${RPICAM_VIDEO_FPS:-30}"
VIDEO_BITRATE="${RPICAM_VIDEO_BITRATE:-1150000}"
LOG_LEVEL="${RPICAM_LOG_LEVEL:=error}"
if [ ! -d "$RAMDISK" ]; then
mkdir -p $RAMDISK
mount -t $RAMDISK_TYPE -o size=$RAMDISK_SIZE $RAMDISK_TYPE $RAMDISK
echo "* Made RAM Disk"
fi
# start a raspivid process, you can install this with aptitude iirc
start() {
raspivid -n \
-w $VIDEO_WIDTH \
-h $VIDEO_HEIGHT \
-fps $VIDEO_FPS \
-ex auto \
-awb auto \
-t 0 \
-b $VIDEO_BITRATE \
-ih -o - \
| ffmpeg -y \
-i - \
-an \
-loglevel $LOG_LEVEL \
-c:v copy \
-map 0:0 \
-f segment \
-segment_time 3 \
-segment_wrap 20 \
-segment_format mpegts \
-segment_list "$RAMDISK/stream.m3u8" \
-segment_list_size $VIDEO_HEIGHT \
-segment_list_flags live \
-segment_list_type m3u8 \
"$RAMDISK/%08d.ts"
}
# removes ram disk contents
# @TODO completely remove the ram disk
cleanup() {
rm $RAMDISK/*.ts
rm $RAMDISK/stream.m3u8
}
# handle command line arguments
case "$1" in
cleanup)
cleanup
;;
*)
start
;;
esac