mirror of https://bitbucket.org/ausocean/av.git
Merged in webcam (pull request #86)
revid: addition of webcam input Approved-by: kortschak <dan@kortschak.io>
This commit is contained in:
commit
ef6811d3b8
|
@ -100,7 +100,7 @@ func handleFlags() revid.Config {
|
|||
var (
|
||||
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
|
||||
|
||||
inputPtr = flag.String("Input", "", "The input type: Raspivid, File")
|
||||
inputPtr = flag.String("Input", "", "The input type: Raspivid, File, Webcam")
|
||||
inputCodecPtr = flag.String("InputCodec", "", "The codec of the input: H264, Mjpeg")
|
||||
output1Ptr = flag.String("Output1", "", "The first output type: Http, Rtmp, File, Udp, Rtp")
|
||||
output2Ptr = flag.String("Output2", "", "The second output type: Http, Rtmp, File, Udp, Rtp")
|
||||
|
@ -148,6 +148,8 @@ func handleFlags() revid.Config {
|
|||
}
|
||||
|
||||
switch *inputPtr {
|
||||
case "Webcam":
|
||||
cfg.Input = revid.Webcam
|
||||
case "Raspivid":
|
||||
cfg.Input = revid.Raspivid
|
||||
case "File":
|
||||
|
|
|
@ -94,6 +94,7 @@ const (
|
|||
Udp
|
||||
MpegtsRtp
|
||||
Rtp
|
||||
Webcam
|
||||
)
|
||||
|
||||
// Default config settings
|
||||
|
@ -133,6 +134,7 @@ func (c *Config) Validate(r *Revid) error {
|
|||
switch c.Input {
|
||||
case Raspivid:
|
||||
case File:
|
||||
case Webcam:
|
||||
case NothingDefined:
|
||||
c.Logger.Log(logger.Warning, pkg+"no input type defined, defaulting", "input",
|
||||
defaultInput)
|
||||
|
|
|
@ -234,6 +234,8 @@ func (r *Revid) reset(config Config) error {
|
|||
}
|
||||
|
||||
switch r.config.Input {
|
||||
case Webcam:
|
||||
r.setupInput = r.startWebcam
|
||||
case Raspivid:
|
||||
r.setupInput = r.startRaspivid
|
||||
case File:
|
||||
|
@ -465,6 +467,28 @@ func (r *Revid) startRaspivid() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (r *Revid) startWebcam() error {
|
||||
r.config.Logger.Log(logger.Info, pkg+"starting webcam")
|
||||
r.cmd = exec.Command("ffmpeg", "-i", r.config.InputFileName, "-r", "25", "-f", "h264", "-")
|
||||
|
||||
delay := time.Second / time.Duration(r.config.FrameRate)
|
||||
stdout, err := r.cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = r.cmd.Start()
|
||||
if err != nil {
|
||||
r.config.Logger.Log(logger.Fatal, pkg+"cannot start webcam", "error", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
r.config.Logger.Log(logger.Info, pkg+"reading camera data")
|
||||
err = r.lexTo(r.encoder, stdout, delay)
|
||||
r.config.Logger.Log(logger.Info, pkg+"finished reading camera data")
|
||||
return err
|
||||
}
|
||||
|
||||
// setupInputForFile sets things up for getting input from a file
|
||||
func (r *Revid) setupInputForFile() error {
|
||||
delay := time.Second / time.Duration(r.config.FrameRate)
|
||||
|
|
Loading…
Reference in New Issue