-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffmpeg-args.ts
More file actions
37 lines (34 loc) · 1.58 KB
/
Copy pathffmpeg-args.ts
File metadata and controls
37 lines (34 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { Config } from "../types/config";
export function getFFmpegArgs(config: Config): string[] {
const ffmpegArgs = [
'-y',
'-f', 'image2pipe',
'-r', `${config.fps}`,
'-i', '-',
'-filter_complex', 'trim=duration=' + config.durationSeconds + ',setpts=PTS-STARTPTS', // Limit duration
'-shortest', // Stop when the shortest input (image pipe) ends
'-c:v', 'libvpx-vp9',
// Use CRF mode for better quality-per-byte (lower = better quality, 15-35 is typical range)
'-crf', '30',
'-b:v', '0', // Required for CRF mode in VP9
'-pix_fmt', 'yuva420p', // With alpha channel (transparent background)
'-auto-alt-ref', '0',
// Streaming optimizations
'-deadline', 'realtime', // Fast encoding for streaming
'-cpu-used', '8', // Faster encoding (0-5, higher = faster)
'-row-mt', '1', // Row-based multithreading
'-frame-parallel', '1', // Parallel frame processing
'-tile-columns', '2', // Parallel encoding tiles
'-g', '30' // Keyframe interval for seeking
];
// output decision
if (config.save_as_file) {
ffmpegArgs.push(config.filename);
} else {
ffmpegArgs.push(
'-f', 'webm',
'pipe:1'
);
}
return ffmpegArgs;
}