@evio/ffai 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -92,6 +92,7 @@ ffai build task.json
92
92
  | `narration` | `string` | ✅ | 字幕文件路径,使用自定义时间格式 |
93
93
  | `videoTranscodeable` | `boolean` | ❌ | 是否对视频进行转码,默认 `false`。启用后会将所有视频统一转码为 H.264/AAC 格式 |
94
94
  | `videoPackMode` | `'random' \| 'all'` | ❌ | 视频打包模式,默认 `'all'`<br>- `random`: 根据音频时长随机选择视频片段<br>- `all`: 使用所有视频文件 |
95
+ | `fontFile` | `string` | ❌ | 自定义字幕字体文件路径。如果不指定,macOS 默认使用宋体,其他系统需要提供字体路径 |
95
96
 
96
97
  ### 字幕文件格式
97
98
 
@@ -115,7 +116,12 @@ ffai build task.json
115
116
  - 字体颜色:白色
116
117
  - 文字效果:黑色描边 + 阴影,确保在任何背景下清晰可见
117
118
  - 位置:视频底部居中(距底部 300px)
118
- - 字体:macOS 使用宋体,其他系统需在 `src/task.ts` 中修改 `fontfile` 变量
119
+ - 字体:可通过 `fontFile` 参数自定义,如果不指定则使用系统默认字体
120
+
121
+ **跨平台字体路径参考:**
122
+ - **macOS**: `/System/Library/Fonts/Supplemental/Songti.ttc`(宋体)
123
+ - **Windows**: `C:/Windows/Fonts/simhei.ttf`(黑体)或 `C:/Windows/Fonts/msyh.ttc`(微软雅黑)
124
+ - **Linux**: `/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc`(文泉驿正黑)
119
125
 
120
126
  ## 🔄 工作流程
121
127
 
@@ -178,12 +184,13 @@ task-0/
178
184
  - 从 `clips/` 目录随机选择视频片段,直到总时长匹配音频
179
185
  - 转码所有视频为统一格式(H.264/AAC)
180
186
  - 添加字幕并输出到 `task-0/video.mp4`
187
+ - 使用系统默认字体
181
188
 
182
189
  **适用场景:** 制作短视频、Vlog、产品宣传片等需要随机素材组合的场景
183
190
 
184
191
  ---
185
192
 
186
- ### 示例 2:使用所有视频 + Glob 模式
193
+ ### 示例 2:使用所有视频 + 自定义字体
187
194
 
188
195
  ```json
189
196
  [
@@ -191,7 +198,8 @@ task-0/
191
198
  "audios": "audio/*.mp3",
192
199
  "videos": ["intro.mp4", "content.mp4", "outro.mp4"],
193
200
  "narration": "subtitle.txt",
194
- "videoPackMode": "all"
201
+ "videoPackMode": "all",
202
+ "fontFile": "/path/to/your/font.ttf"
195
203
  }
196
204
  ]
197
205
  ```
@@ -200,6 +208,7 @@ task-0/
200
208
  - 混合 `audio/` 目录下的所有 MP3 文件
201
209
  - 按顺序拼接三个视频文件(片头 + 内容 + 片尾)
202
210
  - 不进行视频转码(使用原始格式,需确保格式一致)
211
+ - 使用自定义字体文件渲染字幕
203
212
  - 添加字幕并输出到 `task-0/video.mp4`
204
213
 
205
214
  **适用场景:** 固定结构的视频制作,如教程视频、演讲录制等
@@ -220,7 +229,8 @@ task-0/
220
229
  "audios": "task2/audio.mp3",
221
230
  "videos": "task2/videos/*.mp4",
222
231
  "narration": "task2/subtitle.txt",
223
- "videoPackMode": "all"
232
+ "videoPackMode": "all",
233
+ "fontFile": "C:/Windows/Fonts/msyh.ttc"
224
234
  },
225
235
  {
226
236
  "audios": ["task3/bgm1.mp3", "task3/bgm2.mp3"],
@@ -235,6 +245,7 @@ task-0/
235
245
  **这个配置会:**
236
246
  - 依次处理三个独立任务
237
247
  - 每个任务输出到对应的 `task-0/`、`task-1/`、`task-2/` 目录
248
+ - 第二个任务使用 Windows 微软雅黑字体
238
249
  - 支持不同的配置组合
239
250
 
240
251
  **适用场景:** 批量生产系列视频、多语言版本视频等
@@ -264,6 +275,30 @@ task-0/
264
275
 
265
276
  **适用场景:** 旅游 Vlog、纪录片、风景视频等需要旁白 + 背景音乐的场景
266
277
 
278
+ ---
279
+
280
+ ### 示例 5:跨平台字体配置
281
+
282
+ ```json
283
+ [
284
+ {
285
+ "audios": "audio.mp3",
286
+ "videos": "videos/*.mp4",
287
+ "narration": "subtitle.txt",
288
+ "fontFile": "/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc"
289
+ }
290
+ ]
291
+ ```
292
+
293
+ **这个配置会:**
294
+ - 在 Linux 系统上使用文泉驿正黑字体
295
+ - 确保中文字幕正确显示
296
+
297
+ **跨平台字体路径:**
298
+ - macOS: `/System/Library/Fonts/Supplemental/Songti.ttc`
299
+ - Windows: `C:/Windows/Fonts/simhei.ttf` 或 `C:/Windows/Fonts/msyh.ttc`
300
+ - Linux: `/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc`(需先安装:`sudo apt install fonts-wqy-zenhei`)
301
+
267
302
  ## 🛠️ 开发
268
303
 
269
304
  ```bash
@@ -442,7 +477,10 @@ if (!available) {
442
477
  ## ⚠️ 注意事项
443
478
 
444
479
  1. **FFmpeg 必须安装** - 工具依赖 FFmpeg,请确保已正确安装并配置到环境变量
445
- 2. **字幕字体路径** - macOS 默认使用宋体(`/System/Library/Fonts/Supplemental/Songti.ttc`),其他系统需要在 `src/task.ts` 中修改 `fontfile` 变量
480
+ 2. **字幕字体配置** - 可通过 `fontFile` 参数自定义字体路径,支持跨平台配置:
481
+ - macOS: `/System/Library/Fonts/Supplemental/Songti.ttc`
482
+ - Windows: `C:/Windows/Fonts/simhei.ttf` 或 `C:/Windows/Fonts/msyh.ttc`
483
+ - Linux: `/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc`
446
484
  3. **视频格式统一** - 强烈建议启用 `videoTranscodeable` 以确保所有视频格式统一,避免拼接时出现黑屏、卡顿或音画不同步
447
485
  4. **文件路径规则** - 所有路径都相对于执行命令的当前目录(`process.cwd()`)
448
486
  5. **临时文件清理** - 处理完成后会自动清理中间过程文件(`video_concat.mp4`、`video_concat_audio.mp4`、`videofiles.txt`),仅保留最终成品
@@ -486,12 +524,18 @@ if (!available) {
486
524
  - 字幕文本不要过长,建议每行不超过 20 个汉字
487
525
  - 预留字幕间隔时间,避免连续出现
488
526
 
489
- 5. **性能优化**
527
+ 5. **字体文件配置**
528
+ - 在配置文件中使用 `fontFile` 参数指定字体路径
529
+ - 确保字体文件存在且可读
530
+ - 使用支持中文的字体文件
531
+ - 不同操作系统使用对应的字体路径
532
+
533
+ 6. **性能优化**
490
534
  - 如果不需要转码,关闭 `videoTranscodeable` 可以大幅提升速度
491
535
  - 批量任务建议分批处理,避免一次处理过多任务
492
536
  - 使用 SSD 硬盘可以显著提升处理速度
493
537
 
494
- 6. **质量控制**
538
+ 7. **质量控制**
495
539
  - 处理完成后检查输出视频的音画同步
496
540
  - 验证字幕显示时间和内容是否正确
497
541
  - 检查音频混音效果,确保旁白清晰可听
@@ -516,10 +560,11 @@ A: FFmpeg 的 `amix` 滤镜会自动调整音量。如需手动控制,可以
516
560
 
517
561
  **Q: 字幕字体显示异常或乱码**
518
562
  A:
519
- - macOS 默认使用宋体,路径为 `/System/Library/Fonts/Supplemental/Songti.ttc`
520
- - Windows 可以使用 `C:/Windows/Fonts/simhei.ttf`(黑体)
521
- - Linux 需要安装中文字体,如 `sudo apt install fonts-wqy-zenhei`
522
- - 修改 `src/task.ts` 中的 `fontfile` 变量指向正确的字体文件
563
+ - 使用 `fontFile` 参数指定正确的字体文件路径
564
+ - macOS 可以使用 `/System/Library/Fonts/Supplemental/Songti.ttc`(宋体)
565
+ - Windows 可以使用 `C:/Windows/Fonts/simhei.ttf`(黑体)或 `C:/Windows/Fonts/msyh.ttc`(微软雅黑)
566
+ - Linux 需要安装中文字体,如 `sudo apt install fonts-wqy-zenhei`,然后使用 `/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc`
567
+ - 确保字体文件支持中文字符
523
568
 
524
569
  **Q: 任务配置文件必须是 .json 后缀吗?**
525
570
  A: 是的,工具会检查文件扩展名,必须使用 `.json` 后缀。
@@ -4,4 +4,5 @@ export interface TaskProps {
4
4
  narration: string;
5
5
  videoTranscodeable?: boolean;
6
6
  videoPackMode?: 'random' | 'all';
7
+ fontFile?: string;
7
8
  }
package/dist/task.js CHANGED
@@ -6,7 +6,6 @@ const glob_1 = require("glob");
6
6
  const node_fs_1 = require("node:fs");
7
7
  const signale_1 = require("signale");
8
8
  const lib_1 = require("./lib");
9
- const fontfile = '/System/Library/Fonts/Supplemental/Songti.ttc';
10
9
  async function RunTask(props, index, total) {
11
10
  const cmd = new signale_1.Signale({
12
11
  interactive: true,
@@ -46,7 +45,7 @@ async function RunTask(props, index, total) {
46
45
  cmd.await(`[%d/7] - 正在添加背景音频...`, 5);
47
46
  await (0, lib_1.addBackgroundAudio)(output_concat, output_concat_audio, audioData.file);
48
47
  cmd.await(`[%d/7] - 正在添加旁白...`, 6);
49
- await (0, lib_1.addSubTitles)(output_concat_audio, output_concat_audio_subtitle, narrationFile, fontfile);
48
+ await (0, lib_1.addSubTitles)(output_concat_audio, output_concat_audio_subtitle, narrationFile, props.fontFile);
50
49
  // 清理
51
50
  (0, node_fs_1.unlinkSync)((0, node_path_1.resolve)(videoTmpDir, 'videofiles.txt'));
52
51
  (0, node_fs_1.rmdirSync)(videoTmpDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evio/ffai",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "一个基于 FFmpeg 的命令行工具,用于批量处理视频和音频文件,支持视频转码、音频合并、字幕添加等功能。",
5
5
  "main": "dist/lib.js",
6
6
  "scripts": {
@@ -30,7 +30,6 @@
30
30
  "@types/fs-extra": "^11.0.4",
31
31
  "@types/node": "^22.0.0",
32
32
  "@types/signale": "^1.4.7",
33
- "dayjs": "1.11.19",
34
33
  "fix-esm-import-path": "^1.10.1",
35
34
  "glob": "^13.0.0",
36
35
  "ts-node": "^10.9.2",