Skip to content

Commit

Permalink
Add 配置 flv使用内置头
Browse files Browse the repository at this point in the history
  • Loading branch information
qydysky committed Jun 15, 2024
1 parent 8b2e354 commit 5846dab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
34 changes: 20 additions & 14 deletions Reply/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,17 @@ func (t *M4SStream) saveStreamFlv() (e error) {
{
pipe := pio.NewPipe()
var (
leastReadUnix atomic.Int64
readTO int64 = 3
leastReadUnix atomic.Int64
readTO int64 = 3
useInterFlvHeader bool = false
)
leastReadUnix.Store(time.Now().Unix())
if v, ok := t.common.K_v.LoadV(`flv断流超时s`).(float64); ok && int64(v) > readTO {
readTO = int64(v)
}
if v, ok := t.common.K_v.LoadV(`flv使用内置头`).(bool); ok && v {
useInterFlvHeader = v
}

// read timeout
go func() {
Expand Down Expand Up @@ -820,18 +824,20 @@ func (t *M4SStream) saveStreamFlv() (e error) {
}
if keyframe.Size() != 0 {
if len(t.first_buf) == 0 {
switch v.Codec {
case "hevc":
t.log.L(`W: `, `flv未接收到起始段,使用内置头`)
t.first_buf = t.first_buf[:0]
t.first_buf = append(t.first_buf, flvHeaderHevc...)
t.msg.Push_tag(`load`, t)
case "avc":
t.log.L(`W: `, `flv未接收到起始段,使用内置头`)
t.first_buf = t.first_buf[:0]
t.first_buf = append(t.first_buf, flvHeader...)
t.msg.Push_tag(`load`, t)
default:
if useInterFlvHeader {
switch v.Codec {
case "hevc":
t.log.L(`W: `, `flv未接收到起始段,使用内置头`)
t.first_buf = t.first_buf[:0]
t.first_buf = append(t.first_buf, flvHeaderHevc...)
t.msg.Push_tag(`load`, t)
case "avc":
t.log.L(`W: `, `flv未接收到起始段,使用内置头`)
t.first_buf = t.first_buf[:0]
t.first_buf = append(t.first_buf, flvHeader...)
t.msg.Push_tag(`load`, t)
default:
}
}
if len(t.first_buf) == 0 {
t.log.L(`W: `, `flv未接收到起始段`)
Expand Down
1 change: 1 addition & 0 deletions demo/config/config_K_v.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"直播流接收n帧才保存": 3,
"flv断流超时s": 5,
"flv断流续接": true,
"flv使用内置头": false,
"fmp4切片下载超时s": 3,
"fmp4获取更多服务器": true,
"fmp4跳过解码出错的帧-help": "fmp4跳过解码出错的帧、但可能导致关键帧时间上的跳越",
Expand Down

0 comments on commit 5846dab

Please sign in to comment.