mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00

- 此提交引入了一项新功能,允许使用FFmpeg从视频中提取关键帧。 - `extractKeyframes` 函数已被添加到 `ffmpeg-util.js` 以处理提取过程。 - `tools.js` 文件已更新以包含新功能,使用户能够预览视频的关键帧。 - `readCurrentDir` 函数已从 `file.js` 导入,以读取关键帧目录的内容。
24 lines
1.1 KiB
JavaScript
24 lines
1.1 KiB
JavaScript
import path from 'path';
|
||
import { exec } from 'child_process';
|
||
|
||
// 写一个执行ffmpeg提取视频关键帧的函数,例如:ffmpeg -i input.mp4 -vf "select=eq(pict_type\,I)" -vsync drop -vframes 5 -qscale:v 2 keyframes\keyframe_%03d.jpg
|
||
export async function extractKeyframes(inputFilePath, outputFolderPath, frameCount = 20) {
|
||
return new Promise((resolve, reject) => {
|
||
// 创建输出文件夹路径
|
||
const outputFilePattern = path.join(outputFolderPath, 'keyframe_%03d.jpg');
|
||
|
||
// 构建FFmpeg命令
|
||
const ffmpegCommand = `ffmpeg -i "${inputFilePath}" -vf "select=eq(pict_type\\,I)" -vsync drop -vframes ${frameCount} -qscale:v 2 "${outputFilePattern}"`;
|
||
|
||
// 执行FFmpeg命令
|
||
exec(ffmpegCommand, (error, stdout, stderr) => {
|
||
if (error) {
|
||
reject(`[R插件][ffmpeg工具]执行FFmpeg命令时出错: ${ stderr }`);
|
||
} else {
|
||
logger.info(`[R插件][ffmpeg工具]关键帧成功提取到 ${ outputFolderPath }`);
|
||
resolve(outputFolderPath);
|
||
}
|
||
});
|
||
});
|
||
}
|