From b10088e496ccca7791952b29df615c27cee443bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=8F=B6?= <1936472877@qq.com> Date: Tue, 7 Jan 2025 11:19:49 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=8F=AF=E9=80=89=E4=BD=BF=E7=94=A8can?= =?UTF-8?q?vas=E5=90=88=E6=88=90gif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/default_config/gif.yaml | 8 ++++++-- models/canvas/info.js | 3 ++- models/info/gif.js | 5 +++-- models/setting/index.js | 4 ++-- models/task/index.js | 3 +++ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/config/default_config/gif.yaml b/config/default_config/gif.yaml index 5157ec6..ef1524b 100644 --- a/config/default_config/gif.yaml +++ b/config/default_config/gif.yaml @@ -2,9 +2,10 @@ # 由puppeteer截图多张图片通过ffmpeg生成gif # 需要有全局安装ffmpeg -# 转换成gif的模式 -# 1: 使用puppeteer多次截图 +# 转换成gif的模式 +# 1: 使用puppeteer多次截图 # 2: 使用puppeteer-screen-recorder录制视频 +# 3: 使用canvas多次生成图片 不会使用下面的配置项 gifMode: 1 # 帧率 @@ -20,3 +21,6 @@ videoLimit: 3 # steam状态 迷你背景图 头像框 头像 infoGif: false + +# 仅用于更新注释捏 +gifDoc: 1 diff --git a/models/canvas/info.js b/models/canvas/info.js index aae9655..4cfc875 100644 --- a/models/canvas/info.js +++ b/models/canvas/info.js @@ -210,7 +210,8 @@ export async function render (data) { setTimeout(() => { fs.rmSync(data.tempPath, { recursive: true }) }, 1000 * 60 * 5) - return segment.image(`file://${output}`) + const base64 = fs.readFileSync(output, { encoding: 'base64' }) + return segment.image(`base64://${base64}`) } else { await draw(data.avatar, data.frame, data.background) return toImage(canvas) diff --git a/models/info/gif.js b/models/info/gif.js index c363e31..38f161b 100644 --- a/models/info/gif.js +++ b/models/info/gif.js @@ -18,7 +18,7 @@ export async function render (data) { fs.rmSync(tempPath, { force: true, recursive: true }) } fs.mkdirSync(tempPath, { recursive: true }) - if (Config.other.renderType == 2) { + if (Config.gif.gifMode == 3) { data.tempPath = tempPath return await canvas.info.render(data) } else { @@ -87,6 +87,7 @@ export async function render (data) { setTimeout(() => { fs.rmSync(tempPath, { force: true, recursive: true }) }, 1000 * 60 * 5) // 5分钟后删除 - return segment.image(`file://${output}`) + const base64 = fs.readFileSync(output, { encoding: 'base64' }) + return segment.image(`base64://${base64}`) } } diff --git a/models/setting/index.js b/models/setting/index.js index 699d01b..215ddb5 100644 --- a/models/setting/index.js +++ b/models/setting/index.js @@ -348,7 +348,7 @@ export const cfgSchema = { min: 1, max: 2, input: (n) => { - if (n >= 1 && n <= 2) { + if (n >= 1 && n <= 3) { return n * 1 } else { return 1 @@ -359,7 +359,7 @@ export const cfgSchema = { { label: '截图合成', value: 1 }, { label: '视频合成', value: 2 } ], - desc: '1: 多张截图合成一张gif 2: 视频转换gif' + desc: '1: 多张截图合成一张gif 2: 视频转换gif 3: canvas多次截图(不会使用下面的配置)' }, frameRate: { title: 'gif帧率', diff --git a/models/task/index.js b/models/task/index.js index 549d20f..dc406f7 100644 --- a/models/task/index.js +++ b/models/task/index.js @@ -97,6 +97,9 @@ export function startTimer () { } // 在线状态改变 if (Config.push.stateChange && player.personastate != lastPlay.state) { + if (![0, 1].includes(lastPlay.state)) { + continue + } const time = now - lastPlay.onlineTime if (Config.push.stateOffline && player.personastate === 0) { db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, player.gameid, player.gameextrainfo, 'onlineTime', time).catch(e => logger.error('更新统计数据失败', e.message))