rc-plugin/utils/ffmpeg-util.js
2025-09-10 22:19:21 +08:00

37 lines
1.3 KiB
JavaScript
Raw Permalink 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';
import fs from 'fs';
/**
* 使用 ffmpeg 将 FLV 文件转换为 MP4 文件
* @param {string} inputFilePath - 输入的 FLV 文件路径
* @param {string} outputFilePath - 输出的 MP4 文件路径
* @returns {Promise<string>} - 返回一个 Promise成功时返回输出文件路径失败时返回错误信息
*/
export function convertFlvToMp4(inputFilePath, outputFilePath) {
return new Promise((resolve, reject) => {
const resolvedInputPath = path.resolve(inputFilePath);
const resolvedOutputPath = path.resolve(outputFilePath);
// 检查文件是否存在
fs.access(resolvedInputPath, fs.constants.F_OK, (err) => {
if (err) {
reject(`[R插件][ffmpeg工具]输入文件不存在: ${resolvedInputPath}`);
return;
}
const command = `ffmpeg -y -i "${resolvedInputPath}" "${resolvedOutputPath}"`;
logger.info(`[R插件][ffmpeg工具]执行命令:${command}`);
// 执行 ffmpeg 转换
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`[R插件][ffmpeg工具]执行 ffmpeg 命令时出错: ${error.message}`);
return;
}
resolve(resolvedOutputPath);
});
});
});
}