@ffmpeg-oneclick/core 0.1.2

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 ADDED
@@ -0,0 +1,208 @@
1
+ # @ffmpeg-oneclick/core
2
+
3
+ > 一键式 FFmpeg Node.js 库 - 简单、快速、完整
4
+
5
+ ## 特性
6
+
7
+ - ✅ **链式 API** - 流畅的链式调用,一行代码完成复杂操作
8
+ - ✅ **TypeScript 原生** - 完整的类型支持和智能提示
9
+ - ✅ **Promise + EventEmitter** - 灵活的异步处理方式
10
+ - ✅ **自动下载 FFmpeg** - 零配置,开箱即用
11
+ - ✅ **进度追踪** - 实时进度、ETA、详细统计
12
+ - ✅ **硬件加速** - 自动检测和使用硬件加速
13
+ - ✅ **流式处理** - 支持 Buffer 和 Stream 输入输出
14
+ - ✅ **完整功能** - 覆盖 FFmpeg 所有原生功能
15
+
16
+ ## 安装
17
+
18
+ ```bash
19
+ npm install @ffmpeg-oneclick/core @ffmpeg-oneclick/bin
20
+ ```
21
+
22
+ ## 快速开始
23
+
24
+ ### 基础用法
25
+
26
+ ```typescript
27
+ import { ffmpeg } from '@ffmpeg-oneclick/core';
28
+
29
+ // 简单转换
30
+ await ffmpeg('input.mp4')
31
+ .output('output.webm')
32
+ .run();
33
+ ```
34
+
35
+ ### 设置视频参数
36
+
37
+ ```typescript
38
+ await ffmpeg('input.mp4')
39
+ .output('output.mp4')
40
+ .size('720p') // 分辨率
41
+ .fps(30) // 帧率
42
+ .videoBitrate('1M') // 视频比特率
43
+ .audioBitrate('128k') // 音频比特率
44
+ .videoCodec('libx264') // 视频编码器
45
+ .audioCodec('aac') // 音频编码器
46
+ .run();
47
+ ```
48
+
49
+ ### 进度监听
50
+
51
+ ```typescript
52
+ await ffmpeg('input.mp4')
53
+ .output('output.mp4')
54
+ .on('progress', (progress) => {
55
+ console.log(`进度: ${progress.percent.toFixed(1)}%`);
56
+ console.log(`预计剩余时间: ${progress.eta}秒`);
57
+ console.log(`当前帧数: ${progress.frames}`);
58
+ console.log(`编码速度: ${progress.fps} fps`);
59
+ })
60
+ .on('end', (result) => {
61
+ console.log(`完成!输出文件: ${result.output}`);
62
+ console.log(`文件大小: ${result.size} 字节`);
63
+ console.log(`处理时长: ${result.duration} 毫秒`);
64
+ })
65
+ .on('error', (error) => {
66
+ console.error(`错误: ${error.message}`);
67
+ console.error(`建议: ${error.suggestion}`);
68
+ })
69
+ .run();
70
+ ```
71
+
72
+ ### 视频裁剪
73
+
74
+ ```typescript
75
+ // 裁剪 5-15 秒的片段
76
+ await ffmpeg('input.mp4')
77
+ .output('clip.mp4')
78
+ .trim(5, 15)
79
+ .run();
80
+ ```
81
+
82
+ ### 视频滤镜
83
+
84
+ ```typescript
85
+ await ffmpeg('input.mp4')
86
+ .output('output.mp4')
87
+ .videoFilters({
88
+ scale: { width: 1920, height: 1080 },
89
+ crop: { x: 0, y: 0, width: 1920, height: 800 },
90
+ brightness: 0.1,
91
+ contrast: 0.2,
92
+ })
93
+ .run();
94
+ ```
95
+
96
+ ### 硬件加速
97
+
98
+ ```typescript
99
+ await ffmpeg('input.mp4')
100
+ .output('output.mp4')
101
+ .hardwareAccelerate('auto') // 自动检测最佳硬件加速
102
+ .run();
103
+ ```
104
+
105
+ ### 获取视频元数据
106
+
107
+ ```typescript
108
+ import { getMetadata } from '@ffmpeg-oneclick/core';
109
+
110
+ const metadata = await getMetadata('video.mp4');
111
+
112
+ console.log(`时长: ${metadata.duration}秒`);
113
+ console.log(`分辨率: ${metadata.width}x${metadata.height}`);
114
+ console.log(`帧率: ${metadata.fps} fps`);
115
+ console.log(`视频编码: ${metadata.videoCodec}`);
116
+ console.log(`音频编码: ${metadata.audioCodec}`);
117
+ ```
118
+
119
+ ### 流式处理
120
+
121
+ ```typescript
122
+ import { createReadStream, createWriteStream } from 'fs';
123
+
124
+ // 从流读取
125
+ await ffmpeg(createReadStream('input.mp4'))
126
+ .output('output.mp4')
127
+ .run();
128
+
129
+ // 输出到流
130
+ await ffmpeg('input.mp4')
131
+ .output(createWriteStream('output.mp4'))
132
+ .run();
133
+ ```
134
+
135
+ ## API 文档
136
+
137
+ ### `ffmpeg(input?, options?)`
138
+
139
+ 创建 FFmpeg 实例。
140
+
141
+ - `input`: 输入文件路径、Buffer 或 Stream(可选)
142
+ - `options`: 配置选项
143
+ - `ffmpegPath`: FFmpeg 可执行文件路径
144
+ - `ffprobePath`: FFprobe 可执行文件路径
145
+ - `hardwareAcceleration`: 硬件加速模式
146
+ - `threads`: 线程数
147
+ - `timeout`: 超时时间(毫秒)
148
+
149
+ ### 链式方法
150
+
151
+ #### 输入输出
152
+ - `.input(input)` - 设置输入
153
+ - `.output(output)` - 设置输出
154
+
155
+ #### 视频参数
156
+ - `.videoCodec(codec)` - 视频编码器
157
+ - `.videoBitrate(bitrate)` - 视频比特率
158
+ - `.fps(fps)` - 帧率
159
+ - `.size(size)` - 分辨率('720p', '1080p', '4k' 或 `{width, height}`)
160
+
161
+ #### 音频参数
162
+ - `.audioCodec(codec)` - 音频编码器
163
+ - `.audioBitrate(bitrate)` - 音频比特率
164
+
165
+ #### 时间控制
166
+ - `.startTime(seconds)` - 起始时间
167
+ - `.duration(seconds)` - 持续时间
168
+ - `.trim(start, end)` - 裁剪片段
169
+
170
+ #### 滤镜
171
+ - `.videoFilters(options)` - 视频滤镜
172
+ - `.audioFilters(options)` - 音频滤镜
173
+
174
+ #### 元数据
175
+ - `.metadata(key, value)` - 添加元数据
176
+ - `.noMetadata()` - 移除所有元数据
177
+
178
+ #### 性能
179
+ - `.hardwareAccelerate(type)` - 硬件加速
180
+ - `.threads(count)` - 线程数
181
+
182
+ #### 事件
183
+ - `.on('start', callback)` - 开始执行
184
+ - `.on('progress', callback)` - 进度更新
185
+ - `.on('end', callback)` - 执行完成
186
+ - `.on('error', callback)` - 执行错误
187
+
188
+ #### 执行
189
+ - `.run()` - 执行命令
190
+ - `.kill()` - 终止执行
191
+ - `.getCommand()` - 获取命令字符串(调试用)
192
+
193
+ ## 开发
194
+
195
+ ```bash
196
+ # 安装依赖
197
+ pnpm install
198
+
199
+ # 运行测试
200
+ pnpm test
201
+
202
+ # 构建
203
+ pnpm build
204
+ ```
205
+
206
+ ## 许可证
207
+
208
+ GPL-3.0