Skip to content

Commit

Permalink
perf: 可选使用canvas合成gif
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Jan 7, 2025
1 parent 4bd361c commit b10088e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions config/default_config/gif.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# 由puppeteer截图多张图片通过ffmpeg生成gif
# 需要有全局安装ffmpeg

# 转换成gif的模式
# 1: 使用puppeteer多次截图
# 转换成gif的模式
# 1: 使用puppeteer多次截图
# 2: 使用puppeteer-screen-recorder录制视频
# 3: 使用canvas多次生成图片 不会使用下面的配置项
gifMode: 1

# 帧率
Expand All @@ -20,3 +21,6 @@ videoLimit: 3

# steam状态 迷你背景图 头像框 头像
infoGif: false

# 仅用于更新注释捏
gifDoc: 1
3 changes: 2 additions & 1 deletion models/canvas/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions models/info/gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}`)
}
}
4 changes: 2 additions & 2 deletions models/setting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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帧率',
Expand Down
3 changes: 3 additions & 0 deletions models/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b10088e

Please sign in to comment.