fix: Исправление выбора энкодер/декодер

This commit is contained in:
2026-01-20 14:24:51 +03:00
parent 88fc443cb6
commit 69b3a4804f
15 changed files with 457 additions and 250 deletions

View File

@@ -6,6 +6,8 @@ export {
checkAV1Support,
detectHardwareEncoders,
detectHardwareDecoders,
testEncoder,
testDecoder,
execFFmpeg,
execMP4Box,
setLogFile

View File

@@ -193,6 +193,57 @@ export async function detectHardwareDecoders(): Promise<HardwareDecoderInfo[]> {
return decoders;
}
/**
* Простой smoke-тест энкодера FFmpeg (1 кадр из testsrc)
*/
export async function testEncoder(encoder: string): Promise<boolean> {
const args = [
'-v', 'error',
'-f', 'lavfi',
'-i', 'testsrc=size=320x240:rate=1',
'-frames:v', '1',
'-an',
'-c:v', encoder,
'-f', 'null', '-'
];
return new Promise((resolve) => {
const proc = spawn('ffmpeg', args);
proc.on('error', () => resolve(false));
proc.on('close', (code) => resolve(code === 0));
});
}
/**
* Простой smoke-тест декодера FFmpeg (1 кадр входного файла)
*/
export async function testDecoder(accel: HardwareAccelerator, input: string): Promise<boolean> {
const args = ['-v', 'error'];
if (accel === 'nvenc') {
args.push('-hwaccel', 'cuda', '-hwaccel_output_format', 'cuda');
} else if (accel === 'qsv') {
args.push('-hwaccel', 'qsv');
} else if (accel === 'vaapi') {
args.push('-hwaccel', 'vaapi', '-vaapi_device', '/dev/dri/renderD128');
} else if (accel === 'videotoolbox') {
args.push('-hwaccel', 'videotoolbox');
} else if (accel === 'v4l2') {
args.push('-hwaccel', 'v4l2m2m');
} else if (accel === 'amf') {
// AMF декод чаще всего не используется напрямую; считаем недоступным
return false;
}
args.push('-i', input, '-frames:v', '1', '-f', 'null', '-');
return new Promise((resolve) => {
const proc = spawn('ffmpeg', args);
proc.on('error', () => resolve(false));
proc.on('close', (code) => resolve(code === 0));
});
}
/**
* Execute FFmpeg command with progress tracking
*/