mjpeg

package module
v0.0.3 Latest Latest
Warning

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

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

README

hz.tools/mjpeg

This package implements support of mjpeg / M-JPEG (or "Motion JPEG"), a fairly strightforward protocol where every frame of a video stream is encoded as a standalone JPEG, streamed to the client.

Go Reference Go Report Card

Documentation

Overview

Package mjpeg implements support for mjpeg (sometimes M-JPEG) video streams.

Each frame of the stream is sent as an encoded JPEG. This, while it has quite a bit of overhead, is simple to work with both from a client and server point of view. Clients update the stream frame-by-frame with a golang image.Image.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// FrameDuration determines how many frames per second are sent to the
	// client.
	FrameDuration time.Duration

	// Context is the root context -- not related to the context of the
	// per-connection HTTP streams, which is pulled from the http.Request
	Context context.Context
}

Options contains all the knobs exposed from the library.

type Stream

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

Stream contains a handle to the underlying image to be distributed to listening clients, as well as some internal state.

This is thread-safe; any client may update or call methods on this object, and that will make its way out to all clients.

func NewStream

func NewStream() *Stream

NewStream will return a new Stream object, with default options. If control over timings, etc is required, you may use the NewStreamWithOptions helper.

func NewStreamWithOptions

func NewStreamWithOptions(opts Options) *Stream

NewStreamWithOptions will return a new Stream object, with the options specified by the caller.

func (*Stream) ServeHTTP

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

ServeHTTP will handle an HTTP request.

func (*Stream) Update

func (s *Stream) Update(i image.Image) error

Update will set the current frame to the provided Image. This will preform a JPEG encoding, and stream those bytes -- this image handle will not be held by the Stream after this call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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