mirror of
https://github.com/snowlyg/GoEasyFfmpeg
synced 2026-04-22 22:57:07 +08:00
增加使用 go_ffmpeg 模式
This commit is contained in:
+13
-10
@@ -1,19 +1,22 @@
|
||||
.vscode
|
||||
/goeasyffmpeg
|
||||
/*.exe
|
||||
/*.exe~
|
||||
/logs
|
||||
/*.log
|
||||
node_modules
|
||||
*.db
|
||||
*.db.bak
|
||||
/*.zip
|
||||
/*.tar.gz
|
||||
/*.dev.ini
|
||||
/*.dev.db
|
||||
.idea
|
||||
.DS_Store
|
||||
/*.db
|
||||
/*.db.bak
|
||||
/*.ini
|
||||
/*.dll
|
||||
|
||||
/.vscode
|
||||
/node_modules/
|
||||
/www/
|
||||
/.idea
|
||||
/.DS_Store
|
||||
/logs
|
||||
|
||||
Unnamed
|
||||
debug
|
||||
*.ini
|
||||
www/
|
||||
/goeasyffmpeg
|
||||
@@ -16,7 +16,6 @@ require (
|
||||
github.com/gorilla/context v1.1.1
|
||||
github.com/gorilla/securecookie v1.1.1
|
||||
github.com/gorilla/sessions v1.2.0
|
||||
github.com/issue9/term v1.1.0 // indirect
|
||||
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
|
||||
github.com/jinzhu/gorm v1.9.12
|
||||
github.com/jonboulle/clockwork v0.1.0 // indirect
|
||||
@@ -27,10 +26,10 @@ require (
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/onsi/ginkgo v1.12.2 // indirect
|
||||
github.com/penggy/cors v0.0.0-20180918145040-d08bb28f7e48
|
||||
github.com/penggy/gobuild v0.7.2-0.20190318034240-e495bc939062 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/shirou/gopsutil v2.20.4+incompatible
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
github.com/snowlyg/go_ffmpeg v0.0.0-20200630145053-9c7b76a3bb95
|
||||
github.com/tebeka/strftime v0.1.4 // indirect
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
|
||||
@@ -72,9 +72,6 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+
|
||||
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
|
||||
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/issue9/assert v1.3.2/go.mod h1:9Ger+iz8X7r1zMYYwEhh++2wMGWcNN2oVI+zIQXxcio=
|
||||
github.com/issue9/term v1.1.0 h1:vKTjD4c0rxw+B7LLfwSypMaVTkyP9DrqyLLgFWsVTVw=
|
||||
github.com/issue9/term v1.1.0/go.mod h1:9/YTi/aRSKOIy44Wso2xDWXJvMLAEYWskjutTkyUBN0=
|
||||
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
|
||||
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
|
||||
github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q=
|
||||
@@ -130,8 +127,6 @@ github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/penggy/cors v0.0.0-20180918145040-d08bb28f7e48 h1:hy1KCfzBOzO70pyGh62FKDVu0lJN8vfKzvAwY9xPjVY=
|
||||
github.com/penggy/cors v0.0.0-20180918145040-d08bb28f7e48/go.mod h1:7ZxfmRpyLzLsFuBNxwsTBq2+perYnFnMS9vEE4GQpkA=
|
||||
github.com/penggy/gobuild v0.7.2-0.20190318034240-e495bc939062 h1:2kdre/EjsGccbmntHo2EKyBuh7FUDZkZMel1EQoD21Q=
|
||||
github.com/penggy/gobuild v0.7.2-0.20190318034240-e495bc939062/go.mod h1:zbuRb2uA+nz652vl02g4lNsfm/f6xxQGpTj/HIK1jsk=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
@@ -143,6 +138,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/snowlyg/go_ffmpeg v0.0.0-20200630145053-9c7b76a3bb95 h1:PqwfywxkLiv2sobqdRl4LAzcalcoYAazVpbDVF2jSak=
|
||||
github.com/snowlyg/go_ffmpeg v0.0.0-20200630145053-9c7b76a3bb95/go.mod h1:/RqwqtAOyWNyIoozMf7ST0Q/3sDnR/rYpdEIGQoncJg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
@@ -169,7 +166,6 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190310054646-10058d7d4faa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
+55
-53
@@ -1,15 +1,14 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/snowlyg/GoEasyFfmpeg/extend/utils"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/snowlyg/go_ffmpeg"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -38,13 +37,13 @@ func GetServer() *Server {
|
||||
// Start 启动
|
||||
func (server *Server) Start() (err error) {
|
||||
logger := server.logger
|
||||
ffmpeg := utils.Conf().Section("rtsp").Key("ffmpeg_path").MustString("")
|
||||
debugLogEnable := utils.Conf().Section("rtsp").Key("debug_log_enable").MustBool(false)
|
||||
//ffmpeg := utils.Conf().Section("rtsp").Key("ffmpeg_path").MustString("")
|
||||
//debugLogEnable := utils.Conf().Section("rtsp").Key("debug_log_enable").MustBool(false)
|
||||
m3u8DirPath := utils.Conf().Section("rtsp").Key("m3u8_dir_path").MustString("")
|
||||
m3u8DirPath = strings.TrimRight(strings.Replace(m3u8DirPath, "\\", "/", -1), "/")
|
||||
|
||||
go func() { // 保持到本地
|
||||
pusher2FfmpegMap := make(map[*Pusher]*exec.Cmd)
|
||||
//pusher2FfmpegMap := make(map[*Pusher]*exec.Cmd)
|
||||
logger.Printf("Prepare to save stream to local....")
|
||||
defer logger.Printf("End save stream to local....")
|
||||
var pusher *Pusher
|
||||
@@ -62,61 +61,64 @@ func (server *Server) Start() (err error) {
|
||||
continue
|
||||
}
|
||||
|
||||
pusherPath = path.Join(pusherPath, fmt.Sprintf("out.m3u8"))
|
||||
paramStr := utils.Conf().Section("rtsp").Key("decoder").MustString("-strict -2 -threads 2 -c:v copy -c:a copy -f rtsp")
|
||||
paramsOfThisPath := strings.Split(paramStr, " ")
|
||||
var params []string
|
||||
if !strings.Contains(pusher.Source, ".m3u8") {
|
||||
params = []string{"-rtsp_transport", "tcp", "-fflags", "+genpts", "-i", pusher.Source, pusherPath}
|
||||
params = append(params[:6], append(paramsOfThisPath, params[6:]...)...)
|
||||
} else {
|
||||
params := []string{"-fflags", "+genpts", "-i", pusher.Source, pusherPath}
|
||||
params = append(params[:4], append(paramsOfThisPath, params[4:]...)...)
|
||||
}
|
||||
//pusherPath = path.Join(pusherPath, fmt.Sprintf("out.m3u8"))
|
||||
//paramStr := utils.Conf().Section("rtsp").Key("decoder").MustString("-strict -2 -threads 2 -c:v copy -c:a copy -f rtsp")
|
||||
//paramsOfThisPath := strings.Split(paramStr, " ")
|
||||
|
||||
cmd := exec.Command(ffmpeg, params...)
|
||||
|
||||
if debugLogEnable {
|
||||
logpath := fmt.Sprintf("%s_log.txt", pusher.Path)
|
||||
f, err := os.OpenFile(path.Join(m3u8DirPath, logpath), os.O_RDWR|os.O_CREATE, 0755)
|
||||
if err == nil {
|
||||
cmd.Stdout = f
|
||||
cmd.Stderr = f
|
||||
}
|
||||
}
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
logger.Printf("Start ffmpeg err:%v", err)
|
||||
}
|
||||
pusher2FfmpegMap[pusher] = cmd
|
||||
logger.Printf("add ffmpeg [%v] to pull stream from pusher[%v]", cmd, pusher)
|
||||
go go_ffmpeg.ToHls(pusher.Source, pusherPath, "tcp")
|
||||
//var params []string
|
||||
//if !strings.Contains(pusher.Source, ".m3u8") {
|
||||
// params = []string{"-rtsp_transport", "tcp", "-fflags", "+genpts", "-i", pusher.Source, pusherPath}
|
||||
// params = append(params[:6], append(paramsOfThisPath, params[6:]...)...)
|
||||
//} else {
|
||||
// params := []string{"-fflags", "+genpts", "-i", pusher.Source, pusherPath}
|
||||
// params = append(params[:4], append(paramsOfThisPath, params[4:]...)...)
|
||||
//}
|
||||
//
|
||||
//
|
||||
//cmd := exec.Command(ffmpeg, params...)
|
||||
//
|
||||
//if debugLogEnable {
|
||||
// logpath := fmt.Sprintf("%s_log.txt", pusher.Path)
|
||||
// f, err := os.OpenFile(path.Join(m3u8DirPath, logpath), os.O_RDWR|os.O_CREATE, 0755)
|
||||
// if err == nil {
|
||||
// cmd.Stdout = f
|
||||
// cmd.Stderr = f
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//err = cmd.Start()
|
||||
//if err != nil {
|
||||
// logger.Printf("Start ffmpeg err:%v", err)
|
||||
//}
|
||||
//pusher2FfmpegMap[pusher] = cmd
|
||||
//logger.Printf("add ffmpeg [%v] to pull stream from pusher[%v]", cmd, pusher)
|
||||
//f.Close()
|
||||
} else {
|
||||
logger.Printf("addPusherChan closed")
|
||||
}
|
||||
case pusher, removeChnOk = <-server.removePusherCh:
|
||||
if removeChnOk {
|
||||
cmd := pusher2FfmpegMap[pusher]
|
||||
proc := cmd.Process
|
||||
if proc != nil {
|
||||
logger.Printf("prepare to SIGTERM to process:%v", proc)
|
||||
proc.Signal(syscall.SIGTERM)
|
||||
proc.Wait()
|
||||
|
||||
logger.Printf("process:%v terminate.", proc)
|
||||
}
|
||||
delete(pusher2FfmpegMap, pusher)
|
||||
logger.Printf("delete ffmpeg from pull stream from pusher[%v]", pusher)
|
||||
//cmd := pusher2FfmpegMap[pusher]
|
||||
//proc := cmd.Process
|
||||
//if proc != nil {
|
||||
// logger.Printf("prepare to SIGTERM to process:%v", proc)
|
||||
// proc.Signal(syscall.SIGTERM)
|
||||
// proc.Wait()
|
||||
//
|
||||
// logger.Printf("process:%v terminate.", proc)
|
||||
//}
|
||||
//delete(pusher2FfmpegMap, pusher)
|
||||
//logger.Printf("delete ffmpeg from pull stream from pusher[%v]", pusher)
|
||||
} else {
|
||||
for _, cmd := range pusher2FfmpegMap {
|
||||
proc := cmd.Process
|
||||
if proc != nil {
|
||||
logger.Printf("prepare to SIGTERM to process:%v", proc)
|
||||
proc.Signal(syscall.SIGTERM)
|
||||
}
|
||||
}
|
||||
pusher2FfmpegMap = make(map[*Pusher]*exec.Cmd)
|
||||
//for _, cmd := range pusher2FfmpegMap {
|
||||
// proc := cmd.Process
|
||||
// if proc != nil {
|
||||
// logger.Printf("prepare to SIGTERM to process:%v", proc)
|
||||
// proc.Signal(syscall.SIGTERM)
|
||||
// }
|
||||
//}
|
||||
//pusher2FfmpegMap = make(map[*Pusher]*exec.Cmd)
|
||||
logger.Printf("removePusherChan closed")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user