docs: обновить readme под новые опции
This commit is contained in:
64
src/cli.ts
64
src/cli.ts
@@ -14,15 +14,14 @@ import { convertToDash, checkFFmpeg, checkMP4Box, getVideoMetadata, detectHardwa
|
||||
import cliProgress from 'cli-progress';
|
||||
import { statSync } from 'node:fs';
|
||||
import { basename, extname } from 'node:path';
|
||||
import type { CodecChoice, StreamingFormatChoice, QualitySettings, HardwareAccelerationOption, HardwareAccelerator } from './types';
|
||||
import type { QualitySettings, HardwareAccelerationOption, HardwareAccelerator, CodecType } from './types';
|
||||
import { selectProfiles, createProfilesFromStrings } from './config/profiles';
|
||||
|
||||
// Parse arguments
|
||||
const args = process.argv.slice(2);
|
||||
let customProfiles: string[] | undefined;
|
||||
let posterTimecode: string | undefined;
|
||||
let codecChoice: CodecChoice = 'auto'; // h264 + AV1 if HW
|
||||
let formatChoice: StreamingFormatChoice = 'auto'; // DASH + HLS
|
||||
let codecChoice: Array<CodecType> | undefined; // default h264
|
||||
const positionalArgs: string[] = [];
|
||||
|
||||
// Quality settings
|
||||
@@ -57,22 +56,16 @@ for (let i = 0; i < args.length; i++) {
|
||||
posterTimecode = args[i + 1];
|
||||
i++; // Skip next arg
|
||||
} else if (args[i] === '-c' || args[i] === '--codec') {
|
||||
const codec = args[i + 1];
|
||||
if (codec === 'av1' || codec === 'h264') {
|
||||
codecChoice = codec;
|
||||
} else {
|
||||
console.error(`❌ Invalid codec: ${codec}. Valid options: av1, h264`);
|
||||
process.exit(1);
|
||||
}
|
||||
i++; // Skip next arg
|
||||
} else if (args[i] === '-f' || args[i] === '--format') {
|
||||
const format = args[i + 1];
|
||||
if (format === 'dash' || format === 'hls') {
|
||||
formatChoice = format;
|
||||
} else {
|
||||
console.error(`❌ Invalid format: ${format}. Valid options: dash, hls`);
|
||||
process.exit(1);
|
||||
const codecArg = args[i + 1];
|
||||
const parts = codecArg.split(/[,\s]+/).map(p => p.trim()).filter(Boolean);
|
||||
const allowed = new Set(['h264', 'av1']);
|
||||
for (const p of parts) {
|
||||
if (!allowed.has(p)) {
|
||||
console.error(`❌ Invalid codec: ${p}. Valid options: av1, h264`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
codecChoice = Array.from(new Set(parts)) as Array<'h264' | 'av1'>;
|
||||
i++; // Skip next arg
|
||||
} else if (args[i] === '--h264-cq') {
|
||||
h264CQ = parseInt(args[i + 1]);
|
||||
@@ -255,29 +248,24 @@ if (!hasMP4Box) {
|
||||
}
|
||||
|
||||
// Resolve codec selection
|
||||
let includeH264 = codecChoice === 'h264' || codecChoice === 'auto';
|
||||
let includeAv1 = codecChoice === 'av1' || codecChoice === 'auto';
|
||||
const codecsRequested = codecChoice && codecChoice.length > 0 ? codecChoice : ['h264'];
|
||||
let includeH264 = codecsRequested.includes('h264');
|
||||
let includeAv1 = codecsRequested.includes('av1');
|
||||
|
||||
if (includeAv1 && !hasAv1Hardware && codecChoice === 'auto') {
|
||||
includeAv1 = false;
|
||||
if (!includeH264) {
|
||||
console.warn('⚠️ H.264 is mandatory for compatibility. Adding H.264.');
|
||||
includeH264 = true;
|
||||
}
|
||||
|
||||
if (codecChoice === 'av1' && !hasAv1Hardware) {
|
||||
console.error(`⚠️ Warning: AV1 encoding requested but no hardware AV1 encoder found.`);
|
||||
if (includeAv1 && !hasAv1Hardware) {
|
||||
console.error(`⚠️ AV1 requested but no hardware AV1 encoder found.`);
|
||||
console.error(` CPU-based AV1 encoding (libsvtav1) will be VERY slow.`);
|
||||
console.error(` Consider using --codec h264 for faster encoding.\n`);
|
||||
}
|
||||
|
||||
// Resolve formats
|
||||
const wantDash = formatChoice === 'dash' || formatChoice === 'auto';
|
||||
const wantHls = formatChoice === 'hls' || formatChoice === 'auto';
|
||||
|
||||
// Validate HLS requires H.264
|
||||
if (wantHls && !includeH264) {
|
||||
console.error(`❌ Error: HLS format requires H.264 codec for Safari/iOS compatibility.`);
|
||||
console.error(` Please use --codec h264 or omit --codec to keep H.264.\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
// Formats are always both
|
||||
const wantDash = true;
|
||||
const wantHls = true;
|
||||
|
||||
// Get video metadata and file size
|
||||
console.log('📊 Analyzing video...\n');
|
||||
@@ -343,7 +331,7 @@ const codecListDisplay = [
|
||||
includeH264 ? 'h264' : null,
|
||||
includeAv1 ? 'av1' : null
|
||||
].filter(Boolean).join(', ');
|
||||
const codecNote = (!includeAv1 && codecChoice === 'auto' && !hasAv1Hardware) ? ' (AV1 disabled: no HW)' : '';
|
||||
const codecNote = (!includeAv1 && codecsRequested.includes('av1')) ? ' (AV1 disabled: no HW)' : '';
|
||||
const bestAccelName = (bestAccel && bestAccel.toUpperCase()) || 'CPU';
|
||||
const bestDecoderName = (bestDecoder && bestDecoder.toUpperCase()) || 'CPU';
|
||||
const plannedAccel = accelerator ? accelerator.toUpperCase() : bestAccelName;
|
||||
@@ -407,8 +395,10 @@ try {
|
||||
outputDir,
|
||||
customProfiles,
|
||||
posterTimecode,
|
||||
codec: codecChoice,
|
||||
format: formatChoice,
|
||||
codec: [
|
||||
...(includeH264 ? ['h264'] as const : []),
|
||||
...(includeAv1 ? ['av1'] as const : [])
|
||||
],
|
||||
segmentDuration: 2,
|
||||
hardwareAccelerator: accelerator,
|
||||
hardwareDecoder: decoder,
|
||||
|
||||
Reference in New Issue
Block a user