mirror of
https://github.com/lkmio/lkm.git
synced 2025-11-03 11:31:00 +08:00
封装rtsp udp拉流
This commit is contained in:
31
main.go
31
main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"github.com/yangjiechina/live-server/flv"
|
||||
"github.com/yangjiechina/live-server/hls"
|
||||
"github.com/yangjiechina/live-server/rtsp"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
@@ -14,6 +15,8 @@ import (
|
||||
"github.com/yangjiechina/live-server/stream"
|
||||
)
|
||||
|
||||
var rtspAddr *net.TCPAddr
|
||||
|
||||
func CreateTransStream(source stream.ISource, protocol stream.Protocol, streams []utils.AVStream) stream.ITransStream {
|
||||
if stream.ProtocolRtmp == protocol {
|
||||
return rtmp.NewTransStream(librtmp.ChunkSize)
|
||||
@@ -30,6 +33,13 @@ func CreateTransStream(source stream.ISource, protocol stream.Protocol, streams
|
||||
return transStream
|
||||
} else if stream.ProtocolFlv == protocol {
|
||||
return flv.NewHttpTransStream()
|
||||
} else if stream.ProtocolRtsp == protocol {
|
||||
trackFormat := source.Id() + "?track=%d"
|
||||
|
||||
return rtsp.NewTransStream(net.IPAddr{
|
||||
IP: rtspAddr.IP,
|
||||
Zone: rtspAddr.Zone,
|
||||
}, trackFormat)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -42,19 +52,32 @@ func init() {
|
||||
func main() {
|
||||
stream.AppConfig.GOPCache = true
|
||||
stream.AppConfig.MergeWriteLatency = 350
|
||||
|
||||
rtmpAddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:1935")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
impl := rtmp.NewServer()
|
||||
addr := "0.0.0.0:1935"
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
|
||||
err = impl.Start(rtmpAddr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = impl.Start(tcpAddr)
|
||||
println("启动rtmp服务成功:" + rtmpAddr.String())
|
||||
|
||||
rtspAddr, err = net.ResolveTCPAddr("tcp", "0.0.0.0:554")
|
||||
if err != nil {
|
||||
panic(rtspAddr)
|
||||
}
|
||||
|
||||
rtspServer := rtsp.NewServer()
|
||||
err = rtspServer.Start(rtspAddr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
println("启动rtmp服务成功:" + addr)
|
||||
println("启动rtsp服务成功:" + rtspAddr.String())
|
||||
|
||||
apiAddr := "0.0.0.0:8080"
|
||||
go startApiServer(apiAddr)
|
||||
|
||||
Reference in New Issue
Block a user