MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / extractWebmFirstFrame

Function extractWebmFirstFrame

xmsl/xmsl.ts:68–95  ·  view source on GitHub ↗

* 从 WebM 视频提取第一帧 PNG

(webmBuffer: Buffer)

Source from the content-addressed store, hash-verified

66
67/**
68 * 从 WebM 视频提取第一帧 PNG
69 */
70async function extractWebmFirstFrame(webmBuffer: Buffer): Promise<Buffer | null> {
71 const uniqueId = Date.now().toString() + '_' + Math.random().toString(36).slice(2);
72 const webmPath = path.join(XMSL_TEMP_DIR, `sticker_${uniqueId}.webm`);
73 const pngPath = path.join(XMSL_TEMP_DIR, `sticker_${uniqueId}.png`);
74
75 try {
76 fs.writeFileSync(webmPath, webmBuffer);
77
78 await execFileAsync('ffmpeg', [
79 '-i', webmPath,
80 '-vf', 'select=eq(n\\,0)',
81 '-vframes', '1',
82 '-y',
83 pngPath
84 ]);
85
86 if (fs.existsSync(pngPath)) {
87 return fs.readFileSync(pngPath);
88 }
89 return null;
90 } catch (error) {
91 console.error('[xmsl] WebM 第一帧提取失败:', error);
92 return null;
93 } finally {
94 try { fs.unlinkSync(webmPath); } catch {}
95 try { fs.unlinkSync(pngPath); } catch {}
96 }
97}
98

Callers 1

extractMediaInfoMethod · 0.85

Calls 2

execFileAsyncFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected