fix(cutter): protect recovery and verify hardware encoders

This commit is contained in:
Sucukdeluxe
2026-08-12 03:00:39 +02:00
parent 86920b5410
commit be5d60a0ca
10 changed files with 264 additions and 255 deletions
+17 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest';
import { calculateCutterExportProgress, createCutterExportPlan, parseCutterHardwareEncoders } from './cutter-export';
import { calculateCutterExportProgress, createCutterExportPlan, parseCutterHardwareEncoders, probeCutterHardwareEncoders } from './cutter-export';
describe('cutter export segments', () => {
test('sorts playable segments and preserves the caller input', () => {
@@ -174,4 +174,20 @@ describe('cutter export segments', () => {
test('recognizes only offered H.264 hardware encoders from an ffmpeg probe', () => {
expect(parseCutterHardwareEncoders(' V..... h264_nvenc NVIDIA NVENC H.264 encoder\n V..... h264_qsv H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration)\n V..... hevc_amf AMD AMF HEVC encoder')).toEqual(['h264_nvenc', 'h264_qsv']);
});
test('offers only hardware encoders that pass a one-frame encode capability test', async () => {
const probes: Array<{ encoder: string; args: readonly string[] }> = [];
const verified = await probeCutterHardwareEncoders(['h264_nvenc', 'h264_qsv', 'h264_amf'], async (encoder, args) => {
probes.push({ encoder, args });
return encoder !== 'h264_qsv';
});
expect(verified).toEqual(['h264_nvenc', 'h264_amf']);
expect(probes).toHaveLength(3);
expect(probes[0]).toMatchObject({
encoder: 'h264_nvenc',
args: expect.arrayContaining(['-f', 'lavfi', '-frames:v', '1', '-c:v', 'h264_nvenc', '-f', 'null', '-']),
});
});
});