| 473 | |
| 474 | return filters; |
| 475 | } |
| 476 | |
| 477 | private buildFfmpegArgs( |
| 478 | inputPath: string, |
| 479 | outputPath: string, |
| 480 | filters: string[], |
| 481 | isGif: boolean, |
| 482 | isWebm: boolean |
| 483 | ): string[] { |
| 484 | const args = ['-y', '-i', inputPath]; |
| 485 | const filterChain = filters.join(','); |
| 486 | |
| 487 | // GIF 使用调色板优化保持质量 |
| 488 | if (isGif) { |
| 489 | const baseFilter = filterChain || 'null'; |
| 490 | const paletteGraph = `[0:v]${baseFilter}[flip];[flip]split[a][b];[a]palettegen=stats_mode=diff[p];[b][p]paletteuse=dither=bayer`; |
| 491 | args.push('-filter_complex', paletteGraph, '-loop', '0'); |
| 492 | } else if (filterChain) { |
| 493 | args.push('-vf', filterChain); |
| 494 | } |
| 495 | |
| 496 | // WebM 特殊编码参数(贴纸格式) |
| 497 | if (isWebm) { |
| 498 | args.push( |
| 499 | '-c:v', |
| 500 | 'libvpx-vp9', |
| 501 | '-pix_fmt', |
| 502 | 'yuva420p', |
| 503 | '-b:v', |
| 504 | '0', |
| 505 | '-crf', |
| 506 | '32', |
| 507 | '-auto-alt-ref', |
| 508 | '0' |
| 509 | ); |
| 510 | } |
| 511 | |
| 512 | args.push(outputPath); |
| 513 | return args; |
| 514 | } |
| 515 | |