Skip to content

Instantly share code, notes, and snippets.

Last active June 5, 2023 06:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Raspberry Pi Camera + mjpg-streamer systemd setup

This article includes setup instructions for the Raspberry Pi camera, but doesn't capture setting it up as a service (even though a few lines up it sets up OctoPrint as a service), and instead provides a pair of relatively-complex scripts to be run at startup via /etc/rc.local.


  • copy to the mjpg-streamer directory (or wherever you'd like, just update the MJPG_DIR variable)
  • copy pi-webcam.service to /etc/systemd/system/ (requires sudo), ensure ExecStart points to the correct path
  • Register the service with sudo systemctl enable pi-webcam.service
Description=Run Pi Camera as Webcam
MJPG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/mjpg-streamer-experimental"
camera_options="-fps 5"
http_options="-p 5001"
start_cam() {
LD_LIBRARY_PATH="$MJPG_DIR" "${MJPG_DIR}/mjpg_streamer" \
-i " ${camera_options}" \
-o " -w ${MJPG_DIR}/www ${http_options}"
# According to
# this is necessary; it doesn't seem to be but it's harmless
vcgencmd version &> /dev/null
if [[ "$(vcgencmd get_camera)" = 'supported=1 detected=1'* ]]; then
logger " Starting Raspberry Pi camera"
logger " Raspberry Pi camera not found: $(vcgencmd get_camera)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment