refactor: убрать useNvenc и разделить выбор энкодера/декодера

This commit is contained in:
2026-01-20 10:38:25 +03:00
parent f550b7eb69
commit 224f14a8e0
8 changed files with 194 additions and 68 deletions

View File

@@ -1,6 +1,6 @@
import { join } from 'node:path';
import { execFFmpeg, selectAudioBitrate } from '../utils';
import type { VideoProfile, VideoOptimizations, CodecQualitySettings } from '../types';
import type { VideoProfile, VideoOptimizations, CodecQualitySettings, HardwareAccelerator } from '../types';
/**
* Get default CQ/CRF value based on resolution and codec
@@ -53,15 +53,29 @@ export async function encodeProfileToMP4(
codecType: 'h264' | 'av1',
qualitySettings?: CodecQualitySettings,
optimizations?: VideoOptimizations,
decoderAccel?: HardwareAccelerator,
onProgress?: (percent: number) => void
): Promise<string> {
const outputPath = join(tempDir, `video_${codecType}_${profile.name}.mp4`);
const args = [
'-y',
'-i', input,
'-c:v', videoCodec
];
const args = ['-y'];
// Hardware decode (optional)
if (decoderAccel) {
if (decoderAccel === 'nvenc') {
args.push('-hwaccel', 'cuda', '-hwaccel_output_format', 'cuda');
} else if (decoderAccel === 'qsv') {
args.push('-hwaccel', 'qsv');
} else if (decoderAccel === 'vaapi') {
args.push('-hwaccel', 'vaapi');
} else if (decoderAccel === 'videotoolbox') {
args.push('-hwaccel', 'videotoolbox');
} else if (decoderAccel === 'v4l2') {
args.push('-hwaccel', 'v4l2');
}
}
args.push('-i', input, '-c:v', videoCodec);
// Determine if using GPU or CPU encoder
const isGPU = videoCodec.includes('nvenc') || videoCodec.includes('qsv') || videoCodec.includes('amf') || videoCodec.includes('vaapi') || videoCodec.includes('videotoolbox') || videoCodec.includes('v4l2');
@@ -196,6 +210,7 @@ export async function encodeProfilesToMP4(
codecType: 'h264' | 'av1',
qualitySettings?: CodecQualitySettings,
optimizations?: VideoOptimizations,
decoderAccel?: HardwareAccelerator,
onProgress?: (profileName: string, percent: number) => void
): Promise<Map<string, string>> {
const mp4Files = new Map<string, string>();
@@ -217,6 +232,7 @@ export async function encodeProfilesToMP4(
codecType,
qualitySettings,
optimizations,
decoderAccel,
(percent) => {
if (onProgress) {
onProgress(profile.name, percent);
@@ -246,6 +262,7 @@ export async function encodeProfilesToMP4(
codecType,
qualitySettings,
optimizations,
decoderAccel,
(percent) => {
if (onProgress) {
onProgress(profile.name, percent);