mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 00:27:40 +00:00
fix(transcode): match target long sides exactly and dynamic resolution mapping
This commit is contained in:
@@ -265,9 +265,12 @@ const TARGET_RESOLUTIONS = [
|
||||
{ name: '360p', longSide: 640 },
|
||||
]
|
||||
|
||||
function getBestMatchResolution(originalWidth: number, originalHeight: number): { name: string; longSide: number } {
|
||||
function getBestMatchResolution(
|
||||
originalWidth: number,
|
||||
originalHeight: number,
|
||||
): { name: string; longSide: number } {
|
||||
const rawLongSide = Math.max(originalWidth, originalHeight)
|
||||
const lower = TARGET_RESOLUTIONS.filter((r) => r.longSide < rawLongSide)
|
||||
const lower = TARGET_RESOLUTIONS.filter((r) => r.longSide <= rawLongSide)
|
||||
if (lower.length > 0) {
|
||||
lower.sort((a, b) => b.longSide - a.longSide)
|
||||
return lower[0]
|
||||
|
||||
@@ -376,10 +376,21 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||
resolution: 'Original',
|
||||
} as DisplayTranscode
|
||||
|
||||
const resolutions: DisplayTranscode[] = (data.media.videoTranscodes ?? []).map((t) => ({
|
||||
...t,
|
||||
resolution: t.isRaw ? 'Original' : `${t.height}p`,
|
||||
}))
|
||||
const resolutions: DisplayTranscode[] = (data.media.videoTranscodes ?? []).map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
let resolution = `${t.height}p`
|
||||
if (longSide >= 3840) resolution = '2160p'
|
||||
else if (longSide >= 1920) resolution = '1080p'
|
||||
else if (longSide >= 1280) resolution = '720p'
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
|
||||
return {
|
||||
...t,
|
||||
resolution: t.isRaw ? 'Original' : resolution,
|
||||
}
|
||||
})
|
||||
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user