diff --git a/ffmpeg.go b/ffmpeg.go index da73b7700..f117d8888 100644 --- a/ffmpeg.go +++ b/ffmpeg.go @@ -20,8 +20,9 @@ func startFfmpeg(configuration Config) { } log.Printf("Starting transcoder saving to /%s.", outputDir) + pipePath := getTempPipePath() - ffmpegCmd := "cat streampipe.flv | " + configuration.FFMpegPath + + ffmpegCmd := "cat " + pipePath + " | " + configuration.FFMpegPath + " -hide_banner -i pipe: -vf scale=" + strconv.Itoa(configuration.VideoSettings.ResolutionWidth) + ":-2 -g 48 -keyint_min 48 -preset ultrafast -f hls -hls_list_size 30 -hls_time " + strconv.Itoa(configuration.VideoSettings.ChunkLengthInSeconds) + " -strftime 1 -use_localtime 1 -hls_segment_filename '" + outputDir + "/stream-%Y%m%d-%s.ts' -hls_flags delete_segments -segment_wrap 100 " + hlsPlaylistName diff --git a/handler.go b/handler.go index 25fdcaa9e..54fb31d2b 100644 --- a/handler.go +++ b/handler.go @@ -6,7 +6,6 @@ import ( "io" "log" "os" - "path/filepath" "syscall" "github.com/pkg/errors" @@ -52,10 +51,9 @@ func (h *Handler) OnPublish(timestamp uint32, cmd *rtmpmsg.NetStreamPublish) err return errors.New("PublishingName is empty") } - // Record streams as FLV! - p := filepath.Join( - filepath.Clean(filepath.Join("./", fmt.Sprintf("%s.flv", "streampipe"))), - ) + // Record streams as FLV + p := getTempPipePath() + fmt.Println(p) syscall.Mkfifo(p, 0666) f, err := os.OpenFile(p, os.O_RDWR, os.ModeNamedPipe) if err != nil { diff --git a/main.go b/main.go index add7ad56b..bc2b5a93e 100644 --- a/main.go +++ b/main.go @@ -50,5 +50,7 @@ func startChatServer() { // static files http.Handle("/", http.FileServer(http.Dir("webroot"))) + log.Printf("Starting public web server on port %d", configuration.WebServerPort) + log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil)) } diff --git a/utils.go b/utils.go index 0de198e2c..ad55fc84b 100644 --- a/utils.go +++ b/utils.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "time" ) @@ -30,6 +31,10 @@ func touch(fileName string) { } } +func getTempPipePath() string { + return filepath.Join(os.TempDir(), "streampipe.flv") +} + func copy(src, dst string) { input, err := ioutil.ReadFile(src) if err != nil {