mirror of
https://github.com/immich-app/immich.git
synced 2026-07-05 20:27:52 -07:00
simplify level picker
This commit is contained in:
@@ -36,28 +36,22 @@ export const getOutputSize = (videoStream: VideoStreamInfo, targetRes: number) =
|
||||
return isVideoVertical(videoStream) ? { width: targetRes, height: larger } : { width: larger, height: targetRes };
|
||||
};
|
||||
|
||||
const pickLevel = (levels: CodecLevel[], frame: number, rate: number): string => {
|
||||
for (const level of levels) {
|
||||
if (frame <= level.maxFrame && rate <= level.maxRate) {
|
||||
return level.token;
|
||||
}
|
||||
}
|
||||
return levels.at(-1)!.token;
|
||||
};
|
||||
const pickLevel = (levels: CodecLevel[], frame: number, rate: number) =>
|
||||
levels.find((level) => frame <= level.maxFrame && rate <= level.maxRate) ?? levels.at(-1)!;
|
||||
|
||||
export const getCodecString = (codec: VideoCodec, width: number, height: number, fps: number): string => {
|
||||
switch (codec) {
|
||||
case VideoCodec.H264: {
|
||||
const macroblocks = Math.ceil(width / 16) * Math.ceil(height / 16);
|
||||
return `avc1.6400${pickLevel(H264_LEVELS, macroblocks, macroblocks * fps)}`;
|
||||
return `avc1.6400${pickLevel(H264_LEVELS, macroblocks, macroblocks * fps).token}`;
|
||||
}
|
||||
case VideoCodec.Hevc: {
|
||||
const samples = width * height;
|
||||
return `hvc1.1.6.${pickLevel(HEVC_LEVELS, samples, samples * fps)}.B0`;
|
||||
return `hvc1.1.6.${pickLevel(HEVC_LEVELS, samples, samples * fps).token}.B0`;
|
||||
}
|
||||
case VideoCodec.Av1: {
|
||||
const samples = width * height;
|
||||
return `av01.0.${pickLevel(AV1_LEVELS, samples, samples * fps)}.08`;
|
||||
return `av01.0.${pickLevel(AV1_LEVELS, samples, samples * fps).token}.08`;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Codec '${codec}' does not support HLS codec strings`);
|
||||
|
||||
Reference in New Issue
Block a user