mjpeg

package module
v0.0.0-...-531a153 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 6 Imported by: 0

README

Forked from HybridGroup

Changes

  • Adds support for streaming an MJPEG http response to Echo web server.
  • Added new func StreamToEcho.
  • StreamToEcho implements echo.Context to set header to image/jpeg content-type.
  • Writes mjpeg buffer to an Echo-type response and streams to http.

How to use

  • Initialise standard Echo server as per.
  • Define a Echo HTTP GET route.
  • Pass new StreamToEcho func as the handler.

Code Example

package main

import (
	"github.com/GaryMcBay/mjpeg"
	"github.com/labstack/echo"
)

func main() {

	e := echo.New()
	stream := mjpeg.NewStream()

	e.GET("/capture", stream.StreamToEcho)
	// Pass your jpegBuffer frames using stream.UpdateJPEG(<your-buffer>)

	// Start server
	e.Logger.Fatal(e.Start(":8080"))

}

Documentation

Overview

Package mjpeg implements a simple MJPEG streamer.

Stream objects implement the http.Handler interface, allowing to use them with the net/http package like so:

stream = mjpeg.NewStream()
http.Handle("/camera", stream)

Then push new JPEG frames to the connected clients using stream.UpdateJPEG().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stream

type Stream struct {
	FrameInterval time.Duration
	// contains filtered or unexported fields
}

Stream represents a single video feed.

func NewStream

func NewStream() *Stream

NewStream initializes and returns a new Stream.

func (*Stream) ServeHTTP

func (s *Stream) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP responds to HTTP requests with the MJPEG stream, implementing the http.Handler interface.

func (*Stream) StreamToEcho

func (s *Stream) StreamToEcho(c echo.Context) error

StreamToEcho implements Echo headers to respond to Echo HTTP requests with an MJPEG stream.

func (*Stream) UpdateJPEG

func (s *Stream) UpdateJPEG(jpeg []byte)

UpdateJPEG pushes a new JPEG frame onto the clients.

Jump to

Keyboard shortcuts

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