Documentation
¶
Overview ¶
Package vid contains various utilities for reading from video files and cameras.
Index ¶
- Variables
- func Probe(path string) (fileProbe *FFProbeJSON, vidProbe *FFStream, err error)
- func ProbeSize(path string) (w, h int, err error)
- type CamConfig
- type CamSrc
- type FFDisposition
- type FFFormat
- type FFProbeJSON
- type FFStream
- type FFTags
- type FileSrc
- type FourCC
- type JPEGScanner
- type PiCam3Config
- type PiCam3Src
- type Src
- type SrcBuf
Constants ¶
This section is empty.
Variables ¶
var ( // FourCCMJPEG means Motion-JPEG. FourCCMJPEG = FourCC(v4l2.PixelFmtMJPEG) // FourCCYUYV means YUYV 4:2:2. FourCCYUYV = FourCC(v4l2.PixelFmtYUYV) // FourCCYUV420 means yuv420p. FourCCYUV420 = FourCCFromString("YU12") )
Functions ¶
Types ¶
type CamConfig ¶
type CamConfig struct { // For example /dev/video0. DeviceFile string // Format is the image format FourCC to request from the camera, for example "MJPG". // To list available formats and frame sizes: // // v4l2-ctl --list-formats-ext --device /dev/video2 Format FourCC `json:"-"` // FormatStr is Format converted to a string. It is only used for JSON serialization and does not need to be set // when opening a camera. FormatStr string `json:"Format"` FrameSize image.Point }
CamConfig describes an available v4l2 camera device with a given pixel format and frame size.
func DetectCams ¶
DetectCams returns a list of detected cameras and their supported pixel formats and frame sizes. This works even if some of the devices are currently in use. Cameras which list no available pixel formats, or produce errors on open, are ignored. Only fixed frame sizes are included.
type CamSrc ¶
type CamSrc struct {
// contains filtered or unexported fields
}
CamSrc is a video frame source which supports video4linux. Use NewCamSrc to open one.
func (*CamSrc) GetFrameRaw ¶
GetFrameRaw returns a raw frame in the specified pixel format from the camera.
type FFDisposition ¶
type FFDisposition struct { Default int `json:"default"` Dub int `json:"dub"` Original int `json:"original"` Comment int `json:"comment"` Lyrics int `json:"lyrics"` Karaoke int `json:"karaoke"` Forced int `json:"forced"` HearingImpaired int `json:"hearing_impaired"` VisualImpaired int `json:"visual_impaired"` CleanEffects int `json:"clean_effects"` AttachedPic int `json:"attached_pic"` TimedThumbnails int `json:"timed_thumbnails"` }
FFDisposition is a part of ffprobe JSON output. See FFProbeJSON.
type FFFormat ¶
type FFFormat struct { Filename string `json:"filename"` NbStreams int `json:"nb_streams"` NbPrograms int `json:"nb_programs"` FormatName string `json:"format_name"` FormatLongName string `json:"format_long_name"` StartTime string `json:"start_time"` Duration string `json:"duration"` Size string `json:"size"` BitRate string `json:"bit_rate"` ProbeScore int `json:"probe_score"` Tags FFTags `json:"tags"` }
FFFormat is a part of ffprobe JSON output. See FFProbeJSON.
type FFProbeJSON ¶
FFProbeJSON represents ffprobe JSON output.
type FFStream ¶
type FFStream struct { Index int `json:"index"` CodecName string `json:"codec_name"` CodecLongName string `json:"codec_long_name"` Profile string `json:"profile"` CodecType string `json:"codec_type"` CodecTimeBase string `json:"codec_time_base"` CodecTagString string `json:"codec_tag_string"` CodecTag string `json:"codec_tag"` Width int `json:"width,omitempty"` Height int `json:"height,omitempty"` CodedWidth int `json:"coded_width,omitempty"` CodedHeight int `json:"coded_height,omitempty"` HasBFrames int `json:"has_b_frames,omitempty"` PixFmt string `json:"pix_fmt,omitempty"` Level int `json:"level,omitempty"` ColorRange string `json:"color_range,omitempty"` ColorSpace string `json:"color_space,omitempty"` ColorTransfer string `json:"color_transfer,omitempty"` ColorPrimaries string `json:"color_primaries,omitempty"` ChromaLocation string `json:"chroma_location,omitempty"` Refs int `json:"refs,omitempty"` IsAvc string `json:"is_avc,omitempty"` NalLengthSize string `json:"nal_length_size,omitempty"` RFrameRate string `json:"r_frame_rate"` AvgFrameRate string `json:"avg_frame_rate"` TimeBase string `json:"time_base"` StartPts int `json:"start_pts"` StartTime string `json:"start_time"` DurationTS int `json:"duration_ts"` Duration string `json:"duration"` BitRate string `json:"bit_rate"` BitsPerRawSample string `json:"bits_per_raw_sample,omitempty"` NbFrames string `json:"nb_frames"` Disposition FFDisposition `json:"disposition"` Tags FFTags `json:"tags"` SampleFmt string `json:"sample_fmt,omitempty"` SampleRate string `json:"sample_rate,omitempty"` Channels int `json:"channels,omitempty"` ChannelLayout string `json:"channel_layout,omitempty"` BitsPerSample int `json:"bits_per_sample,omitempty"` MaxBitRate string `json:"max_bit_rate,omitempty"` }
FFStream is a part of ffprobe JSON output. See FFProbeJSON.
type FFTags ¶
type FFTags struct { CreationTime time.Time `json:"creation_time"` Language string `json:"language"` HandlerName string `json:"handler_name"` MajorBrand string `json:"major_brand"` MinorVersion string `json:"minor_version"` CompatibleBrands string `json:"compatible_brands"` Encoder string `json:"encoder"` }
FFTags is a part of ffprobe JSON output. See FFProbeJSON.
type FileSrc ¶
type FileSrc struct {
// contains filtered or unexported fields
}
FileSrc is a video file source. Use NewFileSrc() to get an instance.
func NewFileSrc ¶
NewFileSrc creates a new FileSrc.
func (*FileSrc) GetFrameRaw ¶
GetFrameRaw implements Src.
type FourCC ¶
type FourCC int32
FourCC is a FourCC pixel format.
func FourCCFromString ¶
FourCCFromString converts a string to a numeric FourCC code. Returns 0 on failure.
type JPEGScanner ¶
type JPEGScanner struct {
// contains filtered or unexported fields
}
JPEGScanner works similar to bufio.Scanner but on JPEG images. Useful to pull frame after frame out of a MJPEG stream.
func NewJPEGScanner ¶
func NewJPEGScanner(r io.Reader) *JPEGScanner
NewJPEGScanner creates a new JPEGScanner. Responsibility to close reader remains with caller.
func (*JPEGScanner) Scan ¶
func (s *JPEGScanner) Scan() ([]byte, error)
Scan reads until it has read an entire JPEG image, and returns the buffer containing its data. https://github.com/corkami/formats/blob/master/image/jpeg.md.
type PiCam3Config ¶
type PiCam3Config struct { // ROI to extract. Defaults to full image if empty. Rect image.Rectangle // Constant lens focus, 0=infinity, 2=approx. 0.5m. Focus float64 // Rotate image by 180 degree if true. Rotate180 bool // Pixel format. Format FourCC // Frames per second. FPS int }
PiCam3Config is the configuration for a PiCam3Src.
type PiCam3Src ¶
type PiCam3Src struct {
// contains filtered or unexported fields
}
PiCam3Src is a video frame source which reads frames from a Raspberry PI 3 camera module. It uses the `libcamera-vid` utility internally. Use NewPiCam3Src() to open one.
func NewPiCam3Src ¶
func NewPiCam3Src(c PiCam3Config) (*PiCam3Src, error)
NewPiCam3Src creates a new PiCam3Src.
func (*PiCam3Src) GetFrameRaw ¶
GetFrameRaw implements Src.
type Src ¶
type Src interface { // GetFrame retrieves the next frame. // Note that the underlying image buffer remains owned by the video source, // it must not be changed by the caller and might be overwritten on the next // invocation. // Returns io.EOF after the last frame, after which Close() should be called // on the instance before discarding it. GetFrame() (image.Image, *time.Time, error) // GetFrameRaw retrieves the next frame in the raw pixel format of the source. // Note that the underlying image buffer remains owned by the video source, // it must not be changed by the caller and might be overwritten on the next // invocation. // Not all sources might implement this. GetFrameRaw() ([]byte, FourCC, *time.Time, error) // IsLive returns if the src is a live source (e.g. camera). IsLive() bool // GetFPS returns the current frame rate of this source. GetFPS() float64 // Close closes the frame source and frees resources. Close() error }
Src describes a frame source.
type SrcBuf ¶
type SrcBuf struct {
// contains filtered or unexported fields
}
SrcBuf buffers a video source. Use NewSrcBuf to create an instance.
func NewSrcBuf ¶
NewSrcBuf creates a new SrcBuf. Will not close src, caller needs to do that after last frame is read.
func (*SrcBuf) GetFrame ¶
GetFrame returns the next frame. As soon as this returns an error once, the instance needs to be discarded. The underlying image buffer will be owned by the caller, src will not reuse or modify it.
func (*SrcBuf) GetFrameRaw ¶
GetFrameRaw implements Src.