rpicamvid

package module
v0.0.0-...-9bd6c8f Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 14 Imported by: 0

README

go-rpicamvid

Go (Golang) wrapper for rpicam-vid (Raspberry Pi Video Capture Application) with stream demultiplexer and HTTP server.

The demultiplexer allows multiple concurrent stream consumers from a single rpicam-vid process.

This implementation produces a MJPEG image stream.

Build

git clone https://github.com/cleroux/go-rpicamvid.git
cd go-rpicamvid
make

Run

./rpicamvid-server

Open video stream in browser at http://localhost:8080

Example Code

stream, err := r.Start()
if err != nil {
	fmt.Printf("Failed to start camera: %v\n", err)
	return
}
defer stream.Close()

for {
	jpegBytes, err := stream.GetFrame()
	if err != nil {
		fmt.Printf("Failed to get camera frame: %v\n", err)
		continue
	}
	// TODO: Do something with the JPEG frame
}

See cmd/server/main.go for a complete example.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("stream closed")
View Source
var ErrNoFrames = errors.New("no image frames to read")

Functions

func ContextMiddleware

func ContextMiddleware(ctx context.Context, next http.HandlerFunc) http.HandlerFunc

ContextMiddleware replaces the request context with the given context. It can be used to set a cancellable context only for streaming endpoints since the HTTP Server will not cancel in-flight requests on shutdown.

Types

type Frame

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

func (*Frame) Close

func (f *Frame) Close() error

func (*Frame) GetBytes

func (f *Frame) GetBytes() []byte

type Rpicamvid

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

func New

func New(log *log.Logger, width, height int, opts ...string) *Rpicamvid

func (*Rpicamvid) HTTPHandler

func (r *Rpicamvid) HTTPHandler(w http.ResponseWriter, req *http.Request)

HTTPHandler is an HTTP route handler that responds with an MJPEG video stream from the rpicam-vid application.

func (*Rpicamvid) Start

func (r *Rpicamvid) Start() (*Stream, error)

type Stream

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

Stream provides []byte frames. It is intended to be used by a single consumer.

func (*Stream) Close

func (s *Stream) Close()

Close closes the stream.

func (*Stream) GetFrame

func (s *Stream) GetFrame() (*Frame, error)

GetFrame returns a single image frame, blocking to wait until the next frame if necessary.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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