mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 15:02:19 +00:00
Add ability to format output URL with the start time of the stream, if the stream is recorded.
This commit is contained in:
parent
ac2f87e936
commit
5ea8a0913b
@ -38,13 +38,17 @@ auth:
|
|||||||
## Stream forwarding ##
|
## Stream forwarding ##
|
||||||
# Forward an incoming stream to other servers
|
# Forward an incoming stream to other servers
|
||||||
# The URL can be anything FFMpeg can accept as an stream output
|
# The URL can be anything FFMpeg can accept as an stream output
|
||||||
|
# If a file is specified, the name may contains %Y, %m, %d, %H, %M or %S
|
||||||
|
# that will be replaced by the current date information.
|
||||||
forwarding:
|
forwarding:
|
||||||
# By default nothing is forwarded.
|
# By default nothing is forwarded.
|
||||||
#
|
#
|
||||||
# This example forwards a stream named "demo" to Twitch and YouTube,
|
# This example forwards a stream named "demo" to Twitch and YouTube,
|
||||||
|
# and save the record in a timestamped-file,
|
||||||
#demo:
|
#demo:
|
||||||
# - rtmp://live-cdg.twitch.tv/app/STREAM_KEY
|
# - rtmp://live-cdg.twitch.tv/app/STREAM_KEY
|
||||||
# - rtmp://a.rtmp.youtube.com/live2/STREAM_KEY
|
# - rtmp://a.rtmp.youtube.com/live2/STREAM_KEY
|
||||||
|
# - /home/ghostream/lives/%name/live-%Y-%m-%d-%H-%M-%S.flv
|
||||||
|
|
||||||
## Prometheus monitoring ##
|
## Prometheus monitoring ##
|
||||||
# Expose a monitoring endpoint for Prometheus
|
# Expose a monitoring endpoint for Prometheus
|
||||||
|
@ -3,8 +3,11 @@ package forwarding
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitlab.crans.org/nounous/ghostream/messaging"
|
"gitlab.crans.org/nounous/ghostream/messaging"
|
||||||
)
|
)
|
||||||
@ -49,20 +52,30 @@ func Serve(streams *messaging.Streams, cfg Options) {
|
|||||||
|
|
||||||
// Start forwarding
|
// Start forwarding
|
||||||
log.Printf("Starting forwarding for '%s' quality '%s'", name, qualityName)
|
log.Printf("Starting forwarding for '%s' quality '%s'", name, qualityName)
|
||||||
go forward(quality, streamCfg)
|
go forward(name, quality, streamCfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a FFMPEG instance and redirect stream output to forwarded streams
|
// Start a FFMPEG instance and redirect stream output to forwarded streams
|
||||||
func forward(q *messaging.Quality, fwdCfg []string) {
|
func forward(streamName string, q *messaging.Quality, fwdCfg []string) {
|
||||||
output := make(chan []byte, 1024)
|
output := make(chan []byte, 1024)
|
||||||
q.Register(output)
|
q.Register(output)
|
||||||
|
|
||||||
// Launch FFMPEG instance
|
// Launch FFMPEG instance
|
||||||
params := []string{"-hide_banner", "-loglevel", "error", "-re", "-i", "pipe:0"}
|
params := []string{"-hide_banner", "-loglevel", "error", "-re", "-i", "pipe:0"}
|
||||||
for _, url := range fwdCfg {
|
for _, url := range fwdCfg {
|
||||||
|
// If the url should be date-formatted, replace special characters with the current time information
|
||||||
|
now := time.Now()
|
||||||
|
formattedURL := strings.ReplaceAll(url, "%Y", fmt.Sprintf("%04d", now.Year()))
|
||||||
|
formattedURL = strings.ReplaceAll(formattedURL, "%m", fmt.Sprintf("%02d", now.Month()))
|
||||||
|
formattedURL = strings.ReplaceAll(formattedURL, "%d", fmt.Sprintf("%02d", now.Day()))
|
||||||
|
formattedURL = strings.ReplaceAll(formattedURL, "%H", fmt.Sprintf("%02d", now.Hour()))
|
||||||
|
formattedURL = strings.ReplaceAll(formattedURL, "%M", fmt.Sprintf("%02d", now.Minute()))
|
||||||
|
formattedURL = strings.ReplaceAll(formattedURL, "%S", fmt.Sprintf("%02d", now.Second()))
|
||||||
|
formattedURL = strings.ReplaceAll(formattedURL, "%name", streamName)
|
||||||
|
|
||||||
params = append(params, "-f", "flv", "-preset", "ultrafast", "-tune", "zerolatency",
|
params = append(params, "-f", "flv", "-preset", "ultrafast", "-tune", "zerolatency",
|
||||||
"-c", "copy", url)
|
"-c", "copy", formattedURL)
|
||||||
}
|
}
|
||||||
ffmpeg := exec.Command("ffmpeg", params...)
|
ffmpeg := exec.Command("ffmpeg", params...)
|
||||||
|
|
||||||
@ -95,7 +108,7 @@ func forward(q *messaging.Quality, fwdCfg []string) {
|
|||||||
go func() {
|
go func() {
|
||||||
scanner := bufio.NewScanner(errOutput)
|
scanner := bufio.NewScanner(errOutput)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
log.Printf("[FORWARDING FFMPEG] %s", scanner.Text())
|
log.Printf("[FORWARDING FFMPEG %s] %s", streamName, scanner.Text())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user