@deepfish-ai/ffmpeg7-media-tools 1.0.0 → 1.0.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 +112 -240
- package/README_CN.md +171 -0
- package/ffmpeg-descriptions.js +24 -0
- package/ffmpeg-functions.js +55 -29
- package/index.js +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,299 +1,171 @@
|
|
|
1
1
|
# @deepfish-ai/ffmpeg7-media-tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [中文](https://github.com/qq306863030/deepfish-extensions/blob/master/deepfish-ffmpeg7-media-tools/README_CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A comprehensive FFmpeg 7 based audio and video processing toolkit with 24 media processing functions, supporting video format conversion, audio extraction, video editing, and other common media processing tasks.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **易于使用**: 统一的参数格式,清晰的错误处理
|
|
9
|
-
- **AI友好**: 包含完整的AI智能体描述信息
|
|
10
|
-
- **跨平台**: 支持Windows、macOS和Linux系统
|
|
11
|
-
- **TypeScript友好**: 完整的JSDoc注释和类型提示
|
|
7
|
+
## ✨ Features
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
- **Comprehensive Coverage**: 24 carefully designed FFmpeg functions covering common media processing needs
|
|
10
|
+
- **Easy to Use**: Unified parameter format, clear error handling
|
|
11
|
+
- **AI Friendly**: Complete AI agent description information included
|
|
12
|
+
- **Cross-Platform**: Supports Windows, macOS, and Linux systems
|
|
13
|
+
- **TypeScript Friendly**: Complete JSDoc comments and type hints
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## 🚀 Quick Start
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Follow these three steps to install and use this extension:
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
2. 解压并添加到系统PATH环境变量
|
|
22
|
-
3. 验证安装:`ffmpeg -version`
|
|
19
|
+
### Step 1: Install DeepFish AI
|
|
20
|
+
First, install the global deepfish-ai library (if not already installed):
|
|
23
21
|
|
|
24
|
-
#### macOS
|
|
25
22
|
```bash
|
|
26
|
-
|
|
27
|
-
brew install ffmpeg@7
|
|
28
|
-
|
|
29
|
-
# 如果找不到ffmpeg@7,可以先更新Homebrew再尝试
|
|
30
|
-
brew update
|
|
31
|
-
brew install ffmpeg@7
|
|
23
|
+
npm install deepfish-ai -g
|
|
32
24
|
```
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
brew install ffmpeg
|
|
37
|
-
```
|
|
26
|
+
### Step 2: Install This Extension
|
|
27
|
+
Install this package globally:
|
|
38
28
|
|
|
39
|
-
#### Linux (Ubuntu/Debian)
|
|
40
|
-
**方法一:使用官方静态构建(推荐)**
|
|
41
29
|
```bash
|
|
42
|
-
|
|
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/
|
|
30
|
+
npm install @deepfish-ai/ffmpeg7-media-tools -g
|
|
50
31
|
```
|
|
51
32
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# 添加PPA
|
|
55
|
-
sudo add-apt-repository ppa:jonathonf/ffmpeg-7
|
|
56
|
-
sudo apt update
|
|
57
|
-
sudo apt install ffmpeg
|
|
58
|
-
```
|
|
33
|
+
### Step 3: Use in DeepFish AI
|
|
34
|
+
Once installed, you can use the extension functions in DeepFish AI by simply asking the AI to perform media processing tasks. For example:
|
|
59
35
|
|
|
60
|
-
**方法三:使用系统仓库(版本可能较旧)**
|
|
61
36
|
```bash
|
|
62
|
-
|
|
63
|
-
sudo apt install ffmpeg
|
|
37
|
+
ai convert video.mp4 to avi format
|
|
64
38
|
```
|
|
65
39
|
|
|
40
|
+
or
|
|
66
41
|
|
|
67
|
-
### 验证安装
|
|
68
|
-
安装完成后,请验证FFmpeg版本是否为7.0或更高:
|
|
69
42
|
```bash
|
|
70
|
-
|
|
43
|
+
ai extract audio from video.mp4
|
|
71
44
|
```
|
|
72
|
-
应该输出类似:`ffmpeg version 7.0.1 Copyright (c) 2000-2024...`
|
|
73
45
|
|
|
74
|
-
|
|
46
|
+
The AI will automatically use the appropriate FFmpeg functions from this extension.
|
|
75
47
|
|
|
76
|
-
###
|
|
77
|
-
```bash
|
|
78
|
-
npm install @deepfish-ai/ffmpeg7-media-tools
|
|
79
|
-
```
|
|
48
|
+
### FFmpeg Installation
|
|
80
49
|
|
|
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
|
-
```
|
|
50
|
+
This toolkit requires FFmpeg 7 or higher. Please install FFmpeg 7 before using:
|
|
106
51
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
```
|
|
52
|
+
- **Windows**: Download FFmpeg 7 from https://ffmpeg.org/download.html and add to system PATH
|
|
53
|
+
- **macOS**: `brew install ffmpeg@7` or `brew install ffmpeg`
|
|
54
|
+
- **Linux**: Use static builds or distribution packages
|
|
163
55
|
|
|
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
|
-
```
|
|
56
|
+
Verify installation: `ffmpeg -version` should show version 7.0 or higher.
|
|
174
57
|
|
|
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
|
-
```
|
|
58
|
+
## 📋 Function List
|
|
186
59
|
|
|
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
|
-
```
|
|
60
|
+
The toolkit provides 24 functions divided into the following categories:
|
|
197
61
|
|
|
198
|
-
###
|
|
199
|
-
```javascript
|
|
200
|
-
const result = await functions.ffmpeg_extractAudioFromVideo({
|
|
201
|
-
videoPath: 'video.mp4',
|
|
202
|
-
audioPath: 'audio.mp3',
|
|
203
|
-
audioFormat: 'mp3'
|
|
204
|
-
});
|
|
205
|
-
```
|
|
62
|
+
### Installation Detection (1 function)
|
|
206
63
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
64
|
+
| Function Name | Description |
|
|
65
|
+
|---------------|-------------|
|
|
66
|
+
| `ffmpeg_checkFfmpegInstallation` | Check FFmpeg installation and version detection |
|
|
67
|
+
|
|
68
|
+
### Video Processing (18 functions)
|
|
69
|
+
|
|
70
|
+
| Function Name | Description |
|
|
71
|
+
|---------------|-------------|
|
|
72
|
+
| `ffmpeg_convertVideoFormat` | Convert video format |
|
|
73
|
+
| `ffmpeg_resizeVideo` | Resize video dimensions |
|
|
74
|
+
| `ffmpeg_trimVideo` | Trim video segment |
|
|
75
|
+
| `ffmpeg_mergeVideos` | Merge multiple video files |
|
|
76
|
+
| `ffmpeg_adjustBitrate` | Adjust video bitrate |
|
|
77
|
+
| `ffmpeg_addWatermark` | Add watermark to video |
|
|
78
|
+
| `ffmpeg_mergeVideoAudio` | Merge video and audio |
|
|
79
|
+
| `ffmpeg_videoToGif` | Convert video to animated GIF |
|
|
80
|
+
| `ffmpeg_cropVideo` | Crop video region |
|
|
81
|
+
| `ffmpeg_rotateVideo` | Rotate video |
|
|
82
|
+
| `ffmpeg_changeVideoSpeed` | Change video playback speed |
|
|
83
|
+
| `ffmpeg_addSubtitles` | Add subtitles to video |
|
|
84
|
+
| `ffmpeg_addTextOverlay` | Add text overlay to video |
|
|
85
|
+
| `ffmpeg_adjustVideoVolume` | Adjust video volume |
|
|
86
|
+
| `ffmpeg_extractVideoFrames` | Extract video frames as image sequence |
|
|
87
|
+
| `ffmpeg_extractVideoThumbnail` | Extract video thumbnail |
|
|
88
|
+
| `ffmpeg_compressVideo` | Compress video (adjust CRF) |
|
|
89
|
+
| `ffmpeg_concatVideos` | Concatenate multiple video files |
|
|
90
|
+
|
|
91
|
+
### Audio Processing (5 functions)
|
|
92
|
+
|
|
93
|
+
| Function Name | Description |
|
|
94
|
+
|---------------|-------------|
|
|
95
|
+
| `ffmpeg_extractAudioFromVideo` | Extract audio from video |
|
|
96
|
+
| `ffmpeg_convertAudioFormat` | Convert audio format |
|
|
97
|
+
| `ffmpeg_adjustAudioVolume` | Adjust audio volume |
|
|
98
|
+
| `ffmpeg_mixAudios` | Mix multiple audio files |
|
|
221
99
|
|
|
222
|
-
|
|
100
|
+
### Media Information (1 function)
|
|
101
|
+
|
|
102
|
+
| Function Name | Description |
|
|
103
|
+
|---------------|-------------|
|
|
104
|
+
| `ffmpeg_getMediaInfo` | Get media file information |
|
|
105
|
+
|
|
106
|
+
## 🏗️ Project Structure
|
|
223
107
|
|
|
224
108
|
```
|
|
225
109
|
ffmpeg7-media-tools/
|
|
226
|
-
├── ffmpeg-functions.js #
|
|
227
|
-
├── ffmpeg-descriptions.js # AI
|
|
228
|
-
├── index.js #
|
|
229
|
-
├── package.json #
|
|
230
|
-
|
|
110
|
+
├── ffmpeg-functions.js # 24 FFmpeg function implementations
|
|
111
|
+
├── ffmpeg-descriptions.js # AI agent description information
|
|
112
|
+
├── index.js # Main entry file, re-exports functions
|
|
113
|
+
├── package.json # Project configuration
|
|
114
|
+
├── README.md # English documentation (this file)
|
|
115
|
+
└── README_CN.md # Chinese documentation
|
|
231
116
|
```
|
|
232
117
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
- **ffmpeg-functions.js**: 包含所有23个FFmpeg媒体处理函数的实现,每个函数都有完整的错误处理和参数验证
|
|
236
|
-
- **ffmpeg-descriptions.js**: 为AI智能体提供的函数描述信息,包含详细的参数说明和功能描述
|
|
237
|
-
- **index.js**: 统一导出接口,便于模块化使用
|
|
118
|
+
## ⚠️ Notes
|
|
238
119
|
|
|
239
|
-
|
|
120
|
+
1. **FFmpeg Version**: This toolkit is designed for FFmpeg 7, recommended to use FFmpeg 7.0 or higher
|
|
121
|
+
2. **File Paths**: Use absolute paths for all file operations
|
|
122
|
+
3. **Error Handling**: All functions include error handling with detailed error messages
|
|
123
|
+
4. **Resource Consumption**: Video processing is CPU-intensive, monitor system resources when processing large files
|
|
124
|
+
5. **Output Directory**: Ensure output directories exist before processing
|
|
240
125
|
|
|
241
|
-
|
|
242
|
-
2. **文件路径**: 所有文件路径建议使用绝对路径,相对路径可能因工作目录不同而产生问题
|
|
243
|
-
3. **错误处理**: 所有函数都包含错误处理,执行失败时会抛出详细的错误信息
|
|
244
|
-
4. **资源消耗**: 视频处理是CPU密集型任务,大文件处理时请注意系统资源
|
|
245
|
-
5. **输出目录**: 请确保输出目录存在,否则某些函数可能无法正常创建输出文件
|
|
126
|
+
## 🔍 Troubleshooting
|
|
246
127
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
### FFmpeg未找到
|
|
128
|
+
### FFmpeg Not Found
|
|
250
129
|
```
|
|
251
130
|
Error: FFmpeg is not installed or not in system PATH
|
|
252
131
|
```
|
|
253
|
-
|
|
254
|
-
-
|
|
255
|
-
-
|
|
256
|
-
-
|
|
132
|
+
**Solution**:
|
|
133
|
+
- Confirm FFmpeg is correctly installed
|
|
134
|
+
- Add FFmpeg to system PATH environment variable
|
|
135
|
+
- Restart terminal or IDE for environment variables to take effect
|
|
257
136
|
|
|
258
|
-
###
|
|
137
|
+
### File Does Not Exist
|
|
259
138
|
```
|
|
260
139
|
Error: Input file does not exist: /path/to/file.mp4
|
|
261
140
|
```
|
|
262
|
-
|
|
263
|
-
-
|
|
264
|
-
-
|
|
265
|
-
-
|
|
141
|
+
**Solution**:
|
|
142
|
+
- Confirm file path is correct
|
|
143
|
+
- Use absolute paths instead of relative paths
|
|
144
|
+
- Check file permissions
|
|
266
145
|
|
|
267
|
-
|
|
268
|
-
```
|
|
269
|
-
Error: Unsupported video format: .xyz
|
|
270
|
-
```
|
|
271
|
-
**解决方案**:
|
|
272
|
-
- 检查输入文件格式是否被FFmpeg支持
|
|
273
|
-
- 尝试使用`ffmpeg_convertVideoFormat`先转换格式
|
|
146
|
+
## 🤝 Contributing
|
|
274
147
|
|
|
275
|
-
|
|
148
|
+
Welcome to submit Issues and Pull Requests to improve this project. Before submitting a PR, please ensure:
|
|
276
149
|
|
|
277
|
-
|
|
150
|
+
1. Code style is consistent
|
|
151
|
+
2. Add appropriate tests
|
|
152
|
+
3. Update documentation (including API docs and examples)
|
|
153
|
+
4. Function parameter formats are unified
|
|
278
154
|
|
|
279
|
-
|
|
280
|
-
2. 添加相应的测试
|
|
281
|
-
3. 更新文档(包括API文档和示例)
|
|
282
|
-
4. 函数参数格式统一
|
|
155
|
+
## 📄 License
|
|
283
156
|
|
|
284
|
-
|
|
157
|
+
MIT License - See LICENSE file
|
|
285
158
|
|
|
286
|
-
|
|
159
|
+
## 📞 Support
|
|
287
160
|
|
|
288
|
-
|
|
161
|
+
For questions or suggestions, please:
|
|
289
162
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
3. 联系维护团队
|
|
163
|
+
1. Check the Troubleshooting section in this documentation
|
|
164
|
+
2. Submit a GitHub Issue
|
|
165
|
+
3. Contact the maintenance team
|
|
294
166
|
|
|
295
167
|
---
|
|
296
168
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
**FFmpeg
|
|
169
|
+
**Last Updated**: 2026
|
|
170
|
+
**Version**: 1.0.0
|
|
171
|
+
**FFmpeg Version**: 7.0+
|
package/README_CN.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# @deepfish-ai/ffmpeg7-media-tools
|
|
2
|
+
|
|
3
|
+
[English](https://github.com/qq306863030/deepfish-extensions/blob/master/deepfish-ffmpeg7-media-tools/README.md) | 中文
|
|
4
|
+
|
|
5
|
+
基于FFmpeg 7的音频视频处理工具函数集,包含24个媒体处理函数,支持视频格式转换、音频提取、视频编辑等常见媒体处理任务。
|
|
6
|
+
|
|
7
|
+
## ✨ 特性
|
|
8
|
+
|
|
9
|
+
- **全面覆盖**: 24个精心设计的FFmpeg函数,覆盖常见媒体处理需求
|
|
10
|
+
- **易于使用**: 统一的参数格式,清晰的错误处理
|
|
11
|
+
- **AI友好**: 包含完整的AI智能体描述信息
|
|
12
|
+
- **跨平台**: 支持Windows、macOS和Linux系统
|
|
13
|
+
- **TypeScript友好**: 完整的JSDoc注释和类型提示
|
|
14
|
+
|
|
15
|
+
## 🚀 快速开始
|
|
16
|
+
|
|
17
|
+
按照以下三个步骤安装和使用此扩展:
|
|
18
|
+
|
|
19
|
+
### 步骤1: 安装DeepFish AI
|
|
20
|
+
首先,安装全局deepfish-ai库(如果尚未安装):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install deepfish-ai -g
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 步骤2: 安装此扩展
|
|
27
|
+
全局安装本包:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @deepfish-ai/ffmpeg7-media-tools -g
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 步骤3: 在DeepFish AI中使用
|
|
34
|
+
安装完成后,您可以在DeepFish AI中通过简单的命令使用扩展功能。例如:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
ai 将video.mp4转换为avi格式
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
或
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
ai 从video.mp4中提取音频
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
AI会自动使用此扩展中的相应FFmpeg函数。
|
|
47
|
+
|
|
48
|
+
### FFmpeg安装
|
|
49
|
+
|
|
50
|
+
本工具集需要FFmpeg 7或更高版本。使用前请先安装FFmpeg 7:
|
|
51
|
+
|
|
52
|
+
- **Windows**: 从 https://ffmpeg.org/download.html 下载FFmpeg 7并添加到系统PATH
|
|
53
|
+
- **macOS**: `brew install ffmpeg@7` 或 `brew install ffmpeg`
|
|
54
|
+
- **Linux**: 使用静态构建或发行版软件包
|
|
55
|
+
|
|
56
|
+
验证安装:`ffmpeg -version` 应显示版本7.0或更高。
|
|
57
|
+
|
|
58
|
+
## 📋 函数列表
|
|
59
|
+
|
|
60
|
+
工具集提供24个函数,分为以下类别:
|
|
61
|
+
|
|
62
|
+
### 安装检测 (1个函数)
|
|
63
|
+
|
|
64
|
+
| 函数名 | 描述 |
|
|
65
|
+
|--------|------|
|
|
66
|
+
| `ffmpeg_checkFfmpegInstallation` | 检测FFmpeg是否安装和版本检测 |
|
|
67
|
+
|
|
68
|
+
### 视频处理 (18个函数)
|
|
69
|
+
|
|
70
|
+
| 函数名 | 描述 |
|
|
71
|
+
|--------|------|
|
|
72
|
+
| `ffmpeg_convertVideoFormat` | 转换视频格式 |
|
|
73
|
+
| `ffmpeg_resizeVideo` | 调整视频尺寸 |
|
|
74
|
+
| `ffmpeg_trimVideo` | 剪切视频片段 |
|
|
75
|
+
| `ffmpeg_mergeVideos` | 合并多个视频文件 |
|
|
76
|
+
| `ffmpeg_adjustBitrate` | 调整视频比特率 |
|
|
77
|
+
| `ffmpeg_addWatermark` | 添加水印 |
|
|
78
|
+
| `ffmpeg_mergeVideoAudio` | 合并视频和音频 |
|
|
79
|
+
| `ffmpeg_videoToGif` | 将视频转换为GIF动图 |
|
|
80
|
+
| `ffmpeg_cropVideo` | 裁剪视频区域 |
|
|
81
|
+
| `ffmpeg_rotateVideo` | 旋转视频 |
|
|
82
|
+
| `ffmpeg_changeVideoSpeed` | 改变视频播放速度 |
|
|
83
|
+
| `ffmpeg_addSubtitles` | 添加字幕到视频 |
|
|
84
|
+
| `ffmpeg_addTextOverlay` | 添加文本叠加到视频 |
|
|
85
|
+
| `ffmpeg_adjustVideoVolume` | 调整视频音量 |
|
|
86
|
+
| `ffmpeg_extractVideoFrames` | 提取视频帧为图片序列 |
|
|
87
|
+
| `ffmpeg_extractVideoThumbnail` | 提取视频缩略图 |
|
|
88
|
+
| `ffmpeg_compressVideo` | 压缩视频(调整CRF) |
|
|
89
|
+
| `ffmpeg_concatVideos` | 拼接多个视频文件 |
|
|
90
|
+
|
|
91
|
+
### 音频处理 (5个函数)
|
|
92
|
+
|
|
93
|
+
| 函数名 | 描述 |
|
|
94
|
+
|--------|------|
|
|
95
|
+
| `ffmpeg_extractAudioFromVideo` | 从视频中提取音频 |
|
|
96
|
+
| `ffmpeg_convertAudioFormat` | 转换音频格式 |
|
|
97
|
+
| `ffmpeg_adjustAudioVolume` | 调整音频音量 |
|
|
98
|
+
| `ffmpeg_mixAudios` | 混合多个音频文件 |
|
|
99
|
+
|
|
100
|
+
### 媒体信息 (1个函数)
|
|
101
|
+
|
|
102
|
+
| 函数名 | 描述 |
|
|
103
|
+
|--------|------|
|
|
104
|
+
| `ffmpeg_getMediaInfo` | 获取媒体文件信息 |
|
|
105
|
+
|
|
106
|
+
## 🏗️ 项目结构
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
ffmpeg7-media-tools/
|
|
110
|
+
├── ffmpeg-functions.js # 24个FFmpeg功能函数实现
|
|
111
|
+
├── ffmpeg-descriptions.js # AI智能体描述信息
|
|
112
|
+
├── index.js # 主入口文件,重新导出功能
|
|
113
|
+
├── package.json # 项目配置
|
|
114
|
+
├── README.md # 英文文档
|
|
115
|
+
└── README_CN.md # 中文文档(本文档)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## ⚠️ 注意事项
|
|
119
|
+
|
|
120
|
+
1. **FFmpeg版本**: 本工具集基于FFmpeg 7设计,建议使用FFmpeg 7.0或更高版本
|
|
121
|
+
2. **文件路径**: 所有文件路径建议使用绝对路径,相对路径可能因工作目录不同而产生问题
|
|
122
|
+
3. **错误处理**: 所有函数都包含错误处理,执行失败时会抛出详细的错误信息
|
|
123
|
+
4. **资源消耗**: 视频处理是CPU密集型任务,大文件处理时请注意系统资源
|
|
124
|
+
5. **输出目录**: 请确保输出目录存在,否则某些函数可能无法正常创建输出文件
|
|
125
|
+
|
|
126
|
+
## 🔍 故障排除
|
|
127
|
+
|
|
128
|
+
### FFmpeg未找到
|
|
129
|
+
```
|
|
130
|
+
Error: FFmpeg is not installed or not in system PATH
|
|
131
|
+
```
|
|
132
|
+
**解决方案**:
|
|
133
|
+
- 确认FFmpeg已正确安装
|
|
134
|
+
- 将FFmpeg添加到系统PATH环境变量
|
|
135
|
+
- 重启终端或IDE使环境变量生效
|
|
136
|
+
|
|
137
|
+
### 文件不存在
|
|
138
|
+
```
|
|
139
|
+
Error: Input file does not exist: /path/to/file.mp4
|
|
140
|
+
```
|
|
141
|
+
**解决方案**:
|
|
142
|
+
- 确认文件路径正确
|
|
143
|
+
- 使用绝对路径而非相对路径
|
|
144
|
+
- 检查文件权限
|
|
145
|
+
|
|
146
|
+
## 🤝 贡献
|
|
147
|
+
|
|
148
|
+
欢迎提交Issue和Pull Request来改进这个项目。在提交PR前,请确保:
|
|
149
|
+
|
|
150
|
+
1. 代码风格一致
|
|
151
|
+
2. 添加相应的测试
|
|
152
|
+
3. 更新文档(包括API文档和示例)
|
|
153
|
+
4. 函数参数格式统一
|
|
154
|
+
|
|
155
|
+
## 📄 许可证
|
|
156
|
+
|
|
157
|
+
MIT License - 详见LICENSE文件
|
|
158
|
+
|
|
159
|
+
## 📞 支持
|
|
160
|
+
|
|
161
|
+
如有问题或建议,请:
|
|
162
|
+
|
|
163
|
+
1. 查看本文档的故障排除部分
|
|
164
|
+
2. 提交GitHub Issue
|
|
165
|
+
3. 联系维护团队
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
**最后更新**: 2026
|
|
170
|
+
**版本**: 1.0.0
|
|
171
|
+
**FFmpeg版本**: 7.0+
|
package/ffmpeg-descriptions.js
CHANGED
|
@@ -672,6 +672,30 @@ descriptions.push({
|
|
|
672
672
|
]
|
|
673
673
|
}
|
|
674
674
|
});
|
|
675
|
+
|
|
676
|
+
descriptions.push({
|
|
677
|
+
name: 'ffmpeg_adjustVideoVolume',
|
|
678
|
+
description: 'FFmpeg工具:调整视频音量',
|
|
679
|
+
parameters: {
|
|
680
|
+
type: 'object',
|
|
681
|
+
properties: {
|
|
682
|
+
videoPath: {
|
|
683
|
+
type: 'string',
|
|
684
|
+
description: '输入视频文件路径',
|
|
685
|
+
},
|
|
686
|
+
outputPath: {
|
|
687
|
+
type: 'string',
|
|
688
|
+
description: '输出视频文件路径',
|
|
689
|
+
},
|
|
690
|
+
volume: {
|
|
691
|
+
type: 'number',
|
|
692
|
+
description: '音量倍数(如0.5为一半音量,2.0为两倍音量)',
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
required: ['videoPath', 'outputPath', 'volume'],
|
|
696
|
+
},
|
|
697
|
+
});
|
|
698
|
+
|
|
675
699
|
|
|
676
700
|
|
|
677
701
|
|
package/ffmpeg-functions.js
CHANGED
|
@@ -22,7 +22,7 @@ const checkFfmpeg = async () => {
|
|
|
22
22
|
command = 'which ffmpeg';
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
await this.Tools.executeCommand(command);
|
|
25
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
26
26
|
return { installed: true, error: null };
|
|
27
27
|
} catch (error) {
|
|
28
28
|
return {
|
|
@@ -38,7 +38,7 @@ const checkFfmpeg = async () => {
|
|
|
38
38
|
*/
|
|
39
39
|
const getFfmpegVersion = async () => {
|
|
40
40
|
try {
|
|
41
|
-
const result = await this.Tools.executeCommand('ffmpeg -version');
|
|
41
|
+
const result = await this.aiCl.Tools.executeCommand('ffmpeg -version');
|
|
42
42
|
// 从输出中提取版本号
|
|
43
43
|
const versionMatch = result.match(/ffmpeg version (\S+)/);
|
|
44
44
|
const version = versionMatch ? versionMatch[1] : '未知版本';
|
|
@@ -132,7 +132,7 @@ functions.ffmpeg_convertVideoFormat = async (params) => {
|
|
|
132
132
|
finalOutputPath = finalOutputPath.replace(/\.[^/.]+$/, "") + `.${format}`;
|
|
133
133
|
}
|
|
134
134
|
const command = `ffmpeg -i "${inputPath}" ${quality} "${finalOutputPath}"`;
|
|
135
|
-
await this.Tools.executeCommand(command);
|
|
135
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
136
136
|
return {
|
|
137
137
|
success: true,
|
|
138
138
|
message: `视频格式转换完成: ${finalOutputPath}`,
|
|
@@ -159,7 +159,7 @@ functions.ffmpeg_extractAudioFromVideo = async (params) => {
|
|
|
159
159
|
finalAudioPath = finalAudioPath.replace(/\.[^/.]+$/, "") + `.${audioFormat}`;
|
|
160
160
|
}
|
|
161
161
|
const command = `ffmpeg -i "${videoPath}" -q:a 0 -map a "${finalAudioPath}"`;
|
|
162
|
-
await this.Tools.executeCommand(command);
|
|
162
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
163
163
|
return {
|
|
164
164
|
success: true,
|
|
165
165
|
message: `音频提取完成: ${finalAudioPath}`,
|
|
@@ -187,7 +187,7 @@ functions.ffmpeg_resizeVideo = async (params) => {
|
|
|
187
187
|
scaleFilter = `scale=${width}:${height}`;
|
|
188
188
|
}
|
|
189
189
|
const command = `ffmpeg -i "${inputPath}" -vf "${scaleFilter}" -c:a copy "${outputPath}"`;
|
|
190
|
-
await this.Tools.executeCommand(command);
|
|
190
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
191
191
|
return {
|
|
192
192
|
success: true,
|
|
193
193
|
message: `视频尺寸调整完成: ${width}x${height}`,
|
|
@@ -209,7 +209,7 @@ functions.ffmpeg_trimVideo = async (params) => {
|
|
|
209
209
|
throw new Error(`FFmpeg检查失败: ${checkResult.message}`);
|
|
210
210
|
}
|
|
211
211
|
const command = `ffmpeg -i "${inputPath}" -ss ${startTime} -t ${duration} -c copy "${outputPath}"`;
|
|
212
|
-
await this.Tools.executeCommand(command);
|
|
212
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
213
213
|
return {
|
|
214
214
|
success: true,
|
|
215
215
|
message: `视频剪切完成: 从 ${startTime} 开始,持续 ${duration}`,
|
|
@@ -237,16 +237,16 @@ functions.ffmpeg_mergeVideos = async (params) => {
|
|
|
237
237
|
videoPaths.forEach(path => {
|
|
238
238
|
listContent += `file '${path}'\n`;
|
|
239
239
|
});
|
|
240
|
-
await this.Tools.createFile(listFilePath, listContent);
|
|
240
|
+
await this.aiCl.Tools.createFile(listFilePath, listContent);
|
|
241
241
|
const command = `ffmpeg -f concat -safe 0 -i "${listFilePath}" -c copy "${outputPath}"`;
|
|
242
|
-
await this.Tools.executeCommand(command);
|
|
242
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
243
243
|
// 删除临时文件
|
|
244
|
-
await this.Tools.deleteFile(listFilePath);
|
|
244
|
+
await this.aiCl.Tools.deleteFile(listFilePath);
|
|
245
245
|
} else if (method === 'overlay') {
|
|
246
246
|
// 简单叠加示例(实际应用中可能需要更复杂的处理)
|
|
247
247
|
if (videoPaths.length === 2) {
|
|
248
248
|
const command = `ffmpeg -i "${videoPaths[0]}" -i "${videoPaths[1]}" -filter_complex "[0:v][1:v]overlay=10:10" "${outputPath}"`;
|
|
249
|
-
await this.Tools.executeCommand(command);
|
|
249
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
250
250
|
} else {
|
|
251
251
|
throw new Error('叠加模式目前仅支持两个视频');
|
|
252
252
|
}
|
|
@@ -283,7 +283,7 @@ functions.ffmpeg_convertAudioFormat = async (params) => {
|
|
|
283
283
|
bitrateOption = `-b:a ${bitrate}`;
|
|
284
284
|
}
|
|
285
285
|
const command = `ffmpeg -i "${inputPath}" ${bitrateOption} "${finalOutputPath}"`;
|
|
286
|
-
await this.Tools.executeCommand(command);
|
|
286
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
287
287
|
return {
|
|
288
288
|
success: true,
|
|
289
289
|
message: `音频格式转换完成: ${format}`,
|
|
@@ -305,7 +305,7 @@ functions.ffmpeg_adjustAudioVolume = async (params) => {
|
|
|
305
305
|
throw new Error(`FFmpeg检查失败: ${checkResult.message}`);
|
|
306
306
|
}
|
|
307
307
|
const command = `ffmpeg -i "${inputPath}" -filter:a "volume=${volume}" "${outputPath}"`;
|
|
308
|
-
await this.Tools.executeCommand(command);
|
|
308
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
309
309
|
return {
|
|
310
310
|
success: true,
|
|
311
311
|
message: `音频音量调整完成: ${volume}倍`,
|
|
@@ -336,7 +336,7 @@ functions.ffmpeg_extractVideoThumbnail = async (params) => {
|
|
|
336
336
|
sizeOption = `-s ${size}`;
|
|
337
337
|
}
|
|
338
338
|
const command = `ffmpeg -i "${videoPath}" -ss ${time} -vframes 1 ${sizeOption} "${finalOutputPath}"`;
|
|
339
|
-
await this.Tools.executeCommand(command);
|
|
339
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
340
340
|
return {
|
|
341
341
|
success: true,
|
|
342
342
|
message: `视频缩略图提取完成: ${time}`,
|
|
@@ -359,7 +359,7 @@ functions.ffmpeg_getMediaInfo = async (params) => {
|
|
|
359
359
|
}
|
|
360
360
|
try {
|
|
361
361
|
const command = `ffprobe -v quiet -print_format json -show_format -show_streams "${mediaPath}"`;
|
|
362
|
-
const result = await this.Tools.executeCommand(command);
|
|
362
|
+
const result = await this.aiCl.Tools.executeCommand(command);
|
|
363
363
|
// 解析JSON结果
|
|
364
364
|
const info = JSON.parse(result);
|
|
365
365
|
// 提取关键信息
|
|
@@ -395,7 +395,7 @@ functions.ffmpeg_getMediaInfo = async (params) => {
|
|
|
395
395
|
// 如果ffprobe失败,尝试使用ffmpeg获取基本信息
|
|
396
396
|
try {
|
|
397
397
|
const fallbackCommand = `ffmpeg -i "${mediaPath}"`;
|
|
398
|
-
await this.Tools.executeCommand(fallbackCommand);
|
|
398
|
+
await this.aiCl.Tools.executeCommand(fallbackCommand);
|
|
399
399
|
} catch (ffmpegError) {
|
|
400
400
|
// 从错误信息中提取信息
|
|
401
401
|
const errorStr = ffmpegError.toString();
|
|
@@ -468,7 +468,7 @@ functions.ffmpeg_addWatermark = async (params) => {
|
|
|
468
468
|
// 添加输出路径
|
|
469
469
|
command += ` "${outputPath}"`;
|
|
470
470
|
try {
|
|
471
|
-
const result = await this.Tools.executeCommand(command);
|
|
471
|
+
const result = await this.aiCl.Tools.executeCommand(command);
|
|
472
472
|
return {
|
|
473
473
|
success: true,
|
|
474
474
|
message: `水印添加完成: ${outputPath}`,
|
|
@@ -502,7 +502,7 @@ functions.ffmpeg_adjustBitrate = async (params) => {
|
|
|
502
502
|
// 添加输出路径
|
|
503
503
|
command += ` "${outputPath}"`;
|
|
504
504
|
try {
|
|
505
|
-
const result = await this.Tools.executeCommand(command);
|
|
505
|
+
const result = await this.aiCl.Tools.executeCommand(command);
|
|
506
506
|
return {
|
|
507
507
|
success: true,
|
|
508
508
|
message: `视频比特率调整完成: ${outputPath}`,
|
|
@@ -535,7 +535,7 @@ functions.ffmpeg_mergeVideoAudio = async (params) => {
|
|
|
535
535
|
command = `ffmpeg -i "${videoPath}" -i "${audioPath}" -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 "${outputPath}"`;
|
|
536
536
|
}
|
|
537
537
|
try {
|
|
538
|
-
const result = await this.Tools.executeCommand(command);
|
|
538
|
+
const result = await this.aiCl.Tools.executeCommand(command);
|
|
539
539
|
return {
|
|
540
540
|
success: true,
|
|
541
541
|
message: `视频音频合并完成: ${outputPath}`,
|
|
@@ -582,7 +582,7 @@ functions.ffmpeg_videoToGif = async (params) => {
|
|
|
582
582
|
command += ` "${outputPath}"`;
|
|
583
583
|
|
|
584
584
|
// 执行命令
|
|
585
|
-
await this.Tools.executeCommand(command);
|
|
585
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
586
586
|
|
|
587
587
|
return {
|
|
588
588
|
success: true,
|
|
@@ -627,7 +627,7 @@ functions.ffmpeg_cropVideo = async (params) => {
|
|
|
627
627
|
const command = `ffmpeg -i "${videoPath}" -vf "crop=${width}:${height}:${x}:${y}" "${outputPath}"`;
|
|
628
628
|
|
|
629
629
|
// 执行命令
|
|
630
|
-
await this.Tools.executeCommand(command);
|
|
630
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
631
631
|
|
|
632
632
|
return {
|
|
633
633
|
success: true,
|
|
@@ -673,7 +673,7 @@ functions.ffmpeg_rotateVideo = async (params) => {
|
|
|
673
673
|
const command = `ffmpeg -i "${videoPath}" -vf "${filter}" "${outputPath}"`;
|
|
674
674
|
|
|
675
675
|
// 执行命令
|
|
676
|
-
await this.Tools.executeCommand(command);
|
|
676
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
677
677
|
|
|
678
678
|
return {
|
|
679
679
|
success: true,
|
|
@@ -712,7 +712,7 @@ functions.ffmpeg_changeVideoSpeed = async (params) => {
|
|
|
712
712
|
const command = `ffmpeg -i "${videoPath}" -filter_complex "[0:v]setpts=${1/speed}*PTS[v];[0:a]atempo=${speed}[a]" -map "[v]" -map "[a]" "${outputPath}"`;
|
|
713
713
|
|
|
714
714
|
// 执行命令
|
|
715
|
-
await this.Tools.executeCommand(command);
|
|
715
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
716
716
|
|
|
717
717
|
return {
|
|
718
718
|
success: true,
|
|
@@ -755,7 +755,7 @@ functions.ffmpeg_addSubtitles = async (params) => {
|
|
|
755
755
|
command += ` -c:a copy "${outputPath}"`;
|
|
756
756
|
|
|
757
757
|
// 执行命令
|
|
758
|
-
await this.Tools.executeCommand(command);
|
|
758
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
759
759
|
|
|
760
760
|
return {
|
|
761
761
|
success: true,
|
|
@@ -800,7 +800,7 @@ functions.ffmpeg_extractVideoFrames = async (params) => {
|
|
|
800
800
|
command += ` "${outputDir}/frame_%04d.${format || 'jpg'}"`;
|
|
801
801
|
|
|
802
802
|
// 执行命令
|
|
803
|
-
await this.Tools.executeCommand(command);
|
|
803
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
804
804
|
|
|
805
805
|
return {
|
|
806
806
|
success: true,
|
|
@@ -838,11 +838,11 @@ functions.ffmpeg_concatVideos = async (params) => {
|
|
|
838
838
|
// 创建临时文件列表
|
|
839
839
|
const listPath = `${outputPath}.txt`;
|
|
840
840
|
const listContent = videoPaths.map(path => `file '${path}'`).join('\n');
|
|
841
|
-
await this.Tools.fs.writeFile(listPath, listContent);
|
|
841
|
+
await this.aiCl.Tools.fs.writeFile(listPath, listContent);
|
|
842
842
|
const command = `ffmpeg -f concat -safe 0 -i "${listPath}" -c copy "${outputPath}"`;
|
|
843
843
|
|
|
844
844
|
// 执行命令
|
|
845
|
-
await this.Tools.executeCommand(command);
|
|
845
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
846
846
|
|
|
847
847
|
return {
|
|
848
848
|
success: true,
|
|
@@ -882,7 +882,7 @@ functions.ffmpeg_mixAudios = async (params) => {
|
|
|
882
882
|
const command = `ffmpeg ${inputs} -filter_complex "${mixFilter}" "${outputPath}"`;
|
|
883
883
|
|
|
884
884
|
// 执行命令
|
|
885
|
-
await this.Tools.executeCommand(command);
|
|
885
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
886
886
|
|
|
887
887
|
return {
|
|
888
888
|
success: true,
|
|
@@ -921,7 +921,7 @@ functions.ffmpeg_compressVideo = async (params) => {
|
|
|
921
921
|
const command = `ffmpeg -i "${videoPath}" -c:v libx264 -crf ${crf || 23} -preset ${preset || 'medium'} -c:a copy "${outputPath}"`;
|
|
922
922
|
|
|
923
923
|
// 执行命令
|
|
924
|
-
await this.Tools.executeCommand(command);
|
|
924
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
925
925
|
|
|
926
926
|
return {
|
|
927
927
|
success: true,
|
|
@@ -968,7 +968,7 @@ functions.ffmpeg_addTextOverlay = async (params) => {
|
|
|
968
968
|
const command = `ffmpeg -i "${videoPath}" -vf "${filter}" "${outputPath}"`;
|
|
969
969
|
|
|
970
970
|
// 执行命令
|
|
971
|
-
await this.Tools.executeCommand(command);
|
|
971
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
972
972
|
|
|
973
973
|
return {
|
|
974
974
|
success: true,
|
|
@@ -981,6 +981,32 @@ functions.ffmpeg_addTextOverlay = async (params) => {
|
|
|
981
981
|
}
|
|
982
982
|
};
|
|
983
983
|
|
|
984
|
+
/**
|
|
985
|
+
* 调整视频音量
|
|
986
|
+
* @param {object} params 参数对象
|
|
987
|
+
* @param {string} params.videoPath 输入视频文件路径
|
|
988
|
+
* @param {string} params.outputPath 输出视频文件路径
|
|
989
|
+
* @param {number} params.volume 音量倍数(如0.5为一半音量,2.0为两倍音量)
|
|
990
|
+
*/
|
|
991
|
+
functions.ffmpeg_adjustVideoVolume = async (params) => {
|
|
992
|
+
const { videoPath, outputPath, volume } = params;
|
|
993
|
+
// 检查ffmpeg安装
|
|
994
|
+
const checkResult = await functions.ffmpeg_checkFfmpegInstallation({ minVersion: '7.0.0' });
|
|
995
|
+
if (!checkResult.installed || !checkResult.versionOk) {
|
|
996
|
+
throw new Error(`FFmpeg检查失败: ${checkResult.message}`);
|
|
997
|
+
}
|
|
998
|
+
// 构建调整视频音量命令
|
|
999
|
+
// 使用-filter:a调整音频,-c:v copy保持视频流不重新编码
|
|
1000
|
+
const command = `ffmpeg -i "${videoPath}" -filter:a "volume=${volume}" -c:v copy "${outputPath}"`;
|
|
1001
|
+
await this.aiCl.Tools.executeCommand(command);
|
|
1002
|
+
return {
|
|
1003
|
+
success: true,
|
|
1004
|
+
message: `视频音量调整完成: ${volume}倍`,
|
|
1005
|
+
outputPath: outputPath
|
|
1006
|
+
};
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
|
|
984
1010
|
|
|
985
1011
|
|
|
986
1012
|
// ============ 模块导出 ============
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepfish-ai/ffmpeg7-media-tools",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"description": "A DeepFish AI extension tool for comprehensive FFmpeg 7 media processing with 24 audio/video manipulation functions",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"scripts": {},
|
|
7
8
|
"keywords": [
|
|
@@ -23,4 +24,4 @@
|
|
|
23
24
|
"url": "https://github.com/qq306863030/deepfish-extensions/issues"
|
|
24
25
|
},
|
|
25
26
|
"homepage": "https://github.com/qq306863030/deepfish-extensions#readme"
|
|
26
|
-
}
|
|
27
|
+
}
|