From 95684ee6e5d533aaa3f451e80045421d5a3ac2a8 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 8 Jun 2021 16:46:35 +0800 Subject: [PATCH] =?utf8?q?ass=20=E9=BB=98=E8=AE=A4=E4=BD=BF=E7=94=A8gbk?= =?utf8?q?=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.md | 26 +++++++++++++----- Reply/F.go | 55 ++++++++++++++++++++++++++++--------- demo/config/config_K_v.json | 4 +-- demo/go.sum | 1 + 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 0725f79..d1d53b9 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,25 @@ golang go version go1.15 linux/amd64 ### 说明 本项目使用github action自动构建,构建过程详见[yml](https://github.com/qydysky/bili_danmu/blob/master/.github/workflows/go.yml) +#### 流保存以及弹幕ass +在`demo/config/config_K_v.json`中可找到配置项 + +```json +"直播流清晰度-help": "清晰度可选-1:不保存 0:默认 10000:原画 800:4K 401:蓝光(杜比) 400:蓝光 250:超清 150:高清 80:流畅,无提供所选清晰度时,使用低一档清晰度", +"直播流清晰度": 150, +"直播流类型-help": "flv or hls", +"直播流类型": "hls", +"直播流保存位置": "./live", +"ass-help": "只有保存直播流时才考虑生成ass,ass编码默认GB18030(可选utf-8)", +"生成Ass弹幕": true, +"Ass编码": "GB18030", +``` + +ass编码GB18030支持中文 + +- `GB18030`(默认) +- `utf-8` + #### 直播流Web服务 启动Web流服务,为下载的直播流提供局域网内的流服务。 @@ -422,13 +441,6 @@ I: 2021/02/18 14:40:54 Msg 礼 [SC: 加拉入我心 ¥ 30 关注了乙女音 I: 2021/02/18 21:48:49 Msg 房 [欢迎舰长 Mana_单推... 进入直播间] ``` -#### 流保存以及弹幕ass -``` -结束后会保存为 -房间号_时间.mkv -房间号_时间.ass -``` - #### 结束后的文件播放效果(显于左上) ![](_Screenshot/Screenshot_20200926_173834.png) diff --git a/Reply/F.go b/Reply/F.go index 8de2c9a..311116f 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -19,6 +19,8 @@ import ( "encoding/base64" // "runtime" + "golang.org/x/text/encoding/simplifiedchinese" + c "github.com/qydysky/bili_danmu/CV" F "github.com/qydysky/bili_danmu/F" send "github.com/qydysky/bili_danmu/Send" @@ -128,6 +130,7 @@ type Ass struct { file string//弹幕ass文件名 startT time.Time//开始记录的基准时间 header string//ass开头 + encoderS func(string)(string,error)//编码 } var ( @@ -154,6 +157,24 @@ Style: Default,,`+strconv.Itoa(Ass_font)+`,&H40FFFFFF,&H000017FF,&H80000000,&H40 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text `, +encoderS:simplifiedchinese.GB18030.NewEncoder().String, +} + +func init(){ + accept := map[string]bool{ + `GB18030`:true, + `utf-8`:true, + } + if v,ok := c.K_v.LoadV("Ass编码").(string);ok{ + if v1,ok := accept[v];ok && v1 { + c.Log.Base(`Ass`).L(`T: `,"编码:", v) + if v == `utf-8` { + ass.encoderS = func(b string)(string,error){ + return b,nil + } + } + } + } } //设定字幕文件名,为""时停止输出 @@ -168,13 +189,17 @@ func Ass_f(file string, st time.Time){ c.Log.Base(`Ass`).L(`W: `, err) } - p.File().FileWR(p.Filel{ - File:ass.file + ".ass", - Write:true, - Loc:0, - Context:[]interface{}{ass.header}, - }) - ass.startT = st + if tmp,err := ass.encoderS(ass.header);err != nil { + c.Log.Base(`Ass`).L(`W: `, err) + } else { + p.File().FileWR(p.Filel{ + File:ass.file + ".ass", + Write:true, + Loc:0, + Context:[]interface{}{tmp}, + }) + ass.startT = st + } } //传入要显示的单条字幕 @@ -193,12 +218,16 @@ func Assf(s string){ b += dtos(st) + `,` + dtos(et) b += `,Default,,0,0,0,,{\fad(200,500)\blur3}` + s + "\n" - p.File().FileWR(p.Filel{ - File:ass.file + ".ass", - Write:true, - Loc:-1, - Context:[]interface{}{b}, - }) + if tmp,err := ass.encoderS(b);err != nil { + c.Log.Base(`Ass`).L(`W: `, err) + } else { + p.File().FileWR(p.Filel{ + File:ass.file + ".ass", + Write:true, + Loc:-1, + Context:[]interface{}{tmp}, + }) + } } //时间转化为0:00:00.00规格字符串 diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index 042fa1b..daced4c 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -49,9 +49,9 @@ "直播流类型": "hls", "直播流保存位置": "./live", "直播流缓冲": 20, - "直播保存位置Web服务":0, - "ass-help": "只有保存直播流时才考虑生成ass", + "ass-help": "只有保存直播流时才考虑生成ass,ass编码默认GB18030(可选utf-8)", "生成Ass弹幕": true, + "Ass编码": "GB18030", "弹幕处理": "", "弹幕合并": true, "相似弹幕忽略": true, diff --git a/demo/go.sum b/demo/go.sum index 743cb91..0f85ea3 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -483,6 +483,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -- 2.39.2