1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 20:52:20 +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 ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"log"
"math/rand"
"net"
"os"
"os/exec"
"time"
"github.com/pion/rtp" "github.com/pion/rtp"
"github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/pkg/media" "github.com/pion/webrtc/v3/pkg/media"
"github.com/pion/webrtc/v3/pkg/media/h264reader" "github.com/pion/webrtc/v3/pkg/media/h264reader"
"gitlab.crans.org/nounous/ghostream/messaging" "gitlab.crans.org/nounous/ghostream/messaging"
"io"
"log"
"math/rand"
"net"
"os/exec"
) )
func ingest(name string, q *messaging.Quality) { func ingest(name string, q *messaging.Quality) {
@ -34,8 +31,11 @@ func ingest(name string, q *messaging.Quality) {
return return
} }
f, _ := os.Open("CoffeeRun.h264") videoListener, err := net.ListenUnix("unix", &net.UnixAddr{Name: "/tmp/video.socket", Net: "unix"})
h264, err := h264reader.NewReader(f) 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, err := startFFmpeg(videoInput, firstPort)
@ -46,7 +46,10 @@ func ingest(name string, q *messaging.Quality) {
// Receive video // Receive video
go func() { go func() {
videoSocket, _ := videoListener.AcceptUnix()
h264, _ := h264reader.NewReader(videoSocket)
var spsAndPpsCache []byte var spsAndPpsCache []byte
for { for {
nal, h264Err := h264.NextNAL() nal, h264Err := h264.NextNAL()
if h264Err == io.EOF { if h264Err == io.EOF {
@ -58,8 +61,6 @@ func ingest(name string, q *messaging.Quality) {
break break
} }
time.Sleep(time.Second / 60)
if videoTracks[name] == nil { if videoTracks[name] == nil {
videoTracks[name] = make([]*webrtc.Track, 0) 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) { func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err error) {
ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0", ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0",
// Vidéo
"-an", "-c:v", "copy",
"-f", "h264", "unix:///tmp/video.socket",
// 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)}