mirror of
https://github.com/owncast/owncast.git
synced 2025-11-02 03:54:54 +08:00
refactor: use io.Pipe and ffmpeg's stdin (#1148)
This removes the usage of `syscall.Mkfifo` which was previously used and won't work on Windows systems and opens the door for other processes on the computer to interfere in the rtmp stream (dumping bad content in the fifo, removing the file, blocking the file in offline status). Instead, this patch introduces an `io.Pipe` which pipes the RTMP stream to the ffmpeg command while staying in Owncast. Further links: * ffmpeg on using `pipe:0` as an input: https://ffmpeg.org/ffmpeg-protocols.html#pipe
This commit is contained in:
@ -3,6 +3,7 @@ package transcoder
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -22,6 +23,7 @@ var _commandExec *exec.Cmd
|
||||
// Transcoder is a single instance of a video transcoder.
|
||||
type Transcoder struct {
|
||||
input string
|
||||
stdin *io.PipeReader
|
||||
segmentOutputPath string
|
||||
playlistOutputPath string
|
||||
variants []HLSVariant
|
||||
@ -95,6 +97,11 @@ func (t *Transcoder) Start() {
|
||||
}
|
||||
|
||||
_commandExec = exec.Command("sh", "-c", command)
|
||||
|
||||
if t.stdin != nil {
|
||||
_commandExec.Stdin = t.stdin
|
||||
}
|
||||
|
||||
stdout, err := _commandExec.StderrPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -240,7 +247,7 @@ func NewTranscoder() *Transcoder {
|
||||
// Playlists are available via the local HTTP server
|
||||
transcoder.playlistOutputPath = config.PublicHLSStoragePath
|
||||
|
||||
transcoder.input = utils.GetTemporaryPipePath(fmt.Sprint(data.GetRTMPPortNumber()))
|
||||
transcoder.input = "pipe:0" // stdin
|
||||
|
||||
for index, quality := range transcoder.currentStreamOutputSettings {
|
||||
variant := getVariantFromConfigQuality(quality, index)
|
||||
@ -389,6 +396,11 @@ func (t *Transcoder) SetInput(input string) {
|
||||
t.input = input
|
||||
}
|
||||
|
||||
// SetStdin sets the Stdin of the ffmpeg command.
|
||||
func (t *Transcoder) SetStdin(rtmp *io.PipeReader) {
|
||||
t.stdin = rtmp
|
||||
}
|
||||
|
||||
// SetOutputPath sets the root directory that should include playlists and video segments.
|
||||
func (t *Transcoder) SetOutputPath(output string) {
|
||||
t.segmentOutputPath = output
|
||||
|
Reference in New Issue
Block a user