mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Transcode stream refactor (#609)
* Remove forceMkv and forceHEVC * Add HLS support and refactor * Add new streaming endpoints
This commit is contained in:
42
pkg/ffmpeg/hls.go
Normal file
42
pkg/ffmpeg/hls.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package ffmpeg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const hlsSegmentLength = 10.0
|
||||
|
||||
func WriteHLSPlaylist(probeResult VideoFile, baseUrl string, w io.Writer) {
|
||||
fmt.Fprint(w, "#EXTM3U\n")
|
||||
fmt.Fprint(w, "#EXT-X-VERSION:3\n")
|
||||
fmt.Fprint(w, "#EXT-X-MEDIA-SEQUENCE:0\n")
|
||||
fmt.Fprint(w, "#EXT-X-ALLOW-CACHE:YES\n")
|
||||
fmt.Fprintf(w, "#EXT-X-TARGETDURATION:%d\n", int(hlsSegmentLength))
|
||||
fmt.Fprint(w, "#EXT-X-PLAYLIST-TYPE:VOD\n")
|
||||
|
||||
duration := probeResult.Duration
|
||||
|
||||
leftover := duration
|
||||
upTo := 0.0
|
||||
|
||||
tsURL := baseUrl
|
||||
i := strings.LastIndex(baseUrl, ".m3u8")
|
||||
tsURL = baseUrl[0:i] + ".ts"
|
||||
|
||||
for leftover > 0 {
|
||||
thisLength := hlsSegmentLength
|
||||
if leftover < thisLength {
|
||||
thisLength = leftover
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "#EXTINF: %f,\n", thisLength)
|
||||
fmt.Fprintf(w, "%s?start=%f\n", tsURL, upTo)
|
||||
|
||||
leftover -= thisLength
|
||||
upTo += thisLength
|
||||
}
|
||||
|
||||
fmt.Fprint(w, "#EXT-X-ENDLIST\n")
|
||||
}
|
||||
Reference in New Issue
Block a user