1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 20:52:20 +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 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 // Start ffmpag to convert videoInput to audio UDP
ffmpeg, err := startFFmpeg(videoInput, firstPort) ffmpeg, ffmpegOut, err := startFFmpeg(videoInput, firstPort)
if err != nil { if err != nil {
log.Printf("Error while starting ffmpeg: %s", err) log.Printf("Error while starting ffmpeg: %s", err)
return return
@ -46,8 +40,7 @@ func ingest(name string, q *messaging.Quality) {
// Receive video // Receive video
go func() { go func() {
videoSocket, _ := videoListener.AcceptUnix() h264, _ := h264reader.NewReader(*ffmpegOut)
h264, _ := h264reader.NewReader(videoSocket)
var spsAndPpsCache []byte var spsAndPpsCache []byte
for { for {
@ -127,11 +120,11 @@ func ingest(name string, q *messaging.Quality) {
q.Unregister(videoInput) 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", ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0",
// Vidéo // Vidéo
"-an", "-c:v", "copy", "-an", "-c:v", "copy", "-bsf", "h264_mp4toannexb",
"-f", "h264", "unix:///tmp/video.socket", "-f", "h264", "pipe:1",
// Audio // Audio
"-vn", "-c:a", "libopus", "-b:a", "96k", "-vn", "-c:a", "libopus", "-b:a", "96k",
"-f", "rtp", fmt.Sprintf("rtp://127.0.0.1:%d", listeningPort)} "-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 // Handle errors output
errOutput, err := ffmpeg.StderrPipe() errOutput, err := ffmpeg.StderrPipe()
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
go func() { go func() {
scanner := bufio.NewScanner(errOutput) scanner := bufio.NewScanner(errOutput)
@ -152,7 +145,7 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err
// Handle stream input // Handle stream input
input, err := ffmpeg.StdinPipe() input, err := ffmpeg.StdinPipe()
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
go func() { go func() {
for data := range in { for data := range in {
@ -165,7 +158,12 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err
ffmpeg.Process.Kill() ffmpeg.Process.Kill()
}() }()
output, err := ffmpeg.StdoutPipe()
if err != nil {
return nil, nil, err
}
// Start process // Start process
err = ffmpeg.Start() err = ffmpeg.Start()
return ffmpeg, err return ffmpeg, &output, err
} }