Closed LuCa-0 closed 3 years ago
I did some tests and seems like it happens when the converted .gif is more than 3Mb. Maybe the base64 conversion has issues? Actually just tried and it works with a 3.9Mb gif, I don't know...
Thank you in advance
Why did you close this? It's still an issue...
Hi LuCa-0!
I had the same issue yesterday. With some debugging I found out it only happens when you try to convert a large video. Small videos to animated stickers are no problem. Is this the same for you? I think the issue is that the base64 conversion only can handle files op to a certain file size.
Anyway, I fixed it by adding some try/catches. So when the program can't convert it to a sticker it tries it again with less FPS. The code isn't very clean, but at least it works ;)
if (isMedia) {
const meta = {
author: '[YOUR NAME HERE]',
pack: '[STICKERPACK NAME HERE]',
keepScale: true
};
if (mimetype === 'video/mp4' && message.duration < 10 || mimetype === 'image/gif' && message.duration < 10) {
const mediaData = await decryptMedia(message, uaOverride)
client.reply(from, 'wait a sec, your video is being converted', id)
const filename = `./media/aswu.${mimetype.split('/')[1]}`
await fs.writeFileSync(filename, mediaData)
await exec(`gify ${filename} ./media/output.gif --fps=30 --scale=240:240`, async function (error, stdout, stderr) {
try {
const gif = await fs.readFileSync('./media/output.gif', { encoding: "base64" })
await client.sendImageAsSticker(from, `data:image/gif;base64,${gif.toString('base64')}`, meta)
console.log('30FPS')
} catch {
await exec(`gify ${filename} ./media/output.gif --fps=15 --scale=240:240`, async function (error, stdout, stderr) {
try {
const gif = await fs.readFileSync('./media/output.gif', { encoding: "base64" })
await client.sendImageAsSticker(from, `data:image/gif;base64,${gif.toString('base64')}`)
console.log('15FPS')
} catch {
await exec(`gify ${filename} ./media/output.gif --fps=5 --scale=240:240`, async function (error, stdout, stderr) {
try {
const gif = await fs.readFileSync('./media/output.gif', {encoding: "base64"})
await client.sendImageAsSticker(from, `data:image/gif;base64,${gif.toString('base64')}`)
console.log('5FPS')
} catch {
client.reply(from, 'file is too big, can't convert it :(', id)
}
})
}
})
}
})
} else (
client.reply(from, 'max duration of a video or GIF is 10 seconds' , id)
)
}
Hi! Awesome project! I really love it. Sadly sometimes when i try to convert a video to animated sticker i get the following error:
Any idea on how to solve this?