(options: TransformOptions)
| 426 | } |
| 427 | |
| 428 | // ==================== FFmpeg 转换 ==================== |
| 429 | |
| 430 | private async runFfmpegTransform(options: TransformOptions): Promise<void> { |
| 431 | const { inputPath, outputPath, flipMode, invertColors, isGif, isWebm } = |
| 432 | options; |
| 433 | |
| 434 | const filters = this.buildVideoFilters(flipMode, invertColors); |
| 435 | const args = this.buildFfmpegArgs( |
| 436 | inputPath, |
| 437 | outputPath, |
| 438 | filters, |
| 439 | isGif, |
| 440 | isWebm |
| 441 | ); |
| 442 | |
| 443 | try { |
| 444 | await execFileAsync('ffmpeg', args); |
| 445 | } catch (error: any) { |
| 446 | if (error?.code === 'ENOENT') { |
| 447 | throw new Error('未找到 ffmpeg,请先安装后再试'); |
| 448 | } |
| 449 | const stderr = |
| 450 | typeof error?.stderr === 'string' ? error.stderr.trim() : ''; |
| 451 | if (stderr) { |
| 452 | throw new Error(`ffmpeg 处理失败: ${stderr.split('\n')[0]}`); |
| 453 | } |
| 454 | throw new Error(`ffmpeg 处理失败: ${error?.message || String(error)}`); |
| 455 | } |
| 456 | } |
| 457 |
no test coverage detected