shorten playlist size, use stream key to construct uri for http server

This commit is contained in:
Muaz Ahmad 2023-08-21 15:10:07 +05:00
parent 223bbf40f7
commit 14336095ea
2 changed files with 8 additions and 6 deletions

View file

@ -9,8 +9,7 @@ import (
func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) { func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
StreamCleanup(chnk_wrp_ptr.params.stream_key, 0) StreamCleanup(chnk_wrp_ptr.params.stream_key, 0)
base_dir, _ := os.UserHomeDir() file_writer, err := flv.NewFLVWriter(chnk_wrp_ptr.params.stream_key)
file_writer, err := flv.NewFLVWriter(base_dir + "/live/" + chnk_wrp_ptr.params.stream_key + "/")
defer file_writer.Close() defer file_writer.Close()
if err != nil { if err != nil {
return return

View file

@ -4,27 +4,30 @@ import (
"io" "io"
"os/exec" "os/exec"
"encoding/binary" "encoding/binary"
"os"
) )
type FLVWriter struct { type FLVWriter struct {
w io.WriteCloser w io.WriteCloser
} }
func NewFLVWriter(stream_dir string) (*FLVWriter, error) { func NewFLVWriter(stream_key string) (*FLVWriter, error) {
base_dir, _ := os.UserHomeDir()
writer := new(FLVWriter) writer := new(FLVWriter)
transcoder := exec.Command( transcoder := exec.Command(
"ffmpeg", "ffmpeg",
"-probesize", "5000", "-probesize", "500",
"-i", "pipe:0", "-i", "pipe:0",
"-c:a", "aac", "-c:a", "aac",
"-c:v", "h264", "-c:v", "h264",
"-b:v", "1M", "-b:v", "1M",
"-hls_time", "6", "-hls_time", "6",
"-hls_list_size", "10", "-hls_list_size", "4",
"-hls_base_url", "/vid/" + stream_key + "/",
"-hls_flags", "delete_segments", "-hls_flags", "delete_segments",
"stream.m3u8", "stream.m3u8",
) )
transcoder.Dir = stream_dir transcoder.Dir = base_dir + "/live/" + stream_key + "/"
flvpipe, err := transcoder.StdinPipe() flvpipe, err := transcoder.StdinPipe()
transcoder.Start() transcoder.Start()
if err != nil { if err != nil {