ffmpeg-progress 1.5.0 → 1.6.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 +58 -0
- package/core.d.ts +8 -0
- package/core.js +30 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,54 @@ await convertFile({
|
|
|
42
42
|
timer.end()
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
**Convert video with custom FFmpeg arguments**:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { convertFile } from 'ffmpeg-progress'
|
|
49
|
+
|
|
50
|
+
// H.264 codec with YUV420p pixel format and 2000k bitrate
|
|
51
|
+
await convertFile({
|
|
52
|
+
inFile: 'input.mp4',
|
|
53
|
+
outFile: 'output.mp4',
|
|
54
|
+
ffmpegArgs: ['-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-b:v', '2000k'],
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// Resize video - Scale to 720p
|
|
58
|
+
await convertFile({
|
|
59
|
+
inFile: 'input.mp4',
|
|
60
|
+
outFile: 'output.mp4',
|
|
61
|
+
ffmpegArgs: ['-vf', 'scale=1280:720'],
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Extract audio - Convert video to MP3
|
|
65
|
+
await convertFile({
|
|
66
|
+
inFile: 'input.mp4',
|
|
67
|
+
outFile: 'output.mp3',
|
|
68
|
+
ffmpegArgs: ['-vn', '-acodec', 'libmp3lame', '-ab', '192k'],
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Quality preset - Use H.264 with slow preset and CRF quality
|
|
72
|
+
await convertFile({
|
|
73
|
+
inFile: 'input.mp4',
|
|
74
|
+
outFile: 'output.mp4',
|
|
75
|
+
ffmpegArgs: ['-c:v', 'libx264', '-preset', 'slow', '-crf', '23'],
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Rotate video**:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { rotateVideo } from 'ffmpeg-progress'
|
|
83
|
+
|
|
84
|
+
await rotateVideo({
|
|
85
|
+
inFile: 'test/in.mp4',
|
|
86
|
+
outFile: 'test/rotated.mp4',
|
|
87
|
+
angle: 90, // Rotate 90° clockwise (or 180, 270)
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Progress monitoring is also available similar to `convertFile` using `onDuration`, `onProgress`, etc.
|
|
92
|
+
|
|
45
93
|
**Get video resolution**:
|
|
46
94
|
|
|
47
95
|
```typescript
|
|
@@ -98,6 +146,16 @@ export function convertFile(
|
|
|
98
146
|
args: {
|
|
99
147
|
inFile: string
|
|
100
148
|
outFile: string
|
|
149
|
+
ffmpegArgs?: string[]
|
|
150
|
+
} & ProgressArgs,
|
|
151
|
+
): Promise<void>
|
|
152
|
+
|
|
153
|
+
export function rotateVideo(
|
|
154
|
+
args: {
|
|
155
|
+
inFile: string
|
|
156
|
+
outFile: string
|
|
157
|
+
/** degrees to rotate in clockwise direction */
|
|
158
|
+
angle: 90 | 180 | 270
|
|
101
159
|
} & ProgressArgs,
|
|
102
160
|
): Promise<void>
|
|
103
161
|
|
package/core.d.ts
CHANGED
|
@@ -43,6 +43,14 @@ export type OnProgressArgs = {
|
|
|
43
43
|
export declare function convertFile(args: {
|
|
44
44
|
inFile: string;
|
|
45
45
|
outFile: string;
|
|
46
|
+
/** e.g. ['-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-b:v', '2000k'] */
|
|
47
|
+
ffmpegArgs?: string[];
|
|
48
|
+
} & ProgressArgs): Promise<void>;
|
|
49
|
+
export declare function rotateVideo(args: {
|
|
50
|
+
inFile: string;
|
|
51
|
+
outFile: string;
|
|
52
|
+
/** degrees to rotate in clockwise direction */
|
|
53
|
+
angle: 90 | 180 | 270;
|
|
46
54
|
} & ProgressArgs): Promise<void>;
|
|
47
55
|
export declare function attachChildProcess(args: {
|
|
48
56
|
childProcess: ChildProcessWithoutNullStreams;
|
package/core.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.secondsToString = secondsToString;
|
|
|
5
5
|
exports.parseVideoMetadata = parseVideoMetadata;
|
|
6
6
|
exports.scanVideo = scanVideo;
|
|
7
7
|
exports.convertFile = convertFile;
|
|
8
|
+
exports.rotateVideo = rotateVideo;
|
|
8
9
|
exports.attachChildProcess = attachChildProcess;
|
|
9
10
|
exports.estimateOutSize = estimateOutSize;
|
|
10
11
|
exports.getVideoResolution = getVideoResolution;
|
|
@@ -136,9 +137,37 @@ function scanVideo(file) {
|
|
|
136
137
|
});
|
|
137
138
|
}
|
|
138
139
|
async function convertFile(args) {
|
|
139
|
-
let
|
|
140
|
+
let ffmpegCommand = ['-y', '-i', args.inFile];
|
|
141
|
+
if (args.ffmpegArgs) {
|
|
142
|
+
ffmpegCommand.push(...args.ffmpegArgs);
|
|
143
|
+
}
|
|
144
|
+
ffmpegCommand.push(args.outFile);
|
|
145
|
+
let childProcess = (0, child_process_1.spawn)('ffmpeg', ffmpegCommand);
|
|
140
146
|
return attachChildProcess({ childProcess, ...args });
|
|
141
147
|
}
|
|
148
|
+
async function rotateVideo(args) {
|
|
149
|
+
let filter;
|
|
150
|
+
switch (args.angle) {
|
|
151
|
+
case 90:
|
|
152
|
+
// 90° clockwise
|
|
153
|
+
filter = 'transpose=1';
|
|
154
|
+
break;
|
|
155
|
+
case 180:
|
|
156
|
+
// 180° rotation
|
|
157
|
+
filter = 'transpose=1,transpose=1';
|
|
158
|
+
break;
|
|
159
|
+
case 270:
|
|
160
|
+
// 270° clockwise (or 90° counterclockwise)
|
|
161
|
+
filter = 'transpose=2';
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
throw new Error(`Unsupported rotation angle: ${args.angle}. Supported angles are 90, 180, or 270 degrees.`);
|
|
165
|
+
}
|
|
166
|
+
return convertFile({
|
|
167
|
+
...args,
|
|
168
|
+
ffmpegArgs: ['-vf', filter, '-c:a', 'copy'],
|
|
169
|
+
});
|
|
170
|
+
}
|
|
142
171
|
async function attachChildProcess(args) {
|
|
143
172
|
let { code, signal } = await new Promise((resolve, reject) => {
|
|
144
173
|
let { childProcess } = args;
|