add: Фоллбек совместимость HLS

This commit is contained in:
2025-11-11 22:56:44 +03:00
parent 8cf4210d20
commit 3b54c059f0
6 changed files with 900 additions and 31 deletions

View File

@@ -7,7 +7,8 @@ import type {
VideoProfile,
ThumbnailConfig,
ConversionProgress,
CodecType
CodecType,
StreamingFormat
} from '../types';
import {
checkFFmpeg,
@@ -20,7 +21,7 @@ import {
import { selectProfiles, createProfilesFromStrings } from '../config/profiles';
import { generateThumbnailSprite, generatePoster } from './thumbnails';
import { encodeProfilesToMP4 } from './encoding';
import { packageToDash } from './packaging';
import { packageToFormats } from './packaging';
/**
* Convert video to DASH format with NVENC acceleration
@@ -36,6 +37,7 @@ export async function convertToDash(
profiles: userProfiles,
customProfiles,
codec = 'dual',
format = 'both',
useNvenc,
generateThumbnails = true,
thumbnailConfig = {},
@@ -58,6 +60,7 @@ export async function convertToDash(
userProfiles,
customProfiles,
codec,
format,
useNvenc,
generateThumbnails,
thumbnailConfig,
@@ -87,6 +90,7 @@ async function convertToDashInternal(
userProfiles: VideoProfile[] | undefined,
customProfiles: string[] | undefined,
codec: CodecType,
format: StreamingFormat,
useNvenc: boolean | undefined,
generateThumbnails: boolean,
thumbnailConfig: ThumbnailConfig,
@@ -260,15 +264,16 @@ async function convertToDashInternal(
reportProgress('encoding', 65, 'Stage 1 complete: All codecs and profiles encoded');
// STAGE 2: Package to DASH using MP4Box (light work, fast)
reportProgress('encoding', 70, `Stage 2: Creating DASH with MP4Box...`);
// STAGE 2: Package to segments and manifests (unified, no duplication)
reportProgress('encoding', 70, `Stage 2: Creating segments and manifests...`);
const manifestPath = await packageToDash(
const { manifestPath, hlsManifestPath } = await packageToFormats(
codecMP4Paths,
videoOutputDir,
profiles,
segmentDuration,
codec
codec,
format
);
// Collect all video paths from all codecs
@@ -277,7 +282,7 @@ async function convertToDashInternal(
videoPaths.push(...Array.from(mp4Paths.values()));
}
reportProgress('encoding', 80, 'Stage 2 complete: DASH created');
reportProgress('encoding', 80, 'Stage 2 complete: All formats packaged');
// Generate thumbnails
let thumbnailSpritePath: string | undefined;
@@ -321,16 +326,17 @@ async function convertToDashInternal(
reportProgress('thumbnails', 95, 'Poster generated');
}
// Generate MPD manifest
reportProgress('manifest', 95, 'Finalizing manifest...');
// Finalize
reportProgress('manifest', 95, 'Finalizing...');
// Note: manifestPath is already created by MP4Box in packageToDash
// Note: manifestPath/hlsManifestPath are already created by MP4Box in packageToDash/packageToHLS
// No need for separate generateManifest function
reportProgress('complete', 100, 'Conversion complete!');
return {
manifestPath,
hlsManifestPath,
videoPaths,
thumbnailSpritePath,
thumbnailVttPath,
@@ -338,7 +344,8 @@ async function convertToDashInternal(
duration: metadata.duration,
profiles,
usedNvenc: willUseNvenc,
codecType: codec
codecType: codec,
format
};
}