paparazzogo

package module
v0.0.0-...-fbb8f74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 12 Imported by: 1

README

Paparazzo.go

A stalker of IP cameras

endorse

What is this?

A high performance caching web proxy for serving MJPG streams to the masses.

Features

  • Easy to use.
  • Done with Go programming language.
  • Compatible with http.HandlerFunc.
  • No unnecessary network traffic to IP-camera.
  • Serves MJPEG-stream as single jpeg-images.
  • Works with every browser.
  • Supports client-side caching.

IPCamera (1) <-> (1) Paparazzo.go (1) <-> (N) Users

Demo screenshot

Background

IP cameras can't handle web traffic

IP cameras are slow devices that can't handle a regular amount of web traffic. So if you plan to go public with an IP camera you have the following options:

  1. The naive approach - Embed the camera service directly in your site, e.g. http://201.166.63.44/axis-cgi/jpg/image.cgi?resolution=CIF.
  2. Ye olde approach - Serve images as static files in your server. I've found that several sites use this approach through messy PHP background jobs that update this files at slow intervals, generating excessive (and unnecessary) disk accesses.
  3. Plug n' pray approach - Embed a flash or Java-based player, such as the Cambozola player. This requires plugins.
  4. MJPG proxy - Serve the MJPG stream directly if you are targeting only grade A browsers, (sorry IE).
  5. Paparazzo.go: A web service of dynamic images - Build a MJPG proxy server which parses the stream, updates images in memory, and delivers new images on demand. This approach is scalable, elegant, blazing fast and doesn't require disk access.

Usage

Get Paparazzo and start demo:

go get github.com/putsi/paparazzogo

cd $GOPATH/src/github.com/putsi/paparazzogo/demo
go run demo.go
open demo.html

Customization of settings:

mjpegHandler := &paparazzogo.Mjpegproxy{
	// Max MJPEG-frame size (5Mb by default).
	partbufsize: 625000,

	// Sleep time between error and reconnecting to stream (one second by default).
	waittime: time.Second * 1,

	// How long to use one stream response before reconnecting (one hour by default).
	responseduration: time.Hour,

	// Caching enables/disables support for client-side caching
	// of jpg-files. If enabled, saves bandwidth.
	// If disabled, allows more than one frame per second.
	// Enabled by default.
	caching: true,
}

See more examples in demo-folder.

Licence

Use of this source code is governed by a MIT-style licence that can be found in the LICENCE-file.

See Also

The original Paparazzo.js for NodeJS!

Documentation

Overview

Package paparazzogo implements a caching proxy for serving MJPEG-stream as JPG-images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mjpegproxy

type Mjpegproxy struct {
	// contains filtered or unexported fields
}

A Mjpegproxy implements http.Handler interface and generates JPG-images from a MJPEG-stream.

func NewMjpegproxy

func NewMjpegproxy() *Mjpegproxy

NewMjpegproxy returns a new Mjpegproxy with default values.

func (*Mjpegproxy) CloseStream

func (m *Mjpegproxy) CloseStream()

CloseStream stops and closes MJPEG-stream.

func (*Mjpegproxy) GetRunning

func (m *Mjpegproxy) GetRunning() bool

GetRunning returns state of openstream.

func (*Mjpegproxy) OpenStream

func (m *Mjpegproxy) OpenStream(mjpegStream, user, pass string, timeout time.Duration)

OpenStream creates a go-routine of openstream.

func (*Mjpegproxy) ServeHTTP

func (m *Mjpegproxy) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP uses w to serve current last MJPEG-frame as JPG. It also reopens MJPEG-stream if it was closed by idle timeout.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL