Coder Social home page Coder Social logo

wattihrvolt / rpimjpeg Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 19 KB

streaming mjpeg from the raspberry pi's camera

License: Apache License 2.0

Java 100.00%
java mjpeg-stream raspberrypi raspberry-pi mjpeg video-streaming camera-control raspberry-pi-camera streaming-mjpeg server

rpimjpeg's Introduction

rpimjpeg - Motion Jpeg Streamer for the RaspberryPi Cam

... a simple solution for streaming mjpeg from the raspberry pi's camera.

Features

  • no additional server software required
  • supports up to 5 clients in parallel (configurable)
  • command line interface for inital settings (width, heigth...)

What you need

to run

  • a Rapsberry Pi (testet with B+ and Zero W)
  • a Raspberry Pi Camera Model
  • raspistill/raspivid installed (comes with raspbian, if pi's cam enabled)

to build

  • java 8 jdk (oracle) installed, com.sun.net.httpserver packages will be used.
  • maven

to view

  • a Browser
  • or vlc (for example)

Build and RUN

After running git clone and mvn clean compile assembly:single (in the root directory of the project) there is a executable jar at /target/rpi.mjpeg.streamer-0.0.1-SNAPSHOT-jar-with-dependencies.jar.

start the server

with default values: (resolution: 640x480, port: 8080)

java -cp rpi.mjpeg.streamer-0.0.1-SNAPSHOT-jar-with-dependencies.jar wattihrvolt.rpi.mjpeg.streamer.MjpegStreamerApplication

or with parameters: (resolution: 1024x800, port: 8090)

java -cp rpi.mjpeg.streamer-0.0.1-SNAPSHOT-jar-with-dependencies.jar wattihrvolt.rpi.mjpeg.streamer.MjpegStreamerApplication -p 8090 -w 1024 -b 800

use -h for help.

View

Open the url in your browser:

http://<HOSTNAME_OR_IP>:PORT

or to directly take a snapshot

http://<HOSTNAME_OR_IP>:PORT/shapshot

connect to the mjepg stream

for example via vlc - open NetworkStream:

http://<HOSTNAME_OR_IP>:PORT/stream

Optional - Run as service

To start this as a service, you can use the following start/stop template

  • sudo vi /etc/init.d/rpicam

  • edit content of /etc/init.d/rpicam

#!/bin/sh
### BEGIN INIT INFO
# Provides:          rpi.mjpeg.streamer
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: rpicam service
# Description:       longer description here
### END INIT INFO

SERVICE_NAME=RpiCam
PATH_TO_JAR=/home/pi/rpi.mjpeg.streamer-0.0.1-SNAPSHOT-jar-with-dependencies.jar
MAIN_CLASS=wattihrvolt.rpi.mjpeg.streamer.MjpegStreamerApplication
PARAMETERS='-w 1024 -b 800 -t -p 8080'
PID_PATH_NAME=/tmp/RpiCam-pid
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
            nohup java -cp $PATH_TO_JAR $MAIN_CLASS $PARAMETERS /tmp 2>> /dev/null >> /dev/null &
            echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stoping ..."
            kill $PID;
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
            kill $PID;
            echo "$SERVICE_NAME stopped ...";
            rm $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            nohup java -cp $PATH_TO_JAR $MAIN_CLASS $PARAMETERS /tmp 2>> /dev/null >> /dev/null &
            echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac 

  • sudo chmod +x /etc/init.d/rpicam

  • sudo update-rc.d rpicam defaults

rpicam starts in the specified runlevels

you can use:

sudo /etc/init.d/rpicam start
sudo /etc/init.d/rpicam stop
sudo /etc/init.d/rpicam restart 

to start stop and restart the service

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.