| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-02-14 16:36:05 |
| 4 | * @LastEditTime: 2025-02-23 20:07:52 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: ffmpeg工具 |
| 7 | */ |
| 8 | import ffmpeg from 'fluent-ffmpeg'; // 一个封装了 ffmpeg API 的库,当然可以选择不安装,直接使用字符串拼接的方式调用 |
| 9 | import os from 'os'; |
| 10 | import { app } from 'electron'; |
| 11 | import path from 'path'; |
| 12 | import { fileURLToPath } from 'node:url'; |
| 13 | |
| 14 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 15 | |
| 16 | const platform = os.platform(); |
| 17 | const arch = os.arch(); |
| 18 | |
| 19 | // 获取ffmpeg二进制文件的路径,不同平台不一样 |
| 20 | function setFFmpegPath() { |
| 21 | const ffPath = app.isPackaged |
| 22 | ? path.join(process.resourcesPath, 'bin') |
| 23 | : path.join(__dirname, `../../scripts/file/ff/${platform}/${arch}`); |
| 24 | |
| 25 | ffmpeg.setFfprobePath( |
| 26 | path.join(ffPath, `ffprobe${platform === 'win32' ? '.exe' : ''}`), |
| 27 | ); |
| 28 | ffmpeg.setFfmpegPath( |
| 29 | path.join(ffPath, `ffmpeg${platform === 'win32' ? '.exe' : ''}`), |
| 30 | ); |
| 31 | } |
| 32 | setFFmpegPath(); |
| 33 | |
| 34 | export default class FFmpeg { |
| 35 | ffmpeg: ffmpeg.FfmpegCommand; |
| 36 | |
| 37 | constructor(inputPath: string) { |
| 38 | this.ffmpeg = ffmpeg(inputPath); |
| 39 | } |
| 40 | } |
| 41 |