videostore

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package videostore contains the implementation of the video storage camera component.

Index

Constants

This section is empty.

Variables

View Source
var Model = resource.ModelNamespace("viam").WithFamily("video").WithModel("storage")

Model is the model for the video storage camera component.

Functions

func ParseDateTimeString

func ParseDateTimeString(datetime string) (time.Time, error)

ParseDateTimeString parses a date and time string in the format "2006-01-02_15-04-05". Returns a time.Time object and an error if the string is not in the correct format.

func SetFFmpegLogCallback

func SetFFmpegLogCallback()

SetFFmpegLogCallback sets the custom log callback for ffmpeg.

func SetLibAVLogLevel

func SetLibAVLogLevel(level string)

SetLibAVLogLevel sets the libav log level. this is global for the entire OS process. valid inputs are "info", "warn", "error", "debug" https://www.ffmpeg.org/doxygen/2.5/group__lavu__log__constants.html

Types

type CodecType

type CodecType int

CodecType repreasents a codec

const (
	// CodecTypeUnknown is an invalid type.
	CodecTypeUnknown CodecType = iota
	// CodecTypeH264 represents h264 codec
	CodecTypeH264
	// CodecTypeH265 represents h265 codec
	CodecTypeH265
)

func (CodecType) String

func (t CodecType) String() string

type Config

type Config struct {
	Type        SourceType
	Storage     StorageConfig
	Encoder     EncoderConfig
	FramePoller FramePollerConfig
}

Config configures a videostore.

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the Config is invalid.

type EncoderConfig

type EncoderConfig struct {
	Bitrate int
	Preset  string
}

EncoderConfig is the config for the video encoder.

func (EncoderConfig) Validate

func (c EncoderConfig) Validate() error

Validate returns an error if the EncoderConfig is invalid.

type FetchRequest

type FetchRequest struct {
	From time.Time
	To   time.Time
}

FetchRequest is the request to the Fetch method

func (*FetchRequest) Validate

func (r *FetchRequest) Validate() error

Validate returns an error if the FetchRequest is invalid

type FetchResponse

type FetchResponse struct {
	Video []byte
}

FetchResponse is the resonse to the Fetch method

type FramePollerConfig

type FramePollerConfig struct {
	Camera    camera.Camera
	Framerate int
	YUYV      bool
}

FramePollerConfig is the config for the frame poller.

func (FramePollerConfig) Validate

func (c FramePollerConfig) Validate() error

Validate returns an error if the FramePollerConfig is invalid.

type RTPVideoStore

type RTPVideoStore interface {
	VideoStore
	Segmenter() *RawSegmenter
}

RTPVideoStore stores video derived from RTP packets and provides APIs to request the stored video

func NewRTPVideoStore

func NewRTPVideoStore(config Config, logger logging.Logger) (RTPVideoStore, error)

NewRTPVideoStore returns a VideoStore that stores video it receives from the caller

type RawSegmenter

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

RawSegmenter stores video in supported codecs to disk in segment video files

func (*RawSegmenter) Close

func (rs *RawSegmenter) Close() error

Close closes the segmenter and writes the trailer to prevent corruption when exiting early in the middle of a segment. Init may be called after Close

func (*RawSegmenter) Init

func (rs *RawSegmenter) Init(codec CodecType, width, height int) error

Init initializes the *RawSegmenter Close must be called to free the resources taken during Init Note: May write to disk

func (*RawSegmenter) WritePacket

func (rs *RawSegmenter) WritePacket(payload []byte, pts, dts int64, isIDR bool) error

WritePacket writes video data in the codec passed to Init to the current segment file. Can't be called before Init is called

type SaveRequest

type SaveRequest struct {
	From     time.Time
	To       time.Time
	Metadata string
	Async    bool
}

SaveRequest is the request to the Save method

func (*SaveRequest) Validate

func (r *SaveRequest) Validate() error

Validate returns an error if the SaveRequest is invalid

type SaveResponse

type SaveResponse struct {
	Filename string
}

SaveResponse is the response to the Save method

type SourceType

type SourceType int

SourceType describes the type of video source.

const (
	// SourceTypeUnknown is an invalid type.
	SourceTypeUnknown SourceType = iota
	// SourceTypeFrame is a video store that creates a video from frames.
	SourceTypeFrame
	// SourceTypeRTP is a video store that creates a video from rtp packets.
	SourceTypeRTP
	// SourceTypeReadOnly is a video store that only reads already stored segment files.
	SourceTypeReadOnly
)

func (SourceType) String

func (t SourceType) String() string

type StorageConfig

type StorageConfig struct {
	SizeGB               int
	OutputFileNamePrefix string
	UploadPath           string
	StoragePath          string
}

StorageConfig is the config for storage.

func (StorageConfig) Validate

func (c StorageConfig) Validate() error

Validate returns an error if the StorageConfig is invalid.

type VideoStore

type VideoStore interface {
	Fetch(ctx context.Context, r *FetchRequest) (*FetchResponse, error)
	Save(ctx context.Context, r *SaveRequest) (*SaveResponse, error)
	Close()
}

VideoStore stores video and provides APIs to request the stored video

func NewFramePollingVideoStore

func NewFramePollingVideoStore(_ context.Context, config Config, logger logging.Logger) (VideoStore, error)

NewFramePollingVideoStore returns a VideoStore that stores video it encoded from polling frames from a camera.Camera

func NewReadOnlyVideoStore

func NewReadOnlyVideoStore(config Config, logger logging.Logger) (VideoStore, error)

NewReadOnlyVideoStore returns a VideoStore that can return stored video but doesn't create new video segements

Jump to

Keyboard shortcuts

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