init
This commit is contained in:
commit
0cbcd9a837
9 changed files with 244 additions and 0 deletions
54
server/main.go
Normal file
54
server/main.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func segmentHandler(ctx *gin.Context) {
|
||||
segment := ctx.Param("segment")
|
||||
if !strings.HasSuffix(segment, ".ts") {
|
||||
ctx.Status(404)
|
||||
return
|
||||
}
|
||||
|
||||
cmd := exec.Command(
|
||||
"/usr/bin/ffmpeg",
|
||||
"-nostdin", "-hide_banner", "-loglevel", "error",
|
||||
"-hwaccel", "cuda", "-hwaccel_output_format", "cuda",
|
||||
"-i", "../video/"+segment,
|
||||
"-vf", "scale_cuda=1280:720",
|
||||
"-copyts",
|
||||
"-c:v", "hevc_nvenc", "-preset", "fast",
|
||||
"-c:a", "copy",
|
||||
"-f", "mpegts", "-mpegts_copyts", "1",
|
||||
"-")
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cmd.Start()
|
||||
//data, _ := cmd.Output()
|
||||
/*
|
||||
f, err := os.OpenFile("../reencoded/"+segment, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
*/
|
||||
|
||||
//ctx.Data(200, "video/MP2T; charset=binary", data)
|
||||
ctx.DataFromReader(200, -1, "video/MP2T; charset=binary", stdout, nil)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Note: the working directory should be one level above
|
||||
router := gin.Default()
|
||||
router.StaticFile("/", "../index.html")
|
||||
router.StaticFile("/video/bbb.m3u8", "../video/bbb.m3u8")
|
||||
router.GET("/video/:segment", segmentHandler)
|
||||
router.Run()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue