Created
February 7, 2015 12:56
-
-
Save aleksihakli/f8a8e84875b7e285ef6e to your computer and use it in GitHub Desktop.
Naive script for streaming camera output from Raspbian as MJPEG; change user and app name to fit your needs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: kahvisio | |
# Required-Start: $network $local_fs $syslog | |
# Required-Stop: $network $local_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start kahvisio at boot time. | |
# Description: Enable kahvisio as a service. | |
### END INIT INFO | |
USER="pi" | |
APP="kahvisio" | |
LOGFOLDER="/var/log/$APP" | |
HTTP_PORT="8080" | |
WIDTH="1280" | |
HEIGHT="720" | |
# Make sure the video module for v4l2 is available | |
# modprobe bcm2835-v4l2 | |
# Start or stop video streamer | |
case "$1" in | |
start) | |
echo "Creating log folders and chowning them to $USER:$USER at $LOGFOLDER" | |
mkdir -p $LOGFOLDER | |
chown -R $USER:$USER $LOGFOLDER | |
echo "Starting $APP cvlc MPJPEG stream on http://:$HTTP_PORT/" | |
su - $USER -c "cvlc v4l2:///dev/video0 --v4l2-width $WIDTH --v4l2-height $HEIGHT --v4l2-chroma mjpg --sout '#standard{access=http,mux=mpjpeg,dst=:8080}' > $LOGFOLDER/kahvisio.log 2> $LOGFOLDER/error.log &" | |
;; | |
stop) | |
echo "Stopping $APP cvlc camera stream" | |
kill `pgrep vlc` | |
;; | |
*) | |
echo "Usage: /etc/init.d/$APP {start|stop}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an init.d script and can be enabled for a Raspbian by copying it to
/etc/init.d/$APP
and runningsudo update-rc.d $APP defaults
. After this starting and stopping go withsudo service $APP start|stop
and the script can be disabled withsudo update-rc.d $APP disable
.