Skip to content

Commit

Permalink
Add BaseURL config parameter
Browse files Browse the repository at this point in the history
to specify a base url for segment files in the playlist file
  • Loading branch information
Thor77 committed Jun 13, 2021
1 parent ac665ee commit 4368ee3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ ffmpeg -i <input file> -f flv "rtmp://localhost/stream01"
| MsPerSegment | `int64` | `15000` | Milliseconds of video/audio written to one segment file |
| LogLevel | `log.Level` | `"info"` | Level for the internal logger |
| HLSDirectory | `string` | `"."` | Directory to write playlist/segment files into
| BaseURL | `string` | | Base URL to use as a prefix for segment files in playlist file |
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Config struct {
MsPerSegment int64
LogLevel log.Level
HLSDirectory string
BaseURL string
}

func loadConfig(path string) (Config, error) {
Expand Down
9 changes: 8 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"math"
"os"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -163,7 +164,13 @@ func publishHandler(conn *rtmp.Conn) {
streamLogger.Debugf("Wrote segment %s\n", segmentName)

// update playlist
playlist.Slide(segmentName, segmentLength.Seconds(), "")
var playlistSegmentName string
if config.BaseURL != "" {
playlistSegmentName = path.Join(config.BaseURL, path.Base(segmentName))
} else {
playlistSegmentName = segmentName
}
playlist.Slide(playlistSegmentName, segmentLength.Seconds(), "")
playlistFile, err := os.Create(playlistFileName)
if err != nil {
handleError(streamLogger, conn, err)
Expand Down

0 comments on commit 4368ee3

Please sign in to comment.