From b47e0b2a00535ffab6cd732087dbcfc297f55aa0 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 11 May 2021 08:34:49 +0800 Subject: [PATCH] =?utf8?q?=E5=88=87=E6=8D=A2=E6=88=BF=E9=97=B4flv=E6=B5=81?= =?utf8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 61 ++++++++++++++++++++++++------------- demo/config/config_K_v.json | 2 +- demo/go.mod | 2 +- demo/go.sum | 2 ++ go.mod | 2 +- go.sum | 2 ++ 6 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Reply/F.go b/Reply/F.go index dcbd5b3..2584f76 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -421,12 +421,6 @@ func Savestreamf(){ savestream.wait = s.Init() savestream.cancel = s.Init() - - rr := reqf.New() - go func(){ - savestream.cancel.Wait() - rr.Close() - }() CookieM := make(map[string]string) c.Cookie.Range(func(k,v interface{})(bool){ @@ -435,6 +429,11 @@ func Savestreamf(){ }) {//重试 + rr := reqf.New() + go func(){ + savestream.cancel.Wait() + rr.Close() + }() l.L(`I: `,"尝试连接live") if e := rr.Reqf(reqf.Rval{ Url:c.Live[0], @@ -653,7 +652,8 @@ func Savestreamf(){ out.Write(req.keyframe[i]) } // reqs_keyframe[0] = [][]byte{reqs_keyframe[0][len(reqs_keyframe[0])-1]} - } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 5 { + } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 3 { + l.L(`T: `,"flv强行拼合") // fmt.Println(`强行merge`) // reqs_remove_id = append(reqs_remove_id, reqs_used_id[0]) // last_time_stamp = int(F.Btoi32([]byte{reqs_keyframe[0][0][7], reqs_keyframe[0][0][4], reqs_keyframe[0][0][5], reqs_keyframe[0][0][6]},0)) @@ -674,7 +674,7 @@ func Savestreamf(){ savestream.flv_stream.Push_tag("stream",req.keyframe[i]) out.Write(req.keyframe[i]) } - } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 2 { + } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 1 { // fmt.Println(`merge 旧连接退出`) reqs_used_id[0].close() // reqs_used_id = reqs_used_id[1:] @@ -696,7 +696,8 @@ func Savestreamf(){ // } } } else { - fmt.Println(`merge成功`,len(b)) + // fmt.Println(`merge成功`,len(b)) + l.L(`T: `,"flv拼合成功") last_keyframe_timestamp = success_last_keyframe_timestamp @@ -718,6 +719,7 @@ func Savestreamf(){ }, // 11区 1 `close`:func(data interface{})(bool){ + // defer l.L(`I: `,"处理退出") reqs_used_id = []id_close{} // reqs_remove_id = []id_close{} reqs_keyframe = [][][]byte{} @@ -728,11 +730,11 @@ func Savestreamf(){ } //连接保持 - for savestream.cancel.Islive() { + for { //获取超时时间 link,exp,e := flv_get_link(c.Live[0]) if e != nil { - l.L(`E: `,e) + l.L(`W: `,e) break } @@ -744,8 +746,13 @@ func Savestreamf(){ //新建请求 go func(r *reqf.Req,rval reqf.Rval){ + go func(){ + savestream.cancel.Wait() + req.Close() + }() + if e := r.Reqf(rval);e != nil { - l.L(`E: `,e) + l.L(`W: `,e) return } }(req,reqf.Rval{ @@ -771,6 +778,7 @@ func Savestreamf(){ //解析 go func(http_error chan error,bc chan[]byte,item *link_stream){ + // defer l.L(`I: `,"解析退出") var ( buf []byte skip_buf_size int @@ -813,6 +821,11 @@ func Savestreamf(){ } // total := 0 + // var tmp_buf []byte + // { + // tmp_buf = make([]byte,len(buf)) + // copy(tmp_buf, buf) + // } item.keyframe = list // item.keyframe = make([][]byte,len(list)) // for i:=0;i%d 下一header %b\n",len(buf),len(buf)-cut_offset,buf[:11]) buf = buf[cut_offset:] } @@ -847,11 +860,14 @@ func Savestreamf(){ case e :=<- http_error: l.L(`W: `,`连接`,item.id.Id,e) } - if exit_sign {break} + if exit_sign { + //退出 + // l.L(`T: `,"chan退出") + break + } } l.L(`I: `,"flv过期,开始新连接") - // fmt.Println(`过期`) //即将过期,刷新c.Live F.Get(`Liveing`) @@ -948,7 +964,7 @@ func Savestreamf(){ links,file_add,exp,e := hls_get_link(c.Live[0],last_download) if e != nil && !reqf.IsTimeout(e) { - l.L(`E: `,e) + l.L(`W: `,e) break } @@ -1106,7 +1122,10 @@ func Savestreamf(){ //set ro `` savestream.path = `` - if !savestream.cancel.Islive() {break}//cancel + if !savestream.cancel.Islive() { + // l.L(`I: `,"退出") + break + }//cancel /* Savestream需要外部组件 ffmpeg http://ffmpeg.org/download.html @@ -1422,12 +1441,12 @@ func init() { lessdanmu.Lock() if ptk := lessdanmu.limit.PTK();ptk == lessdanmu.max_num { - if lessdanmu.threshold > 0.01 { - lessdanmu.threshold -= 0.01 + if lessdanmu.threshold > 0.03 { + lessdanmu.threshold -= 0.03 } } else if ptk == 0 { - if lessdanmu.threshold < 0.99 { - lessdanmu.threshold += 0.01 + if lessdanmu.threshold < 0.97 { + lessdanmu.threshold += 0.03 } } lessdanmu.Unlock() diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index fffeb66..9f324c7 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -55,7 +55,7 @@ "弹幕合并": true, "相似弹幕忽略": true, "每10秒显示弹幕数-help": "为0时禁用,相似弹幕忽略需设为true", - "每10秒显示弹幕数": 14, + "每10秒显示弹幕数": 10, "精简弹幕": true, "弹幕机": "", "反射弹幕机": true, diff --git a/demo/go.mod b/demo/go.mod index 1a50dda..aff7a82 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -14,7 +14,7 @@ require ( github.com/miekg/dns v1.1.41 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/qydysky/bili_danmu v0.5.8 - github.com/qydysky/part v0.5.13 // indirect + github.com/qydysky/part v0.5.14 // indirect github.com/shirou/gopsutil v3.21.4+incompatible // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect diff --git a/demo/go.sum b/demo/go.sum index dfbaf66..ffcf759 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -278,6 +278,8 @@ github.com/qydysky/part v0.5.12 h1:HnXJ7NmL5kvpFwPSpz5D5Kmg50mTblRP6tIufVsXP+U= github.com/qydysky/part v0.5.12/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part v0.5.13 h1:Y1SXoT5ZKCBURoP63G3iOx17kJKlXHpUVNE+oJVFp3o= github.com/qydysky/part v0.5.13/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.5.14 h1:jlroaks8tdBhV1CPIgdW9jtwtwMg4L9OSZH2WzsPfQg= +github.com/qydysky/part v0.5.14/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad h1:Jtzf509lQrkUMGTV0Sc6IDCAiR1VrBcHrIban7hpye4= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8= diff --git a/go.mod b/go.mod index 9a313a6..6a72931 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/mdp/qrterminal/v3 v3.0.0 github.com/miekg/dns v1.1.41 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect - github.com/qydysky/part v0.5.13 + github.com/qydysky/part v0.5.14 github.com/shirou/gopsutil v3.21.4+incompatible // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 diff --git a/go.sum b/go.sum index 524c3e9..f41ff90 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/qydysky/part v0.5.12 h1:HnXJ7NmL5kvpFwPSpz5D5Kmg50mTblRP6tIufVsXP+U= github.com/qydysky/part v0.5.12/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part v0.5.13 h1:Y1SXoT5ZKCBURoP63G3iOx17kJKlXHpUVNE+oJVFp3o= github.com/qydysky/part v0.5.13/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.5.14 h1:jlroaks8tdBhV1CPIgdW9jtwtwMg4L9OSZH2WzsPfQg= +github.com/qydysky/part v0.5.14/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg= github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -- 2.39.2