1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 15:02:19 +00:00

Use stdout instead of Unix socket

This commit is contained in:
Yohann D'ANELLO 2020-11-07 22:11:21 +01:00
parent bdd67a5bd2
commit cc40226111

View File

@ -31,14 +31,8 @@ func ingest(name string, q *messaging.Quality) {
return
}
videoListener, err := net.ListenUnix("unix", &net.UnixAddr{Name: "/tmp/video.socket", Net: "unix"})
if err != nil {
log.Printf("Faited to open UNIX socket %s", err)
return
}
// Start ffmpag to convert videoInput to audio UDP
ffmpeg, err := startFFmpeg(videoInput, firstPort)
ffmpeg, ffmpegOut, err := startFFmpeg(videoInput, firstPort)
if err != nil {
log.Printf("Error while starting ffmpeg: %s", err)
return
@ -46,8 +40,7 @@ func ingest(name string, q *messaging.Quality) {
// Receive video
go func() {
videoSocket, _ := videoListener.AcceptUnix()
h264, _ := h264reader.NewReader(videoSocket)
h264, _ := h264reader.NewReader(*ffmpegOut)
var spsAndPpsCache []byte
for {
@ -127,11 +120,11 @@ func ingest(name string, q *messaging.Quality) {
q.Unregister(videoInput)
}
func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err error) {
func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, stdout *io.ReadCloser, err error) {
ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0",
// Vidéo
"-an", "-c:v", "copy",
"-f", "h264", "unix:///tmp/video.socket",
"-an", "-c:v", "copy", "-bsf", "h264_mp4toannexb",
"-f", "h264", "pipe:1",
// Audio
"-vn", "-c:a", "libopus", "-b:a", "96k",
"-f", "rtp", fmt.Sprintf("rtp://127.0.0.1:%d", listeningPort)}
@ -140,7 +133,7 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err
// Handle errors output
errOutput, err := ffmpeg.StderrPipe()
if err != nil {
return nil, err
return nil, nil, err
}
go func() {
scanner := bufio.NewScanner(errOutput)
@ -152,7 +145,7 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err
// Handle stream input
input, err := ffmpeg.StdinPipe()
if err != nil {
return nil, err
return nil, nil, err
}
go func() {
for data := range in {
@ -165,7 +158,12 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err
ffmpeg.Process.Kill()
}()
output, err := ffmpeg.StdoutPipe()
if err != nil {
return nil, nil, err
}
// Start process
err = ffmpeg.Start()
return ffmpeg, err
return ffmpeg, &output, err
}