Skip to content

Commit 5b9225f

Browse files
authored
add hostname to broadcast variables. (#576)
1 parent e867434 commit 5b9225f

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

server/internal/capture/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package capture
33
import (
44
"errors"
55
"fmt"
6+
"os"
67
"strings"
78

89
"github.com/rs/zerolog"
@@ -80,6 +81,10 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
8081
broadcast: broadcastNew(func(url string) (string, error) {
8182
if config.BroadcastPipeline != "" {
8283
var pipeline = config.BroadcastPipeline
84+
if hostname, err := os.Hostname(); err == nil {
85+
// replace {hostname} with valid hostname
86+
pipeline = strings.Replace(pipeline, "{hostname}", hostname, 1)
87+
}
8388
// replace {display} with valid display
8489
pipeline = strings.Replace(pipeline, "{display}", config.Display, 1)
8590
// replace {device} with valid device

server/internal/config/capture.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func (Capture) InitV2(cmd *cobra.Command) error {
298298
// broadcast
299299
//
300300

301-
cmd.PersistentFlags().String("broadcast_pipeline", "", "V2: custom gst pipeline used for broadcasting, strings {url} {device} {display} will be replaced")
301+
cmd.PersistentFlags().String("broadcast_pipeline", "", "V2: custom gst pipeline used for broadcasting, strings {hostname} {url} {device} {display} will be replaced")
302302
if err := viper.BindPFlag("broadcast_pipeline", cmd.PersistentFlags().Lookup("broadcast_pipeline")); err != nil {
303303
return err
304304
}

server/internal/config/capture_pipeline.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33

44
import (
55
"fmt"
6+
"os"
67
"strings"
78

89
"github.com/m1k1o/neko/server/pkg/gst"
@@ -40,12 +41,17 @@ func NewBroadcastPipeline(device string, display string, pipelineSrc string, url
4041

4142
var pipelineStr string
4243
if pipelineSrc != "" {
44+
pipelineStr = pipelineSrc
45+
// replace {hostname} with valid hostname
46+
if hostname, err := os.Hostname(); err == nil {
47+
pipelineStr = strings.ReplaceAll(pipelineStr, "{hostname}", hostname)
48+
}
4349
// replace RTMP url
44-
pipelineStr = strings.Replace(pipelineSrc, "{url}", url, -1)
50+
pipelineStr = strings.ReplaceAll(pipelineStr, "{url}", url)
4551
// replace audio device
46-
pipelineStr = strings.Replace(pipelineStr, "{device}", device, -1)
52+
pipelineStr = strings.ReplaceAll(pipelineStr, "{device}", device)
4753
// replace display
48-
pipelineStr = strings.Replace(pipelineStr, "{display}", display, -1)
54+
pipelineStr = strings.ReplaceAll(pipelineStr, "{display}", display)
4955
} else {
5056
pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s x264enc bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", url, audio, video)
5157
}

webpage/docs/configuration/capture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ The default encoder uses `h264` for video and `aac` for audio, muxed in the `flv
347347

348348
- <Def id="broadcast.audio_bitrate" /> and <Def id="broadcast.video_bitrate" /> are the bitrate settings for the default audio and video encoders expressed in kilobits per second.
349349
- <Def id="broadcast.preset" /> is the encoding speed preset for the default video encoder. See available presets [here](https://gstreamer.freedesktop.org/documentation/x264/index.html?gi-language=c#GstX264EncPreset).
350-
- <Def id="broadcast.pipeline" /> when set, encoder settings above are ignored and the custom Gstreamer pipeline description is used. In the pipeline, you can use `{display}`, `{device}` and `{url}` as placeholders for the X display name, pulseaudio audio device name, and broadcast URL respectively.
350+
- <Def id="broadcast.pipeline" /> when set, encoder settings above are ignored and the custom Gstreamer pipeline description is used. In the pipeline, you can use `{hostname}`, `{display}`, `{device}` and `{url}` as placeholders for the X display name, pulseaudio audio device name, and broadcast URL respectively.
351351
- <Def id="broadcast.url" /> is the URL of the RTMP server where the broadcast will be sent e.g. `rtmp://<server>/<application>/<stream_key>`. This can be set later using the API if the URL is not known at the time of configuration or is expected to change.
352352
- <Def id="broadcast.autostart" /> is a boolean value that determines whether the broadcast should start automatically when neko starts, works only if the URL is set.
353353

webpage/docs/migration-from-v2/help.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
"broadcast_pipeline"
251251
],
252252
"type": "string",
253-
"description": "custom gst pipeline used for broadcasting, strings {url} {device} {display} will be replaced"
253+
"description": "custom gst pipeline used for broadcasting, strings {hostname} {url} {device} {display} will be replaced"
254254
},
255255
{
256256
"key": [

webpage/docs/migration-from-v2/help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
--audio string audio codec parameters to use for streaming
3838
--audio_bitrate int audio bitrate in kbit/s
3939

40-
--broadcast_pipeline string custom gst pipeline used for broadcasting, strings {url} {device} {display} will be replaced
40+
--broadcast_pipeline string custom gst pipeline used for broadcasting, strings {hostname} {url} {device} {display} will be replaced
4141
--broadcast_url string a default default URL for broadcast streams, can be disabled/changed later by admins in the GUI
4242
--broadcast_autostart automatically start broadcasting when neko starts and broadcast_url is set
4343

0 commit comments

Comments
 (0)