封装hls

This commit is contained in:
yangjiechina
2024-03-06 20:42:17 +08:00
parent f7552240d0
commit de6cca48ca
8 changed files with 254 additions and 39 deletions

18
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
"github.com/yangjiechina/live-server/hls"
"net"
"net/http"
@@ -12,18 +13,25 @@ import (
"github.com/yangjiechina/live-server/stream"
)
func CreateTransStream(protocol stream.Protocol, streams []utils.AVStream) stream.ITransStream {
func CreateTransStream(source stream.ISource, protocol stream.Protocol, streams []utils.AVStream) stream.ITransStream {
if stream.ProtocolRtmp == protocol {
return rtmp.NewTransStream(librtmp.ChunkSize)
} else if stream.ProtocolHls == protocol {
id := source.Id()
m3u8Name := id + ".m3u8"
tsFormat := id + "_%d.ts"
transStream, err := hls.NewTransStream("/live/hls/", m3u8Name, tsFormat, "../tmp/", 2, 10)
if err != nil {
panic(err)
}
return transStream
}
return nil
}
func requestStream(sourceId string) {
}
func init() {
stream.TransStreamFactory = CreateTransStream
}