Support multiple adaptive bitrates

This commit is contained in:
Gabe Kangas
2020-06-09 01:52:15 -07:00
parent 29f51f6ccc
commit 0b5452de89
9 changed files with 213 additions and 54 deletions

View File

@@ -1,8 +1,15 @@
package main
import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
)
func getTempPipePath() string {
@@ -18,8 +25,43 @@ func fileExists(name string) bool {
return true
}
func getRelativePathFromAbsolutePath(path string) string {
pathComponents := strings.Split(path, "/")
variant := pathComponents[len(pathComponents)-2]
file := pathComponents[len(pathComponents)-1]
return filepath.Join(variant, file)
}
func verifyError(e error) {
if e != nil {
panic(e)
log.Panic(e)
}
}
func copy(src, dst string) {
input, err := ioutil.ReadFile(src)
if err != nil {
fmt.Println(err)
return
}
err = ioutil.WriteFile(dst, input, 0644)
if err != nil {
fmt.Println("Error creating", dst)
fmt.Println(err)
return
}
}
func resetDirectories(configuration Config) {
// Wipe the public, web-accessible hls data directory
os.RemoveAll(configuration.PublicHLSPath)
os.MkdirAll(configuration.PublicHLSPath, 0777)
// Create private hls data dirs
os.RemoveAll(configuration.PrivateHLSPath)
for index := range configuration.VideoSettings.StreamQualities {
os.MkdirAll(path.Join(configuration.PrivateHLSPath, strconv.Itoa(index)), 0777)
os.MkdirAll(path.Join(configuration.PublicHLSPath, strconv.Itoa(index)), 0777)
}
}