Skip to content

Commit

Permalink
Starting to add further output options
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
  • Loading branch information
s00500 committed May 15, 2021
1 parent 034a99e commit 7c23975
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
26 changes: 0 additions & 26 deletions ffmpeg.go

This file was deleted.

3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func main() {
}

func openStream(dev *gousb.Device) {
ffmpegIn, stopPlayer := StartFFMPEGInstance()
sink := FFPlaySink{}
ffmpegIn, stopPlayer := sink.StartInstance()
// claim interface
intf, done, err := googleInterface(dev)
if err != nil {
Expand Down
49 changes: 49 additions & 0 deletions sinks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"io"
"os/exec"
"syscall"

log "github.com/s00500/env_logger"
)

type StreamSink interface {
StartInstance() (io.WriteCloser, func())
}

type FFPlaySink struct {
}

func (sink FFPlaySink) StartInstance() (io.WriteCloser, func()) {
additionalArgs := []string{"-fast", "-flags2", "fast", "-fflags", "nobuffer", "-flags", "low_delay", "-strict", "experimental", "-vf", "setpts=N/60/TB", "-framedrop", "-sync", "ext", "-probesize", "32", "-analyzeduration", "0"}
args := []string{"-i", "-"}
args = append(args, additionalArgs...)
cmd := exec.Command("ffplay", args...)
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal("Could not get ffplay stdin")
}
log.MustFatal(cmd.Start())
return stdin, func() {
cmd.Process.Signal(syscall.SIGKILL) // Not ellegant... could try sigterm and wait before...
}
}

type UdpSink struct {
}

func (sink UdpSink) StartInstance() (io.WriteCloser, func()) {
additionalArgs := []string{"-vcodec", "mpeg4", "-v", "0", "-f", "mpegts", "udp://127.0.0.1:23000"}
args := []string{"-i", "-"}
args = append(args, additionalArgs...)
cmd := exec.Command("ffmpeg", args...)
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal("Could not get ffmpeg stdin")
}
log.MustFatal(cmd.Start())
return stdin, func() {
cmd.Process.Signal(syscall.SIGKILL) // Not ellegant... could try sigterm and wait before...
}
}

0 comments on commit 7c23975

Please sign in to comment.