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

Use input stream instead of sample video

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

View File

@ -4,19 +4,16 @@ package webrtc
import (
"bufio"
"fmt"
"io"
"log"
"math/rand"
"net"
"os"
"os/exec"
"time"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/pkg/media"
"github.com/pion/webrtc/v3/pkg/media/h264reader"
"gitlab.crans.org/nounous/ghostream/messaging"
"io"
"log"
"math/rand"
"net"
"os/exec"
)
func ingest(name string, q *messaging.Quality) {
@ -34,8 +31,11 @@ func ingest(name string, q *messaging.Quality) {
return
}
f, _ := os.Open("CoffeeRun.h264")
h264, err := h264reader.NewReader(f)
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)
@ -46,7 +46,10 @@ func ingest(name string, q *messaging.Quality) {
// Receive video
go func() {
videoSocket, _ := videoListener.AcceptUnix()
h264, _ := h264reader.NewReader(videoSocket)
var spsAndPpsCache []byte
for {
nal, h264Err := h264.NextNAL()
if h264Err == io.EOF {
@ -58,8 +61,6 @@ func ingest(name string, q *messaging.Quality) {
break
}
time.Sleep(time.Second / 60)
if videoTracks[name] == nil {
videoTracks[name] = make([]*webrtc.Track, 0)
}
@ -128,6 +129,9 @@ func ingest(name string, q *messaging.Quality) {
func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err error) {
ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0",
// Vidéo
"-an", "-c:v", "copy",
"-f", "h264", "unix:///tmp/video.socket",
// Audio
"-vn", "-c:a", "libopus", "-b:a", "96k",
"-f", "rtp", fmt.Sprintf("rtp://127.0.0.1:%d", listeningPort)}