@deepfish-ai/ffmpeg7-media-tools 1.0.0
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 +299 -0
- package/ffmpeg-descriptions.js +679 -0
- package/ffmpeg-functions.js +987 -0
- package/index.js +13 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# @deepfish-ai/ffmpeg7-media-tools
|
|
2
|
+
|
|
3
|
+
基于FFmpeg 7的音频视频处理工具函数集,包含23个媒体处理函数,支持视频格式转换、音频提取、视频编辑等常见媒体处理任务。
|
|
4
|
+
|
|
5
|
+
## ✨ 特性
|
|
6
|
+
|
|
7
|
+
- **全面覆盖**: 23个精心设计的FFmpeg函数,覆盖常见媒体处理需求
|
|
8
|
+
- **易于使用**: 统一的参数格式,清晰的错误处理
|
|
9
|
+
- **AI友好**: 包含完整的AI智能体描述信息
|
|
10
|
+
- **跨平台**: 支持Windows、macOS和Linux系统
|
|
11
|
+
- **TypeScript友好**: 完整的JSDoc注释和类型提示
|
|
12
|
+
|
|
13
|
+
## 📦 安装
|
|
14
|
+
|
|
15
|
+
### 前提条件
|
|
16
|
+
|
|
17
|
+
需要先安装FFmpeg 7或更高版本:
|
|
18
|
+
|
|
19
|
+
#### Windows
|
|
20
|
+
1. 下载FFmpeg 7:https://ffmpeg.org/download.html(选择包含版本7的构建)
|
|
21
|
+
2. 解压并添加到系统PATH环境变量
|
|
22
|
+
3. 验证安装:`ffmpeg -version`
|
|
23
|
+
|
|
24
|
+
#### macOS
|
|
25
|
+
```bash
|
|
26
|
+
# 使用Homebrew安装FFmpeg 7
|
|
27
|
+
brew install ffmpeg@7
|
|
28
|
+
|
|
29
|
+
# 如果找不到ffmpeg@7,可以先更新Homebrew再尝试
|
|
30
|
+
brew update
|
|
31
|
+
brew install ffmpeg@7
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
或者安装最新版本(可能包含FFmpeg 7):
|
|
35
|
+
```bash
|
|
36
|
+
brew install ffmpeg
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Linux (Ubuntu/Debian)
|
|
40
|
+
**方法一:使用官方静态构建(推荐)**
|
|
41
|
+
```bash
|
|
42
|
+
# 下载最新FFmpeg 7静态构建
|
|
43
|
+
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
|
|
44
|
+
# 解压
|
|
45
|
+
tar xf ffmpeg-release-amd64-static.tar.xz
|
|
46
|
+
# 进入解压目录
|
|
47
|
+
cd ffmpeg-*-amd64-static
|
|
48
|
+
# 复制二进制文件到系统路径
|
|
49
|
+
sudo cp ffmpeg ffprobe /usr/local/bin/
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**方法二:使用PPA安装(适用于Ubuntu 22.04+)**
|
|
53
|
+
```bash
|
|
54
|
+
# 添加PPA
|
|
55
|
+
sudo add-apt-repository ppa:jonathonf/ffmpeg-7
|
|
56
|
+
sudo apt update
|
|
57
|
+
sudo apt install ffmpeg
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**方法三:使用系统仓库(版本可能较旧)**
|
|
61
|
+
```bash
|
|
62
|
+
sudo apt update
|
|
63
|
+
sudo apt install ffmpeg
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### 验证安装
|
|
68
|
+
安装完成后,请验证FFmpeg版本是否为7.0或更高:
|
|
69
|
+
```bash
|
|
70
|
+
ffmpeg -version | head -n 1
|
|
71
|
+
```
|
|
72
|
+
应该输出类似:`ffmpeg version 7.0.1 Copyright (c) 2000-2024...`
|
|
73
|
+
|
|
74
|
+
如果版本低于7.0,请参考上述安装方法重新安装FFmpeg 7。
|
|
75
|
+
|
|
76
|
+
### 安装包
|
|
77
|
+
```bash
|
|
78
|
+
npm install @deepfish-ai/ffmpeg7-media-tools
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 🚀 快速开始
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
const { functions } = require('@deepfish-ai/ffmpeg7-media-tools');
|
|
85
|
+
|
|
86
|
+
// 1. 检查FFmpeg安装
|
|
87
|
+
const checkResult = await functions.ffmpeg_checkFfmpegInstallation({
|
|
88
|
+
minVersion: '7.0.0'
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// 2. 转换视频格式
|
|
92
|
+
const convertResult = await functions.ffmpeg_convertVideoFormat({
|
|
93
|
+
inputPath: '/path/to/input.avi',
|
|
94
|
+
outputPath: '/path/to/output.mp4',
|
|
95
|
+
format: 'mp4',
|
|
96
|
+
quality: '-crf 23'
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 3. 从视频中提取音频
|
|
100
|
+
const audioResult = await functions.ffmpeg_extractAudioFromVideo({
|
|
101
|
+
videoPath: '/path/to/video.mp4',
|
|
102
|
+
audioPath: '/path/to/audio.mp3',
|
|
103
|
+
audioFormat: 'mp3'
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 📋 API参考
|
|
108
|
+
|
|
109
|
+
### 安装检测 (1个)
|
|
110
|
+
|
|
111
|
+
| 函数名 | 描述 | 主要参数 |
|
|
112
|
+
|--------|------|----------|
|
|
113
|
+
| `ffmpeg_checkFfmpegInstallation` | 检测FFmpeg是否安装和版本检测 | `minVersion` |
|
|
114
|
+
|
|
115
|
+
### 视频处理 (17个)
|
|
116
|
+
|
|
117
|
+
| 函数名 | 描述 | 主要参数 |
|
|
118
|
+
|--------|------|----------|
|
|
119
|
+
| `ffmpeg_convertVideoFormat` | 转换视频格式 | `inputPath`, `outputPath`, `format`, `quality` |
|
|
120
|
+
| `ffmpeg_resizeVideo` | 调整视频尺寸 | `inputPath`, `outputPath`, `width`, `height`, `keepAspectRatio` |
|
|
121
|
+
| `ffmpeg_trimVideo` | 剪切视频片段 | `inputPath`, `outputPath`, `startTime`, `duration` |
|
|
122
|
+
| `ffmpeg_mergeVideos` | 合并多个视频文件 | `videoPaths`, `outputPath`, `method` |
|
|
123
|
+
| `ffmpeg_adjustBitrate` | 调整视频比特率 | `inputPath`, `outputPath`, `bitrate`, `audioBitrate` |
|
|
124
|
+
| `ffmpeg_addWatermark` | 添加水印 | `inputPath`, `outputPath`, `watermarkPath`, `position`, `opacity` |
|
|
125
|
+
| `ffmpeg_mergeVideoAudio` | 合并视频和音频 | `videoPath`, `audioPath`, `outputPath`, `sync` |
|
|
126
|
+
| `ffmpeg_videoToGif` | 将视频转换为GIF动图 | `videoPath`, `outputPath`, `startTime`, `duration`, `fps`, `width` |
|
|
127
|
+
| `ffmpeg_cropVideo` | 裁剪视频区域 | `videoPath`, `outputPath`, `x`, `y`, `width`, `height` |
|
|
128
|
+
| `ffmpeg_rotateVideo` | 旋转视频 | `videoPath`, `outputPath`, `angle` |
|
|
129
|
+
| `ffmpeg_changeVideoSpeed` | 改变视频播放速度 | `videoPath`, `outputPath`, `speed` |
|
|
130
|
+
| `ffmpeg_addSubtitles` | 添加字幕到视频 | `videoPath`, `subtitlePath`, `outputPath`, `encoding` |
|
|
131
|
+
| `ffmpeg_addTextOverlay` | 添加文本叠加到视频 | `videoPath`, `outputPath`, `text`, `x`, `y`, `fontSize`, `fontColor`, `startTime`, `duration` |
|
|
132
|
+
| `ffmpeg_extractVideoFrames` | 提取视频帧为图片序列 | `videoPath`, `outputDir`, `fps`, `format`, `startTime`, `duration` |
|
|
133
|
+
| `ffmpeg_extractVideoThumbnail` | 提取视频缩略图 | `videoPath`, `outputPath`, `time`, `size` |
|
|
134
|
+
| `ffmpeg_compressVideo` | 压缩视频(调整CRF) | `videoPath`, `outputPath`, `crf`, `preset` |
|
|
135
|
+
| `ffmpeg_concatVideos` | 拼接多个视频文件 | `videoPaths`, `outputPath`, `transition` |
|
|
136
|
+
|
|
137
|
+
### 音频处理 (5个)
|
|
138
|
+
|
|
139
|
+
| 函数名 | 描述 | 主要参数 |
|
|
140
|
+
|--------|------|----------|
|
|
141
|
+
| `ffmpeg_extractAudioFromVideo` | 从视频中提取音频 | `videoPath`, `audioPath`, `audioFormat` |
|
|
142
|
+
| `ffmpeg_convertAudioFormat` | 转换音频格式 | `inputPath`, `outputPath`, `format`, `bitrate` |
|
|
143
|
+
| `ffmpeg_adjustAudioVolume` | 调整音频音量 | `inputPath`, `outputPath`, `volume` |
|
|
144
|
+
| `ffmpeg_mixAudios` | 混合多个音频文件 | `audioPaths`, `outputPath`, `volumes` |
|
|
145
|
+
|
|
146
|
+
### 媒体信息 (1个)
|
|
147
|
+
|
|
148
|
+
| 函数名 | 描述 | 主要参数 |
|
|
149
|
+
|--------|------|----------|
|
|
150
|
+
| `ffmpeg_getMediaInfo` | 获取媒体文件信息 | `mediaPath` |
|
|
151
|
+
|
|
152
|
+
## 🔧 详细使用示例
|
|
153
|
+
|
|
154
|
+
### 视频格式转换
|
|
155
|
+
```javascript
|
|
156
|
+
const result = await functions.ffmpeg_convertVideoFormat({
|
|
157
|
+
inputPath: 'input.avi',
|
|
158
|
+
outputPath: 'output.mp4',
|
|
159
|
+
format: 'mp4',
|
|
160
|
+
quality: '-crf 23'
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 调整视频尺寸
|
|
165
|
+
```javascript
|
|
166
|
+
const result = await functions.ffmpeg_resizeVideo({
|
|
167
|
+
inputPath: 'input.mp4',
|
|
168
|
+
outputPath: 'output_720p.mp4',
|
|
169
|
+
width: 1280,
|
|
170
|
+
height: 720,
|
|
171
|
+
keepAspectRatio: true
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 视频裁剪
|
|
176
|
+
```javascript
|
|
177
|
+
const result = await functions.ffmpeg_cropVideo({
|
|
178
|
+
videoPath: 'input.mp4',
|
|
179
|
+
outputPath: 'output_cropped.mp4',
|
|
180
|
+
x: 100,
|
|
181
|
+
y: 100,
|
|
182
|
+
width: 800,
|
|
183
|
+
height: 600
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 添加水印
|
|
188
|
+
```javascript
|
|
189
|
+
const result = await functions.ffmpeg_addWatermark({
|
|
190
|
+
inputPath: 'video.mp4',
|
|
191
|
+
outputPath: 'video_with_logo.mp4',
|
|
192
|
+
watermarkPath: 'logo.png',
|
|
193
|
+
position: 'top-right',
|
|
194
|
+
opacity: 0.7
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 从视频中提取音频
|
|
199
|
+
```javascript
|
|
200
|
+
const result = await functions.ffmpeg_extractAudioFromVideo({
|
|
201
|
+
videoPath: 'video.mp4',
|
|
202
|
+
audioPath: 'audio.mp3',
|
|
203
|
+
audioFormat: 'mp3'
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### 批量处理示例
|
|
208
|
+
```javascript
|
|
209
|
+
// 批量压缩视频
|
|
210
|
+
const videos = ['video1.mp4', 'video2.mp4', 'video3.mp4'];
|
|
211
|
+
|
|
212
|
+
for (const video of videos) {
|
|
213
|
+
await functions.ffmpeg_compressVideo({
|
|
214
|
+
videoPath: video,
|
|
215
|
+
outputPath: `compressed_${video}`,
|
|
216
|
+
crf: 28, // 更高的CRF值表示更强的压缩
|
|
217
|
+
preset: 'slow'
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## 🏗️ 项目结构
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
ffmpeg7-media-tools/
|
|
226
|
+
├── ffmpeg-functions.js # 23个FFmpeg功能函数实现
|
|
227
|
+
├── ffmpeg-descriptions.js # AI智能体描述信息
|
|
228
|
+
├── index.js # 主入口文件,重新导出功能
|
|
229
|
+
├── package.json # 项目配置
|
|
230
|
+
└── README.md # 本文档
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 文件说明
|
|
234
|
+
|
|
235
|
+
- **ffmpeg-functions.js**: 包含所有23个FFmpeg媒体处理函数的实现,每个函数都有完整的错误处理和参数验证
|
|
236
|
+
- **ffmpeg-descriptions.js**: 为AI智能体提供的函数描述信息,包含详细的参数说明和功能描述
|
|
237
|
+
- **index.js**: 统一导出接口,便于模块化使用
|
|
238
|
+
|
|
239
|
+
## ⚠️ 注意事项
|
|
240
|
+
|
|
241
|
+
1. **FFmpeg版本**: 本工具集基于FFmpeg 7设计,建议使用FFmpeg 7.0或更高版本
|
|
242
|
+
2. **文件路径**: 所有文件路径建议使用绝对路径,相对路径可能因工作目录不同而产生问题
|
|
243
|
+
3. **错误处理**: 所有函数都包含错误处理,执行失败时会抛出详细的错误信息
|
|
244
|
+
4. **资源消耗**: 视频处理是CPU密集型任务,大文件处理时请注意系统资源
|
|
245
|
+
5. **输出目录**: 请确保输出目录存在,否则某些函数可能无法正常创建输出文件
|
|
246
|
+
|
|
247
|
+
## 🔍 故障排除
|
|
248
|
+
|
|
249
|
+
### FFmpeg未找到
|
|
250
|
+
```
|
|
251
|
+
Error: FFmpeg is not installed or not in system PATH
|
|
252
|
+
```
|
|
253
|
+
**解决方案**:
|
|
254
|
+
- 确认FFmpeg已正确安装
|
|
255
|
+
- 将FFmpeg添加到系统PATH环境变量
|
|
256
|
+
- 重启终端或IDE使环境变量生效
|
|
257
|
+
|
|
258
|
+
### 文件不存在
|
|
259
|
+
```
|
|
260
|
+
Error: Input file does not exist: /path/to/file.mp4
|
|
261
|
+
```
|
|
262
|
+
**解决方案**:
|
|
263
|
+
- 确认文件路径正确
|
|
264
|
+
- 使用绝对路径而非相对路径
|
|
265
|
+
- 检查文件权限
|
|
266
|
+
|
|
267
|
+
### 格式不支持
|
|
268
|
+
```
|
|
269
|
+
Error: Unsupported video format: .xyz
|
|
270
|
+
```
|
|
271
|
+
**解决方案**:
|
|
272
|
+
- 检查输入文件格式是否被FFmpeg支持
|
|
273
|
+
- 尝试使用`ffmpeg_convertVideoFormat`先转换格式
|
|
274
|
+
|
|
275
|
+
## 🤝 贡献
|
|
276
|
+
|
|
277
|
+
欢迎提交Issue和Pull Request来改进这个项目。在提交PR前,请确保:
|
|
278
|
+
|
|
279
|
+
1. 代码风格一致
|
|
280
|
+
2. 添加相应的测试
|
|
281
|
+
3. 更新文档(包括API文档和示例)
|
|
282
|
+
4. 函数参数格式统一
|
|
283
|
+
|
|
284
|
+
## 📄 许可证
|
|
285
|
+
|
|
286
|
+
MIT License - 详见LICENSE文件
|
|
287
|
+
|
|
288
|
+
## 📞 支持
|
|
289
|
+
|
|
290
|
+
如有问题或建议,请:
|
|
291
|
+
1. 查看本文档的故障排除部分
|
|
292
|
+
2. 提交GitHub Issue
|
|
293
|
+
3. 联系维护团队
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
**最后更新**: 2026年
|
|
298
|
+
**版本**: 1.0.0
|
|
299
|
+
**FFmpeg版本**: 7.0+
|