ffmpeg

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2019 License: MIT Imports: 7 Imported by: 0

README

Simple Go FFMPEG Library for RTSP streams (IP cameras)

Capture video footage from RTSP IP cameras.

Provides a simple interface to set FFMPEG options and capture video from an RTSP source.

Lots of other libraries out there do ffmpeg and rtsp things, but I couldn't find any that fit this simple task of "get a video snippet from a camera."

Example

package main

import (
	"log"

	"github.com/golift/ffmpeg"
)

func main() {
	/* Example non-transcode direct-save from securityspy. */

	securitypsy := "rtsp://user:pass@127.0.0.1:8000/++stream?cameraNum=1"
	output := "/tmp/securitypsy_captured_file.mov"
	c := &ffmpeg.Config{
		FFMPEG: "/usr/local/bin/ffmpeg",
		Copy:   true, // do not transcode
		Audio:  true, // retain audio stream
		Time:   10,   // 10 seconds
	}
	encode := ffmpeg.Get(c)
	cmd, out, err := encode.SaveVideo(securitypsy, output, "SecuritySpyVideoTitle")
	log.Println("Command Used:", cmd)
	log.Println("Command Output:", out)
	if err != nil {
		log.Fatalln(err)
	}
	log.Println("Saved file from", securitypsy, "to", output)

	/* Example transcode from a Dahua IP camera. */

	dahua := "rtsp://admin:password@192.168.1.12/live"
	output = "/tmp/dahua_captured_file.m4v"
	f := ffmpeg.Get(&ffmpeg.Config{
		Audio:  true, // retain audio stream
		Time:   10,   // 10 seconds
		Width:  1920,
		Height: 1080,
		CRF:    23,
		Level:  "4.0",
		Rate:   5,
		Prof:   "baseline",
	})
	cmd, out, err = f.SaveVideo(dahua, output, "DahuaVideoTitle")
	log.Println("Command Used:", cmd)
	log.Println("Command Output:", out)
	if err != nil {
		log.Fatalln(err)
	}
	log.Println("Saved file from", dahua, "to", output)
}


Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultFrameRate   = 5
	MinimumFrameRate   = 1
	MaximumFrameRate   = 60
	DefaultFrameHeight = 720
	DefaultFrameWidth  = 1280
	MinimumFrameSize   = 100
	MaximumFrameSize   = 5000
	DefaultEncodeCRF   = 21
	MinimumEncodeCRF   = 16
	MaximumEncodeCRF   = 30
	DefaultCaptureTime = 15
	MaximumCaptureTime = 1200             // 10 minute max.
	DefaultCaptureSize = int64(2500000)   // 2.5MB default (roughly 5-10 seconds)
	MaximumCaptureSize = int64(104857600) // 100MB max.
	DefaultFFmpegPath  = "/usr/local/bin/ffmpeg"
	DefaultProfile     = "main"
	DefaultLevel       = "3.0"
	ErrorInvalidOutput = errors.New("output path is not valid")
	ErrorInvalidInput  = errors.New("input path is not valid")
)

Default, Maximum and Minimum Values

Functions

This section is empty.

Types

type Config

type Config struct {
	FFMPEG string // "/usr/local/bin/ffmpeg"
	Level  string // 3.0, 3.1 ..
	Width  int    // 1920
	Height int    // 1080
	CRF    int    // 24
	Time   int    // 15 (seconds)
	Audio  bool   // include audio?
	Rate   int    // framerate (5-20)
	Size   int64  // max file size (always goes over). use 2000000 for 2.5MB
	Prof   string // main, high, baseline
	Copy   bool   // Copy original stream, rather than transcode.
}

Config defines how to ffmpeg shall transcode a stream.

type Encoder

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

Encoder is the struct returned by this library. Contains all the bound methods.

func Get

func Get(config *Config) *Encoder

Get an encoder interface.

func (*Encoder) Config

func (e *Encoder) Config() Config

Config returns the current values in the encoder.

func (*Encoder) GetVideo

func (e *Encoder) GetVideo(input, title string) (string, io.ReadCloser, error)

GetVideo retreives video from an input and returns a Reader to consume the output. The Reader contains output messages if output is a filepath. The Reader contains the video if the output is "-"

func (*Encoder) SaveVideo

func (e *Encoder) SaveVideo(input, output, title string) (string, string, error)

SaveVideo saves a video snippet to a file.

func (*Encoder) SetAudio

func (e *Encoder) SetAudio(audio string) bool

SetAudio turns audio on or off based on a string value.

func (*Encoder) SetCRF

func (e *Encoder) SetCRF(crf string) int

SetCRF sets the h264 transcode CRF value.

func (*Encoder) SetHeight

func (e *Encoder) SetHeight(height string) int

SetHeight sets the transcode frame width.

func (*Encoder) SetLevel

func (e *Encoder) SetLevel(level string) string

SetLevel sets the h264 transcode level.

func (*Encoder) SetProfile

func (e *Encoder) SetProfile(profile string) string

SetProfile sets the h264 transcode profile.

func (*Encoder) SetRate

func (e *Encoder) SetRate(rate string) int

SetRate sets the transcode framerate.

func (*Encoder) SetSize

func (e *Encoder) SetSize(size string) int64

SetSize sets the maximum transcode file size.

func (*Encoder) SetTime

func (e *Encoder) SetTime(seconds string) int

SetTime sets the maximum transcode duration.

func (*Encoder) SetWidth

func (e *Encoder) SetWidth(width string) int

SetWidth sets the transcode frame width.

Jump to

Keyboard shortcuts

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