mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 19:04:23 +00:00
feat(transcode): add multi-resolution strategy with configurable ladders and fallback (#438)
* feat(transcode): add multi-resolution strategy with configurable ladders and fallback * feat(settings): show toast on settings update and add manual verification plan to PR template * fix(webui): preserve video resolution and fix 480p label in download dropdowns * fix(webui): display standard short-side resolution for vertical videos in seekbar * fix(webui): fix portrait transcode resolution labeling and serialize settings toggles
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React from 'react'
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { BreadcrumbNav } from './breadcrumb-nav'
|
||||
@@ -160,4 +160,107 @@ describe('BreadcrumbNav component', () => {
|
||||
const triggerButton = screen.getByRole('button', { name: 'sample.mov' })
|
||||
expect(triggerButton).toBeDefined()
|
||||
})
|
||||
|
||||
it('displays 480p instead of 360p for 480p video transcode in download menu', () => {
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BreadcrumbNav
|
||||
{...baseProps}
|
||||
fileId="file-1"
|
||||
currentAsset={{ id: 'file-1', name: 'sample.mov', type: 'file', version: 1 }}
|
||||
allowDownload={true}
|
||||
downloadInfo={{
|
||||
originalKey: 'raw.mov',
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'sample-480p.mp4',
|
||||
width: 854,
|
||||
height: 480,
|
||||
hdr: false,
|
||||
},
|
||||
],
|
||||
}}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
const triggerButton = screen.getByRole('button', { name: 'sample.mov' })
|
||||
fireEvent.pointerDown(triggerButton, { button: 0, ctrlKey: false })
|
||||
|
||||
const downloadSubTrigger = screen.getByText('Download')
|
||||
fireEvent.click(downloadSubTrigger)
|
||||
|
||||
const items = screen.getAllByRole('menuitem')
|
||||
expect(items.some((i) => i.textContent?.includes('480p'))).toBe(true)
|
||||
expect(items.some((i) => i.textContent?.includes('360p'))).toBe(false)
|
||||
})
|
||||
|
||||
it('displays explicit resolution when provided in download menu', () => {
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BreadcrumbNav
|
||||
{...baseProps}
|
||||
fileId="file-1"
|
||||
currentAsset={{ id: 'file-1', name: 'sample.mov', type: 'file', version: 1 }}
|
||||
allowDownload={true}
|
||||
downloadInfo={{
|
||||
originalKey: 'raw.mov',
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'sample-480p.mp4',
|
||||
width: 854,
|
||||
height: 480,
|
||||
resolution: '480p',
|
||||
hdr: false,
|
||||
},
|
||||
],
|
||||
}}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
const triggerButton = screen.getByRole('button', { name: 'sample.mov' })
|
||||
fireEvent.pointerDown(triggerButton, { button: 0, ctrlKey: false })
|
||||
|
||||
const downloadSubTrigger = screen.getByText('Download')
|
||||
fireEvent.click(downloadSubTrigger)
|
||||
|
||||
const items = screen.getAllByRole('menuitem')
|
||||
expect(items.some((i) => i.textContent?.includes('480p'))).toBe(true)
|
||||
expect(items.some((i) => i.textContent?.includes('360p'))).toBe(false)
|
||||
})
|
||||
|
||||
it('correctly labels legacy portrait video transcode in download menu using long side fallback', () => {
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BreadcrumbNav
|
||||
{...baseProps}
|
||||
fileId="file-portrait"
|
||||
currentAsset={{ id: 'file-portrait', name: 'portrait.mp4', type: 'file', version: 1 }}
|
||||
allowDownload={true}
|
||||
downloadInfo={{
|
||||
originalKey: 'raw.mp4',
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'portrait-legacy.mp4',
|
||||
width: 1080,
|
||||
height: 1920,
|
||||
hdr: false,
|
||||
},
|
||||
],
|
||||
}}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
const triggerButton = screen.getByRole('button', { name: 'portrait.mp4' })
|
||||
fireEvent.pointerDown(triggerButton, { button: 0, ctrlKey: false })
|
||||
|
||||
const downloadSubTrigger = screen.getByText('Download')
|
||||
fireEvent.click(downloadSubTrigger)
|
||||
|
||||
const items = screen.getAllByRole('menuitem')
|
||||
expect(items.some((i) => i.textContent?.includes('1080p'))).toBe(true)
|
||||
expect(items.some((i) => i.textContent?.includes('1920p'))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -48,6 +48,7 @@ import { useState } from 'react'
|
||||
import { useDualSidebarStore } from '@/ui/stores/dual-sidebar'
|
||||
import { ManageVersionsDialog } from './manage-versions-dialog'
|
||||
import { AssetLinkedTasksDialog } from './kanban/asset-linked-tasks-dialog'
|
||||
import { getVideoResolutionLabel } from '@/ui/lib/media'
|
||||
|
||||
interface BreadcrumbNavProps {
|
||||
teamId: string
|
||||
@@ -84,6 +85,7 @@ interface BreadcrumbNavProps {
|
||||
key: string
|
||||
width: number
|
||||
height: number
|
||||
resolution?: string
|
||||
hdr?: boolean
|
||||
}>
|
||||
}
|
||||
@@ -287,14 +289,7 @@ export function BreadcrumbNav({
|
||||
<DropdownMenuSubContent className="w-48">
|
||||
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
|
||||
{downloadInfo?.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'
|
||||
const resolution = getVideoResolutionLabel(t)
|
||||
const label = t.hdr ? `${resolution} (HDR)` : resolution
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
|
||||
@@ -145,6 +145,7 @@ export function MobileFileDetail({
|
||||
key: t.key,
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
resolution: t.resolution,
|
||||
hdr: t.hdr,
|
||||
})),
|
||||
}
|
||||
|
||||
@@ -119,4 +119,69 @@ describe('MobileFileHeader', () => {
|
||||
expect(menuBtn).toBeDefined()
|
||||
fireEvent.click(menuBtn)
|
||||
})
|
||||
|
||||
it('displays 480p instead of 360p for 480p video transcode in download menu', () => {
|
||||
render(
|
||||
<MobileFileHeader
|
||||
fileName="scene1.mp4"
|
||||
activeFileId="file-1"
|
||||
allowDownload={true}
|
||||
onBack={vi.fn()}
|
||||
downloadInfo={{
|
||||
originalKey: 'raw.mov',
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'scene1-480p.mp4',
|
||||
width: 854,
|
||||
height: 480,
|
||||
resolution: '480p',
|
||||
hdr: false,
|
||||
},
|
||||
],
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
|
||||
const menuBtn = screen.getByLabelText(/More options/i)
|
||||
fireEvent.pointerDown(menuBtn, { button: 0, ctrlKey: false })
|
||||
|
||||
const downloadSubTrigger = screen.getByText('Download')
|
||||
fireEvent.click(downloadSubTrigger)
|
||||
|
||||
const items = screen.getAllByRole('menuitem')
|
||||
expect(items.some((i) => i.textContent?.includes('480p'))).toBe(true)
|
||||
expect(items.some((i) => i.textContent?.includes('360p'))).toBe(false)
|
||||
})
|
||||
|
||||
it('correctly labels legacy portrait video transcode in download menu using long side fallback', () => {
|
||||
render(
|
||||
<MobileFileHeader
|
||||
fileName="portrait.mp4"
|
||||
activeFileId="file-portrait"
|
||||
allowDownload={true}
|
||||
onBack={vi.fn()}
|
||||
downloadInfo={{
|
||||
originalKey: 'raw.mp4',
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'portrait-legacy.mp4',
|
||||
width: 1080,
|
||||
height: 1920,
|
||||
hdr: false,
|
||||
},
|
||||
],
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
|
||||
const menuBtn = screen.getByLabelText(/More options/i)
|
||||
fireEvent.pointerDown(menuBtn, { button: 0, ctrlKey: false })
|
||||
|
||||
const downloadSubTrigger = screen.getByText('Download')
|
||||
fireEvent.click(downloadSubTrigger)
|
||||
|
||||
const items = screen.getAllByRole('menuitem')
|
||||
expect(items.some((i) => i.textContent?.includes('1080p'))).toBe(true)
|
||||
expect(items.some((i) => i.textContent?.includes('1920p'))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
Trash2,
|
||||
} from 'lucide-react'
|
||||
import React from 'react'
|
||||
import { getVideoResolutionLabel } from '@/ui/lib/media'
|
||||
|
||||
export interface MobileFileHeaderProps {
|
||||
fileName: string
|
||||
@@ -46,6 +47,7 @@ export interface MobileFileHeaderProps {
|
||||
key: string
|
||||
width: number
|
||||
height: number
|
||||
resolution?: string
|
||||
hdr?: boolean
|
||||
}>
|
||||
}
|
||||
@@ -238,14 +240,7 @@ export function MobileFileHeader({
|
||||
<DropdownMenuSubContent className="w-48 z-50">
|
||||
<DropdownMenuLabel className="text-xs">{m.download()}</DropdownMenuLabel>
|
||||
{downloadInfo?.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'
|
||||
const resolution = getVideoResolutionLabel(t)
|
||||
const label = t.hdr ? `${resolution} (HDR)` : resolution
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
|
||||
@@ -440,6 +440,7 @@ export function PublicShareManager({
|
||||
key: t.key,
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
resolution: t.resolution,
|
||||
hdr: t.hdr,
|
||||
})),
|
||||
}
|
||||
|
||||
@@ -214,4 +214,95 @@ describe('CompareVideoPane', () => {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('reports 2160p instead of 3840p for 4K vertical video when HLS switches level on Auto', () => {
|
||||
mockHlsInstance.levels = [{ height: 3840, width: 2160, bitrate: 10000000 }]
|
||||
|
||||
const hlsVideo: AssetInfo = {
|
||||
id: 'video-hls-compare-vertical-4k',
|
||||
name: 'vertical-4k.m3u8',
|
||||
proxyType: 'video',
|
||||
media: {
|
||||
isHls: true,
|
||||
hls: {
|
||||
key: 'hls-key',
|
||||
url: 'https://cdn.example.com/master.m3u8',
|
||||
resolutions: [{ width: 2160, height: 3840, resolution: '2160p' }],
|
||||
},
|
||||
metadata: {
|
||||
originalWidth: 2160,
|
||||
originalHeight: 3840,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
},
|
||||
},
|
||||
} as unknown as AssetInfo
|
||||
|
||||
const ref = createRef<ComparePaneHandle>()
|
||||
const reportedStates: PaneReportedState[] = []
|
||||
|
||||
render(
|
||||
<CompareVideoPane
|
||||
ref={ref}
|
||||
file={hlsVideo}
|
||||
isActive={true}
|
||||
annotations={[]}
|
||||
onActivate={vi.fn()}
|
||||
onStateChange={(s) => reportedStates.push(s)}
|
||||
/>,
|
||||
)
|
||||
|
||||
const levelSwitchedHandler = mockHlsInstance.on.mock.calls.find(
|
||||
([event]) => event === 'hlsLevelSwitched',
|
||||
)?.[1]
|
||||
expect(levelSwitchedHandler).toBeDefined()
|
||||
|
||||
act(() => {
|
||||
levelSwitchedHandler('hlsLevelSwitched', { level: 0 })
|
||||
})
|
||||
|
||||
const lastState = reportedStates[reportedStates.length - 1]
|
||||
expect(lastState?.video?.activeAutoResolution).toBe('2160p')
|
||||
})
|
||||
|
||||
it('derives resolution from long side for legacy portrait MP4 transcode without explicit resolution', () => {
|
||||
const legacyPortraitVideo: AssetInfo = {
|
||||
id: 'legacy-portrait-compare-mp4',
|
||||
name: 'portrait.mp4',
|
||||
proxyType: 'video',
|
||||
media: {
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'portrait-1080p.mp4',
|
||||
url: 'https://cdn.example.com/portrait-1080p.mp4',
|
||||
width: 1080,
|
||||
height: 1920,
|
||||
size: 5000000,
|
||||
},
|
||||
],
|
||||
metadata: {
|
||||
originalWidth: 1080,
|
||||
originalHeight: 1920,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
},
|
||||
},
|
||||
} as unknown as AssetInfo
|
||||
|
||||
const reportedStates: PaneReportedState[] = []
|
||||
render(
|
||||
<CompareVideoPane
|
||||
file={legacyPortraitVideo}
|
||||
isActive={true}
|
||||
annotations={[]}
|
||||
onActivate={vi.fn()}
|
||||
onStateChange={(s) => reportedStates.push(s)}
|
||||
/>,
|
||||
)
|
||||
|
||||
const lastState = reportedStates[reportedStates.length - 1]
|
||||
expect(lastState?.video?.resolutions?.[0]?.resolution).toBe('1080p')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useFramePlayer } from './use-frame-player'
|
||||
import { calculateFrameCenterTime, resolveTotalFrames } from './utils'
|
||||
import { clampFrame as clampFrameUtil } from '../../compare/compare-utils'
|
||||
import type { ComparePaneHandle, DisplayTranscode, PaneReportedState } from '../../compare/types'
|
||||
import { getVideoResolutionLabel } from '@/ui/lib/media'
|
||||
|
||||
interface CompareVideoPaneProps {
|
||||
file: AssetInfo
|
||||
@@ -36,20 +37,10 @@ function computeResolutions(file: AssetInfo): DisplayTranscode[] {
|
||||
? (file.media?.hls?.resolutions ?? [])
|
||||
: (file.media?.videoTranscodes ?? [])
|
||||
|
||||
return baseTranscodes.map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
const resCandidate = 'resolution' in t && t.resolution ? t.resolution : undefined
|
||||
let resolution = resCandidate || `${t.height}p`
|
||||
if (!resCandidate) {
|
||||
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 }
|
||||
})
|
||||
return baseTranscodes.map((t) => ({
|
||||
...t,
|
||||
resolution: getVideoResolutionLabel(t),
|
||||
}))
|
||||
}
|
||||
|
||||
function getInitialResolution(resolutions: DisplayTranscode[]): DisplayTranscode | null {
|
||||
@@ -216,7 +207,18 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
hls.on(Hls.Events.LEVEL_SWITCHED, (_event, eventData) => {
|
||||
const level = hls?.levels[eventData.level]
|
||||
if (level) {
|
||||
setActiveAutoResolution(`${level.height}p`)
|
||||
const matched = resolutions.find(
|
||||
(r) => r.width === level.width && r.height === level.height,
|
||||
)
|
||||
if (matched?.resolution) {
|
||||
setActiveAutoResolution(matched.resolution)
|
||||
} else {
|
||||
const shortSide =
|
||||
level.width && level.height
|
||||
? Math.min(level.width, level.height)
|
||||
: level.height || level.width
|
||||
setActiveAutoResolution(shortSide ? `${shortSide}p` : undefined)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -617,7 +619,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
],
|
||||
)
|
||||
|
||||
const displayAnnotations = [...annotations, ...(isActive ? draftAnnotations : [])]
|
||||
const displayAnnotations = [...(annotations ?? []), ...(isActive ? draftAnnotations : [])]
|
||||
|
||||
const scale = zoom
|
||||
const defaultPanX = (containerSize.width - vidW * scale) / 2
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
import { Slider } from '../../ui/slider'
|
||||
import ProgressBar from './progress-bar'
|
||||
import { formatTime, formatTimecode } from './utils'
|
||||
import { getVideoResolutionLabel } from '@/ui/lib/media'
|
||||
|
||||
export interface PlayerState {
|
||||
isPlaying: boolean
|
||||
@@ -431,8 +432,7 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
? data.media.videoTranscodes
|
||||
: resolutions
|
||||
).map((res) => {
|
||||
const resLabel =
|
||||
'resolution' in res && res.resolution ? res.resolution : `${res.height}p`
|
||||
const resLabel = getVideoResolutionLabel(res)
|
||||
const itemKey = res.key || `${resLabel}-${res.hdr ? 'hdr' : 'sdr'}`
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
|
||||
@@ -495,4 +495,75 @@ describe('VideoViewer', () => {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('displays 2160p instead of 3840p for 4K vertical video when HLS switches level on Auto', () => {
|
||||
mockHlsInstance.levels = [{ height: 3840, width: 2160, bitrate: 10000000 }]
|
||||
|
||||
const hlsVideo: AssetInfo = {
|
||||
id: 'video-hls-vertical-4k',
|
||||
name: 'vertical-4k.m3u8',
|
||||
proxyType: 'video',
|
||||
media: {
|
||||
isHls: true,
|
||||
hls: {
|
||||
key: 'hls-key',
|
||||
url: 'https://cdn.example.com/master.m3u8',
|
||||
resolutions: [{ width: 2160, height: 3840, resolution: '2160p' }],
|
||||
},
|
||||
metadata: {
|
||||
originalWidth: 2160,
|
||||
originalHeight: 3840,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
},
|
||||
},
|
||||
} as unknown as AssetInfo
|
||||
|
||||
const { container } = render(<VideoViewer file={hlsVideo} />)
|
||||
|
||||
const levelSwitchedHandler = mockHlsInstance.on.mock.calls.find(
|
||||
([event]) => event === 'hlsLevelSwitched',
|
||||
)?.[1]
|
||||
expect(levelSwitchedHandler).toBeDefined()
|
||||
|
||||
act(() => {
|
||||
levelSwitchedHandler('hlsLevelSwitched', { level: 0 })
|
||||
})
|
||||
|
||||
const settingsButton = container.querySelector('button:has(.lucide-settings)')
|
||||
expect(settingsButton?.textContent).toContain('2160p')
|
||||
expect(settingsButton?.textContent).not.toContain('3840p')
|
||||
})
|
||||
|
||||
it('derives resolution from long side for legacy portrait MP4 transcode without explicit resolution', () => {
|
||||
const legacyPortraitVideo: AssetInfo = {
|
||||
id: 'legacy-portrait-mp4',
|
||||
name: 'portrait.mp4',
|
||||
proxyType: 'video',
|
||||
media: {
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'portrait-1080p.mp4',
|
||||
url: 'https://cdn.example.com/portrait-1080p.mp4',
|
||||
width: 1080,
|
||||
height: 1920,
|
||||
size: 5000000,
|
||||
},
|
||||
],
|
||||
metadata: {
|
||||
originalWidth: 1080,
|
||||
originalHeight: 1920,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
},
|
||||
},
|
||||
} as unknown as AssetInfo
|
||||
|
||||
const { container } = render(<VideoViewer file={legacyPortraitVideo} />)
|
||||
const settingsButton = container.querySelector('button:has(.lucide-settings)')
|
||||
expect(settingsButton?.textContent).toContain('1080p')
|
||||
expect(settingsButton?.textContent).not.toContain('1920p')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import { MobileVideoControlBar } from './mobile-video-control-bar'
|
||||
import { useIsMobile } from '@/ui/hooks/use-mobile'
|
||||
import DrawingCanvas from '@/ui/components/drawing-canvas'
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import { getVideoResolutionLabel } from '@/ui/lib/media'
|
||||
import { FileViewerProps, MediaController } from '../types'
|
||||
import { centeredPan, fitScale, zoomAtPoint } from '../pan-zoom'
|
||||
import { usePanZoomGestures } from '../use-pan-zoom'
|
||||
@@ -39,24 +40,10 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
? (data.media?.hls?.resolutions ?? [])
|
||||
: (data.media?.videoTranscodes ?? [])
|
||||
|
||||
const resolutions: DisplayTranscode[] = baseTranscodes.map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
const resCandidate = 'resolution' in t && t.resolution ? t.resolution : undefined
|
||||
let resolution = resCandidate || `${t.height}p`
|
||||
if (!resCandidate) {
|
||||
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,
|
||||
}
|
||||
})
|
||||
const resolutions: DisplayTranscode[] = baseTranscodes.map((t) => ({
|
||||
...t,
|
||||
resolution: getVideoResolutionLabel(t),
|
||||
}))
|
||||
// Only transcoded proxy versions are ever displayed; the raw original file
|
||||
// is never used as a playback source.
|
||||
const hasMedia = (isHls || resolutions.length > 0) && !!data.media?.metadata
|
||||
@@ -365,8 +352,18 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
hls.on(Hls.Events.LEVEL_SWITCHED, (_event, eventData) => {
|
||||
const level = hls?.levels[eventData.level]
|
||||
if (level) {
|
||||
const h = level.height || Math.min(level.width, level.height)
|
||||
setActiveAutoResolution(h ? `${h}p` : undefined)
|
||||
const matched = resolutions.find(
|
||||
(r) => r.width === level.width && r.height === level.height,
|
||||
)
|
||||
if (matched?.resolution) {
|
||||
setActiveAutoResolution(matched.resolution)
|
||||
} else {
|
||||
const shortSide =
|
||||
level.width && level.height
|
||||
? Math.min(level.width, level.height)
|
||||
: level.height || level.width
|
||||
setActiveAutoResolution(shortSide ? `${shortSide}p` : undefined)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user