-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-gpu.mjs
More file actions
118 lines (97 loc) · 3.36 KB
/
Copy pathtest-gpu.mjs
File metadata and controls
118 lines (97 loc) · 3.36 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env node
/**
* GPU 硬件编码器检测测试脚本
* 用于验证系统是否支持硬件加速
*/
import { spawn } from 'child_process';
const runCommand = (command, args) => {
return new Promise((resolve, reject) => {
const child = spawn(command, args);
let stdout = '';
let stderr = '';
child.stdout.on('data', (data) => {
stdout += data.toString();
});
child.stderr.on('data', (data) => {
stderr += data.toString();
});
child.on('close', (code) => {
if (code === 0) {
resolve({ stdout, stderr });
} else {
reject(new Error(`Command failed with code ${code}\n${stderr}`));
}
});
child.on('error', (err) => {
reject(err);
});
});
};
const testEncoder = async (encoderName, description) => {
try {
await runCommand('ffmpeg', [
'-f', 'lavfi', '-i', 'color=c=black:s=256x256:d=0.1',
'-c:v', encoderName, '-f', 'null', '-'
]);
console.log(`✅ ${description.padEnd(30)} [${encoderName}]`);
return true;
} catch (e) {
console.log(`❌ ${description.padEnd(30)} [${encoderName}]`);
return false;
}
};
const main = async () => {
console.log('\n🔍 检测可用的硬件编码器...\n');
console.log('='.repeat(60));
console.log('\n📹 H.264 编码器:\n');
const h264Encoders = [
{ name: 'h264_videotoolbox', desc: 'Apple VideoToolbox (macOS)' },
{ name: 'h264_nvenc', desc: 'NVIDIA NVENC' },
{ name: 'h264_amf', desc: 'AMD AMF' },
{ name: 'h264_qsv', desc: 'Intel Quick Sync' },
{ name: 'libx264', desc: 'Software Encoding (CPU)' },
];
const h264Results = [];
for (const encoder of h264Encoders) {
const available = await testEncoder(encoder.name, encoder.desc);
h264Results.push({ ...encoder, available });
}
console.log('\n🎬 VP9 编码器 (WebM):\n');
const vp9Encoders = [
{ name: 'vp9_qsv', desc: 'Intel Quick Sync VP9' },
{ name: 'vp9_vaapi', desc: 'VAAPI VP9 (Intel/AMD Linux)' },
{ name: 'libvpx-vp9', desc: 'Software VP9 (CPU)' },
];
const vp9Results = [];
for (const encoder of vp9Encoders) {
const available = await testEncoder(encoder.name, encoder.desc);
vp9Results.push({ ...encoder, available });
}
console.log('='.repeat(60));
const h264HW = h264Results.filter(r => r.available && r.name !== 'libx264');
const vp9HW = vp9Results.filter(r => r.available && r.name !== 'libvpx-vp9');
console.log('\n📊 检测结果:\n');
if (h264HW.length > 0) {
console.log(`✅ H.264 硬件加速: ${h264HW[0].desc} (${h264HW[0].name})`);
console.log(' 适用格式: MP4');
console.log(' 预计性能提升: 3-10 倍 🚀');
} else {
console.log('⚠️ H.264: 仅支持 CPU 软件编码');
}
if (vp9HW.length > 0) {
console.log(`\n✅ VP9 硬件加速: ${vp9HW[0].desc} (${vp9HW[0].name})`);
console.log(' 适用格式: WebM');
console.log(' 预计性能提升: 2-5 倍 🚀');
} else {
console.log('\n⚠️ VP9: 仅支持 CPU 软件编码');
}
if (h264HW.length === 0 && vp9HW.length === 0) {
console.log('\n💡 建议:');
console.log(' - macOS: 确保系统版本 ≥ 10.13');
console.log(' - NVIDIA: 安装最新显卡驱动');
console.log(' - AMD: 安装 AMD 驱动');
console.log(' - Intel: 启用 Intel Quick Sync');
}
console.log('\n');
};
main().catch(console.error);