rc-plugin/utils/ffmpeg-util.js
zhiyu1998 a38ef04d27 feat:添加预览视频指令,视频关键帧提取功能
- 此提交引入了一项新功能,允许使用FFmpeg从视频中提取关键帧。
- `extractKeyframes` 函数已被添加到 `ffmpeg-util.js` 以处理提取过程。
- `tools.js` 文件已更新以包含新功能,使用户能够预览视频的关键帧。
- `readCurrentDir` 函数已从 `file.js` 导入,以读取关键帧目录的内容。
2024-09-02 22:36:45 +08:00

24 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
});
});
}