mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 13:47:36 +00:00
feat(transcode): add HDR video proxy support and playback (#424)
* feat(transcode): add HDR output proxy support * fix(transcode): auto-detect MoltenVK Vulkan ICD on macOS for libplacebo filters * fix(transcode): split filter in generateSprite to ensure poster uses tone-mapped stream * docs(changelog): update docs/changelog.mdx and ignore in prettier * fix(transcode): respect video rotation metadata to preserve display aspect ratio * fix(webui): render native video with hardware EDR acceleration instead of 2D canvas * fix(webui): show HDR label on mobile video control bar * fix(share): preserve hdr flag on watermarked video transcodes * fix(webui): differentiate HDR download options in video player * fix(transcode): handle Dolby Vision Profile 5 via standard HDR pipeline without libplacebo * fix(transcode): prepend setparams filter to prevent zscale colorspace path error for DV P5 * refactor(transcode): simplify HDR proxies to always produce HDR without SDR setting
This commit is contained in:
+2
-1
@@ -7,4 +7,5 @@ packages/core/src/generated
|
||||
src/ui/components/ui
|
||||
packages/webui/paraglide
|
||||
*.md
|
||||
**/*.md
|
||||
**/*.md
|
||||
docs/changelog.mdx
|
||||
|
||||
@@ -8,10 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Added
|
||||
|
||||
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
|
||||
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
|
||||
|
||||
### Fixed
|
||||
|
||||
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
|
||||
- **docker**: Fix an issue where the bundled PostgreSQL container published port 5432 on the host, causing deployment to fail on machines where that port was already in use; the database is now only reachable by Shumai itself
|
||||
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: 'Changelog'
|
||||
description: 'Recent updates, new features, and improvements in Shumai'
|
||||
title: "Changelog"
|
||||
description: "Recent updates, new features, and improvements in Shumai"
|
||||
---
|
||||
|
||||
<Update label="v0.4.7" description="September 19, 2026">
|
||||
|
||||
@@ -55,6 +55,7 @@ async function applyWatermarkToAssetMedia(
|
||||
width: vt.width ?? 0,
|
||||
height: vt.height ?? 0,
|
||||
size: 0,
|
||||
hdr: vt.hdr,
|
||||
})),
|
||||
)
|
||||
: []
|
||||
|
||||
@@ -418,6 +418,51 @@ describe('Share API', () => {
|
||||
expect(body.media.imageTranscodes).toEqual([])
|
||||
})
|
||||
|
||||
test('serves watermarked transcodes with hdr flags preserved when watermark enabled and completed', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
|
||||
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(
|
||||
new Map([
|
||||
[
|
||||
'file1',
|
||||
watermarkMediaInfo({
|
||||
videoTranscodes: [
|
||||
{ key: 'files/watermarked-1080p.mp4', width: 1920, height: 1080, hdr: false },
|
||||
{ key: 'files/watermarked-1080p-hdr.mp4', width: 1920, height: 1080, hdr: true },
|
||||
],
|
||||
}),
|
||||
],
|
||||
]),
|
||||
)
|
||||
|
||||
const res = await app.request('/shares/share1/files/file1', {
|
||||
method: 'GET',
|
||||
headers: { 'x-share-password': 'pass' },
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.media.videoTranscodes).toEqual([
|
||||
{
|
||||
id: 'files/watermarked-1080p.mp4',
|
||||
url: 'http://s3/presigned',
|
||||
key: 'files/watermarked-1080p.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
size: 0,
|
||||
hdr: false,
|
||||
},
|
||||
{
|
||||
id: 'files/watermarked-1080p-hdr.mp4',
|
||||
url: 'http://s3/presigned',
|
||||
key: 'files/watermarked-1080p-hdr.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
size: 0,
|
||||
hdr: true,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test('serves empty transcode arrays while watermark transcoding is in flight', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
|
||||
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
|
||||
|
||||
@@ -365,7 +365,15 @@ describe('TeamService', () => {
|
||||
})
|
||||
|
||||
const settings = await teamService.getSettings(team.id)
|
||||
expect(settings).toEqual({ semanticSearchEnabled: false, appearance: { hideAgent: false } })
|
||||
expect(settings).toEqual({
|
||||
semanticSearchEnabled: false,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
hardwareAcceleration: 'off',
|
||||
threads: 0,
|
||||
},
|
||||
appearance: { hideAgent: false },
|
||||
})
|
||||
|
||||
await teamService.updateSettings(team.id, 'theme', 'dark')
|
||||
|
||||
@@ -373,6 +381,11 @@ describe('TeamService', () => {
|
||||
expect(newSettings).toEqual({
|
||||
theme: 'dark',
|
||||
semanticSearchEnabled: false,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
hardwareAcceleration: 'off',
|
||||
threads: 0,
|
||||
},
|
||||
appearance: { hideAgent: false },
|
||||
})
|
||||
|
||||
@@ -384,7 +397,11 @@ describe('TeamService', () => {
|
||||
const finalSettings = await teamService.getSettings(team.id)
|
||||
expect(finalSettings).toEqual({
|
||||
theme: 'dark',
|
||||
transcode: { videoStrategy: 'all', hardwareAcceleration: 'auto', threads: 4 },
|
||||
transcode: {
|
||||
videoStrategy: 'all',
|
||||
hardwareAcceleration: 'auto',
|
||||
threads: 4,
|
||||
},
|
||||
appearance: { hideAgent: true },
|
||||
semanticSearchEnabled: false,
|
||||
})
|
||||
|
||||
@@ -33,7 +33,11 @@ export class TeamService {
|
||||
data: {
|
||||
name: 'Default Team',
|
||||
settings: {
|
||||
transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off', threads: 0 },
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
hardwareAcceleration: 'off',
|
||||
threads: 0,
|
||||
},
|
||||
},
|
||||
sandbox: { create: {} },
|
||||
},
|
||||
@@ -301,6 +305,14 @@ export class TeamService {
|
||||
})
|
||||
settings.semanticSearchEnabled = !!embeddingAgent
|
||||
|
||||
if (!settings.transcode) {
|
||||
settings.transcode = {
|
||||
videoStrategy: 'best_match',
|
||||
hardwareAcceleration: 'off',
|
||||
threads: 0,
|
||||
}
|
||||
}
|
||||
|
||||
if (!settings.appearance) {
|
||||
settings.appearance = { hideAgent: false }
|
||||
} else if (settings.appearance.hideAgent === undefined) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
getDefaultBitrateBps,
|
||||
calculateMaxBitrate,
|
||||
H264_ENCODER_CONFIGS,
|
||||
buildSdrToneMapFilterChain,
|
||||
} from './transcode'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import * as path from 'path'
|
||||
@@ -1813,4 +1814,477 @@ describe('TranscodeService', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('HDR detection, tone mapping, and transcoding', () => {
|
||||
it('buildSdrToneMapFilterChain constructs zscale + tonemap filter chain for PQ and HLG', () => {
|
||||
const available = new Set(['zscale', 'tonemap'])
|
||||
const pqChain = buildSdrToneMapFilterChain({
|
||||
hdrType: 'pq',
|
||||
availableFilters: available,
|
||||
})
|
||||
expect(pqChain).toContain(
|
||||
'setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc',
|
||||
)
|
||||
expect(pqChain).toContain('zscale=tin=smpte2084:pin=bt2020:min=bt2020nc')
|
||||
expect(pqChain).toContain('tonemap=tonemap=hable:desat=0:peak=100')
|
||||
expect(pqChain).toContain('format=yuv420p')
|
||||
|
||||
const hlgChain = buildSdrToneMapFilterChain({
|
||||
hdrType: 'hlg',
|
||||
availableFilters: available,
|
||||
})
|
||||
expect(hlgChain).toContain(
|
||||
'setparams=color_primaries=bt2020:color_trc=arib-std-b67:colorspace=bt2020nc',
|
||||
)
|
||||
expect(hlgChain).toContain('zscale=tin=arib-std-b67:pin=bt2020:min=bt2020nc')
|
||||
expect(hlgChain).toContain('tonemap=tonemap=hable')
|
||||
})
|
||||
|
||||
it('buildSdrToneMapFilterChain throws error if zscale or tonemap is missing for PQ/HLG', () => {
|
||||
expect(() =>
|
||||
buildSdrToneMapFilterChain({
|
||||
hdrType: 'pq',
|
||||
availableFilters: new Set(['zscale']),
|
||||
}),
|
||||
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
|
||||
|
||||
expect(() =>
|
||||
buildSdrToneMapFilterChain({
|
||||
hdrType: 'hlg',
|
||||
availableFilters: new Set(['tonemap']),
|
||||
}),
|
||||
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
|
||||
})
|
||||
|
||||
it('buildSdrToneMapFilterChain constructs zscale + tonemap filter chain for Dolby Vision Profile 5', () => {
|
||||
const chain = buildSdrToneMapFilterChain({
|
||||
hdrType: 'dovi_p5',
|
||||
availableFilters: new Set(['zscale', 'tonemap']),
|
||||
})
|
||||
expect(chain).toContain(
|
||||
'setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc',
|
||||
)
|
||||
expect(chain).toContain('tin=smpte2084')
|
||||
expect(chain).toContain('tonemap=tonemap=hable')
|
||||
expect(chain).toContain('m=bt709')
|
||||
})
|
||||
|
||||
it('buildSdrToneMapFilterChain throws error if zscale or tonemap is missing for Dolby Vision Profile 5', () => {
|
||||
expect(() =>
|
||||
buildSdrToneMapFilterChain({
|
||||
hdrType: 'dovi_p5',
|
||||
availableFilters: new Set(['tonemap']),
|
||||
}),
|
||||
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
|
||||
})
|
||||
|
||||
const mockExecFileStdout = (mockOutput: string) => {
|
||||
;(
|
||||
child_process.execFile as unknown as {
|
||||
mockImplementation: (
|
||||
fn: (
|
||||
file: string,
|
||||
args: string[],
|
||||
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
|
||||
) => unknown,
|
||||
) => void
|
||||
}
|
||||
).mockImplementation((_file, _args, cb) => {
|
||||
cb(null, { stdout: mockOutput, stderr: '' })
|
||||
})
|
||||
}
|
||||
|
||||
it('getVideoInfo detects PQ HDR from smpte2084 color_transfer', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '20000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'hevc',
|
||||
width: 3840,
|
||||
height: 2160,
|
||||
r_frame_rate: '24/1',
|
||||
color_transfer: 'smpte2084',
|
||||
color_primaries: 'bt2020',
|
||||
color_space: 'bt2020nc',
|
||||
bits_per_raw_sample: '10',
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('hdr-pq.mp4')
|
||||
expect(info.isHdr).toBe(true)
|
||||
expect(info.hdrType).toBe('pq')
|
||||
expect(info.colorTransfer).toBe('smpte2084')
|
||||
})
|
||||
|
||||
it('getVideoInfo detects HLG HDR from arib-std-b67 color_transfer', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '20000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'hevc',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
r_frame_rate: '30/1',
|
||||
color_transfer: 'arib-std-b67',
|
||||
color_primaries: 'bt2020',
|
||||
color_space: 'bt2020nc',
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('hdr-hlg.mp4')
|
||||
expect(info.isHdr).toBe(true)
|
||||
expect(info.hdrType).toBe('hlg')
|
||||
expect(info.colorTransfer).toBe('arib-std-b67')
|
||||
})
|
||||
|
||||
it('getVideoInfo treats 10-bit Rec.709 with BT.709 transfer as SDR', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '20000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'h264',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
r_frame_rate: '24/1',
|
||||
color_transfer: 'bt709',
|
||||
color_primaries: 'bt709',
|
||||
color_space: 'bt709',
|
||||
bits_per_raw_sample: '10',
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('10bit-sdr.mp4')
|
||||
expect(info.isHdr).toBe(false)
|
||||
expect(info.hdrType).toBe('sdr')
|
||||
})
|
||||
|
||||
it('getVideoInfo detects Dolby Vision Profile 5 via side data', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '25000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'hevc',
|
||||
width: 3840,
|
||||
height: 2160,
|
||||
r_frame_rate: '24/1',
|
||||
side_data_list: [
|
||||
{
|
||||
side_data_type: 'DOVI configuration record',
|
||||
dv_profile: 5,
|
||||
dv_level: 6,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('dovi-p5.mp4')
|
||||
expect(info.isHdr).toBe(true)
|
||||
expect(info.hdrType).toBe('dovi_p5')
|
||||
expect(info.dvProfile).toBe(5)
|
||||
})
|
||||
|
||||
it('getVideoInfo treats Dolby Vision Profile 8 with BT.709 transfer as SDR', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '25000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'hevc',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
r_frame_rate: '24/1',
|
||||
color_transfer: 'bt709',
|
||||
color_primaries: 'bt709',
|
||||
color_space: 'bt709',
|
||||
side_data_list: [
|
||||
{
|
||||
side_data_type: 'DOVI configuration record',
|
||||
dv_profile: 8,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('dovi-p8-sdr.mp4')
|
||||
expect(info.isHdr).toBe(false)
|
||||
expect(info.hdrType).toBe('sdr')
|
||||
expect(info.dvProfile).toBe(8)
|
||||
})
|
||||
|
||||
it('getVideoInfo swaps width and height when Display Matrix side data has rotation -90', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '20000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'hevc',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
r_frame_rate: '30/1',
|
||||
side_data_list: [
|
||||
{
|
||||
side_data_type: 'Display Matrix',
|
||||
rotation: -90,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('vertical-display-matrix.mp4')
|
||||
expect(info.originalWidth).toBe(1080)
|
||||
expect(info.originalHeight).toBe(1920)
|
||||
expect(info.rotation).toBe(-90)
|
||||
})
|
||||
|
||||
it('getVideoInfo swaps width and height when tags.rotate is 90 or 270', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '20000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'h264',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
r_frame_rate: '30/1',
|
||||
tags: {
|
||||
rotate: '90',
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('vertical-tag.mp4')
|
||||
expect(info.originalWidth).toBe(1080)
|
||||
expect(info.originalHeight).toBe(1920)
|
||||
expect(info.rotation).toBe(90)
|
||||
})
|
||||
|
||||
it('getVideoInfo preserves width and height when rotation is 180 degrees', async () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const mockOutput = JSON.stringify({
|
||||
format: { duration: '10.0', bit_rate: '20000000' },
|
||||
streams: [
|
||||
{
|
||||
codec_type: 'video',
|
||||
codec_name: 'h264',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
r_frame_rate: '30/1',
|
||||
tags: {
|
||||
rotate: '180',
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
mockExecFileStdout(mockOutput)
|
||||
|
||||
const info = await transcodeService.getVideoInfo('upside-down.mp4')
|
||||
expect(info.originalWidth).toBe(1920)
|
||||
expect(info.originalHeight).toBe(1080)
|
||||
expect(info.rotation).toBe(180)
|
||||
})
|
||||
|
||||
it('transcodeVideo preserves HDR parameters and tags when hdr is true', async () => {
|
||||
let executedArgs: string[] = []
|
||||
;(
|
||||
child_process.execFile as unknown as {
|
||||
mockImplementation: (
|
||||
fn: (
|
||||
file: string,
|
||||
args: string[],
|
||||
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
|
||||
) => unknown,
|
||||
) => void
|
||||
}
|
||||
).mockImplementation((_file, args, cb) => {
|
||||
if (args.includes('-filters')) {
|
||||
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
|
||||
return {}
|
||||
}
|
||||
if (args.includes('-encoders')) {
|
||||
cb(null, { stdout: ' V..... libx264 ', stderr: '' })
|
||||
return {}
|
||||
}
|
||||
executedArgs = args
|
||||
cb(null, { stdout: '', stderr: '' })
|
||||
return {}
|
||||
})
|
||||
|
||||
const outputFile = path.join(tempDir, 'hdr_output.mp4')
|
||||
await transcodeService.transcodeVideo({
|
||||
inputFile: 'hdr_input.mp4',
|
||||
outputFile,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: true,
|
||||
sourceIsHdr: true,
|
||||
sourceHdrType: 'pq',
|
||||
sourceColorTransfer: 'smpte2084',
|
||||
})
|
||||
|
||||
expect(executedArgs).toContain('-color_primaries')
|
||||
expect(executedArgs).toContain('bt2020')
|
||||
expect(executedArgs).toContain('-color_trc')
|
||||
expect(executedArgs).toContain('smpte2084')
|
||||
expect(executedArgs).toContain('-colorspace')
|
||||
expect(executedArgs).toContain('bt2020nc')
|
||||
expect(executedArgs).toContain('-x264-params')
|
||||
expect(executedArgs).toContain('colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc')
|
||||
})
|
||||
|
||||
it('transcodeVideo transcodes Dolby Vision Profile 5 to HDR proxy without libplacebo', async () => {
|
||||
let executedArgs: string[] = []
|
||||
;(
|
||||
child_process.execFile as unknown as {
|
||||
mockImplementation: (
|
||||
fn: (
|
||||
file: string,
|
||||
args: string[],
|
||||
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
|
||||
) => unknown,
|
||||
) => void
|
||||
}
|
||||
).mockImplementation((_file, args, cb) => {
|
||||
if (args.includes('-filters')) {
|
||||
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
|
||||
return {}
|
||||
}
|
||||
if (args.includes('-encoders')) {
|
||||
cb(null, { stdout: ' V..... libx264 ', stderr: '' })
|
||||
return {}
|
||||
}
|
||||
executedArgs = args
|
||||
cb(null, { stdout: '', stderr: '' })
|
||||
return {}
|
||||
})
|
||||
|
||||
const outputFile = path.join(tempDir, 'dovi_p5_hdr.mp4')
|
||||
await transcodeService.transcodeVideo({
|
||||
inputFile: 'dovi_p5_input.mp4',
|
||||
outputFile,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: true,
|
||||
sourceIsHdr: true,
|
||||
sourceHdrType: 'dovi_p5',
|
||||
})
|
||||
|
||||
const filterIdx = executedArgs.indexOf('-filter_complex')
|
||||
expect(filterIdx).toBeGreaterThan(-1)
|
||||
const filterComplex = executedArgs[filterIdx + 1]
|
||||
expect(filterComplex).not.toContain('libplacebo')
|
||||
expect(executedArgs).toContain('-color_primaries')
|
||||
expect(executedArgs).toContain('bt2020')
|
||||
expect(executedArgs).toContain('-color_trc')
|
||||
expect(executedArgs).toContain('smpte2084')
|
||||
})
|
||||
|
||||
it('generateSprite uses split=2 filterComplex for HDR inputs', async () => {
|
||||
let executedArgs: string[] = []
|
||||
;(
|
||||
child_process.execFile as unknown as {
|
||||
mockImplementation: (
|
||||
fn: (
|
||||
file: string,
|
||||
args: string[],
|
||||
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
|
||||
) => unknown,
|
||||
) => void
|
||||
}
|
||||
).mockImplementation((_file, args, cb) => {
|
||||
if (args.includes('-filters')) {
|
||||
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
|
||||
return {}
|
||||
}
|
||||
executedArgs = args
|
||||
cb(null, { stdout: '', stderr: '' })
|
||||
return {}
|
||||
})
|
||||
|
||||
const spritePath = path.join(tempDir, 'sprite.webp')
|
||||
const posterPath = path.join(tempDir, 'poster.webp')
|
||||
await transcodeService.generateSprite('input.mp4', spritePath, posterPath, 100, undefined, {
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
})
|
||||
|
||||
const filterIdx = executedArgs.indexOf('-filter_complex')
|
||||
expect(filterIdx).toBeGreaterThan(-1)
|
||||
const filterStr = executedArgs[filterIdx + 1]
|
||||
expect(filterStr).toContain('split=2[v_sprite][v_thumb]')
|
||||
expect(filterStr).toContain('[v_sprite]fps=')
|
||||
expect(filterStr).toContain('[v_thumb]scale=')
|
||||
})
|
||||
|
||||
it('generateSprite uses split=2 filterComplex for SDR inputs', async () => {
|
||||
let executedArgs: string[] = []
|
||||
;(
|
||||
child_process.execFile as unknown as {
|
||||
mockImplementation: (
|
||||
fn: (
|
||||
file: string,
|
||||
args: string[],
|
||||
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
|
||||
) => unknown,
|
||||
) => void
|
||||
}
|
||||
).mockImplementation((_file, args, cb) => {
|
||||
executedArgs = args
|
||||
cb(null, { stdout: '', stderr: '' })
|
||||
return {}
|
||||
})
|
||||
|
||||
const spritePath = path.join(tempDir, 'sprite.webp')
|
||||
const posterPath = path.join(tempDir, 'poster.webp')
|
||||
await transcodeService.generateSprite('input.mp4', spritePath, posterPath, 100)
|
||||
|
||||
const filterIdx = executedArgs.indexOf('-filter_complex')
|
||||
expect(filterIdx).toBeGreaterThan(-1)
|
||||
const filterStr = executedArgs[filterIdx + 1]
|
||||
expect(filterStr).toContain('[0:v]split=2[v_sprite][v_thumb]')
|
||||
expect(filterStr).toContain('[v_sprite]fps=')
|
||||
expect(filterStr).toContain('[v_thumb]scale=')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -87,6 +87,8 @@ export function parseCsvContent(content: string): string[][] {
|
||||
}
|
||||
}
|
||||
|
||||
export type HdrType = 'pq' | 'hlg' | 'dovi_p5' | 'dovi_p8' | 'sdr'
|
||||
|
||||
export interface MediaMetadata {
|
||||
originalWidth: number
|
||||
originalHeight: number
|
||||
@@ -103,6 +105,14 @@ export interface MediaMetadata {
|
||||
audioSampleRate?: number
|
||||
audioBitDepth?: number
|
||||
mimeType: string
|
||||
colorTransfer?: string
|
||||
colorPrimaries?: string
|
||||
colorSpace?: string
|
||||
isHdr?: boolean
|
||||
hdrType?: HdrType
|
||||
dvProfile?: number
|
||||
dvCompatibilityId?: number
|
||||
rotation?: number
|
||||
}
|
||||
|
||||
export interface TranscodeVideoParams {
|
||||
@@ -118,6 +128,12 @@ export interface TranscodeVideoParams {
|
||||
sourceVideoBitrate?: number
|
||||
threads?: number
|
||||
signal?: AbortSignal
|
||||
hdr?: boolean
|
||||
sourceIsHdr?: boolean
|
||||
sourceHdrType?: HdrType
|
||||
sourceColorTransfer?: string
|
||||
sourceColorPrimaries?: string
|
||||
sourceColorSpace?: string
|
||||
}
|
||||
|
||||
export interface EncoderConfig {
|
||||
@@ -224,6 +240,24 @@ export function calculateMaxBitrate(
|
||||
}
|
||||
}
|
||||
|
||||
export function buildSdrToneMapFilterChain(options: {
|
||||
hdrType?: HdrType
|
||||
availableFilters?: Set<string>
|
||||
colorTransfer?: string
|
||||
}): string {
|
||||
if (options.availableFilters) {
|
||||
if (!options.availableFilters.has('zscale') || !options.availableFilters.has('tonemap')) {
|
||||
throw new Error('zscale and tonemap filters are required for HDR tone mapping')
|
||||
}
|
||||
}
|
||||
|
||||
const tin =
|
||||
options.hdrType === 'hlg' || options.colorTransfer === 'arib-std-b67'
|
||||
? 'arib-std-b67'
|
||||
: 'smpte2084'
|
||||
return `setparams=color_primaries=bt2020:color_trc=${tin}:colorspace=bt2020nc,zscale=tin=${tin}:pin=bt2020:min=bt2020nc:t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0:peak=100,zscale=t=bt709:m=bt709:out_range=full,format=yuv420p`
|
||||
}
|
||||
|
||||
export interface ExtractVideoFramesParams {
|
||||
inputFile: string
|
||||
outputDir: string
|
||||
@@ -432,9 +466,101 @@ export class TranscodeService {
|
||||
}
|
||||
}
|
||||
|
||||
const colorTransfer =
|
||||
typeof videoStream.color_transfer === 'string'
|
||||
? videoStream.color_transfer.toLowerCase()
|
||||
: undefined
|
||||
const colorPrimaries =
|
||||
typeof videoStream.color_primaries === 'string'
|
||||
? videoStream.color_primaries.toLowerCase()
|
||||
: undefined
|
||||
const colorSpace =
|
||||
typeof videoStream.color_space === 'string'
|
||||
? videoStream.color_space.toLowerCase()
|
||||
: undefined
|
||||
|
||||
let dvProfile: number | undefined
|
||||
let dvCompatibilityId: number | undefined
|
||||
|
||||
if (Array.isArray(videoStream.side_data_list)) {
|
||||
const dovi = videoStream.side_data_list.find(
|
||||
(sd: unknown): sd is Record<string, unknown> =>
|
||||
typeof (sd as Record<string, unknown>)?.side_data_type === 'string' &&
|
||||
String((sd as Record<string, unknown>).side_data_type)
|
||||
.toLowerCase()
|
||||
.includes('dovi'),
|
||||
)
|
||||
if (dovi) {
|
||||
dvProfile = this.safeParseInt(dovi.dv_profile)
|
||||
dvCompatibilityId = this.safeParseInt(dovi.dv_bl_signal_compatibility_id)
|
||||
}
|
||||
}
|
||||
|
||||
let isHdr: boolean
|
||||
let hdrType: HdrType
|
||||
|
||||
if (dvProfile === 5) {
|
||||
isHdr = true
|
||||
hdrType = 'dovi_p5'
|
||||
} else if (dvProfile !== undefined) {
|
||||
if (colorTransfer === 'smpte2084') {
|
||||
isHdr = true
|
||||
hdrType = 'pq'
|
||||
} else if (colorTransfer === 'arib-std-b67') {
|
||||
isHdr = true
|
||||
hdrType = 'hlg'
|
||||
} else {
|
||||
isHdr = false
|
||||
hdrType = 'sdr'
|
||||
}
|
||||
} else {
|
||||
if (colorTransfer === 'smpte2084') {
|
||||
isHdr = true
|
||||
hdrType = 'pq'
|
||||
} else if (colorTransfer === 'arib-std-b67') {
|
||||
isHdr = true
|
||||
hdrType = 'hlg'
|
||||
} else {
|
||||
isHdr = false
|
||||
hdrType = 'sdr'
|
||||
}
|
||||
}
|
||||
|
||||
let rotation = 0
|
||||
|
||||
if (Array.isArray(videoStream.side_data_list)) {
|
||||
const displayMatrix = videoStream.side_data_list.find(
|
||||
(sd: unknown): sd is Record<string, unknown> =>
|
||||
typeof (sd as Record<string, unknown>)?.side_data_type === 'string' &&
|
||||
String((sd as Record<string, unknown>).side_data_type).toLowerCase() === 'display matrix',
|
||||
)
|
||||
if (displayMatrix && typeof displayMatrix.rotation === 'number') {
|
||||
rotation = displayMatrix.rotation
|
||||
}
|
||||
}
|
||||
|
||||
if (!rotation) {
|
||||
const rotateTag = videoStream.tags?.rotate || info.format?.tags?.rotate
|
||||
if (rotateTag) {
|
||||
const parsed = parseFloat(rotateTag)
|
||||
if (Number.isFinite(parsed)) {
|
||||
rotation = parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedRotation = ((Math.round(rotation) % 360) + 360) % 360
|
||||
const isRotatedVertical = normalizedRotation === 90 || normalizedRotation === 270
|
||||
|
||||
const rawWidth = typeof videoStream.width === 'number' ? videoStream.width : 0
|
||||
const rawHeight = typeof videoStream.height === 'number' ? videoStream.height : 0
|
||||
const originalWidth = isRotatedVertical ? rawHeight : rawWidth
|
||||
const originalHeight = isRotatedVertical ? rawWidth : rawHeight
|
||||
|
||||
return {
|
||||
originalWidth: videoStream.width,
|
||||
originalHeight: videoStream.height,
|
||||
originalWidth,
|
||||
originalHeight,
|
||||
rotation: rotation || undefined,
|
||||
duration,
|
||||
bitRate: parseFloat(info.format.bit_rate),
|
||||
videoBitRate,
|
||||
@@ -450,6 +576,13 @@ export class TranscodeService {
|
||||
this.safeParseInt(audioStream?.bits_per_raw_sample) ??
|
||||
this.safeParseInt(audioStream?.bits_per_sample),
|
||||
mimeType: '',
|
||||
colorTransfer,
|
||||
colorPrimaries,
|
||||
colorSpace,
|
||||
isHdr,
|
||||
hdrType,
|
||||
dvProfile,
|
||||
dvCompatibilityId,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,6 +672,34 @@ export class TranscodeService {
|
||||
}
|
||||
}
|
||||
|
||||
private availableFiltersCache: Set<string> | null = null
|
||||
|
||||
clearFiltersCache(): void {
|
||||
this.availableFiltersCache = null
|
||||
}
|
||||
|
||||
async getAvailableFilters(): Promise<Set<string>> {
|
||||
if (this.availableFiltersCache) {
|
||||
return this.availableFiltersCache
|
||||
}
|
||||
try {
|
||||
const { stdout } = await execFileAsync('ffmpeg', ['-filters'])
|
||||
const filters = new Set<string>()
|
||||
const lines = stdout.split('\n')
|
||||
for (const line of lines) {
|
||||
const match = line.match(/^\s*[A-Z.]{2,4}\s+([a-zA-Z0-9_-]+)/)
|
||||
if (match) {
|
||||
filters.add(match[1])
|
||||
}
|
||||
}
|
||||
this.availableFiltersCache = filters
|
||||
return filters
|
||||
} catch (err) {
|
||||
console.warn('Failed to probe ffmpeg filters:', err)
|
||||
return new Set<string>()
|
||||
}
|
||||
}
|
||||
|
||||
async selectH264Encoder(
|
||||
hardwareAcceleration?: 'off' | 'auto',
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
@@ -559,14 +720,22 @@ export class TranscodeService {
|
||||
}
|
||||
|
||||
async transcodeVideo(params: TranscodeVideoParams): Promise<void> {
|
||||
const isSourceHdr =
|
||||
params.sourceIsHdr ||
|
||||
params.sourceHdrType === 'pq' ||
|
||||
params.sourceHdrType === 'hlg' ||
|
||||
params.sourceHdrType === 'dovi_p5'
|
||||
const isHdrOutput = Boolean(params.hdr)
|
||||
|
||||
let filterComplex: string
|
||||
const args: string[] = ['-i', params.inputFile]
|
||||
const baseScale = `scale=w=${params.width}:h=${params.height}:force_original_aspect_ratio=decrease,scale=w='trunc(iw/2)*2':h='trunc(ih/2)*2'`
|
||||
|
||||
if (params.overlayFile) {
|
||||
args.push('-i', params.overlayFile)
|
||||
filterComplex = `[0:v]scale=${params.width}:${params.height}[vscaled];[vscaled][1:v]overlay=0:0`
|
||||
} else {
|
||||
filterComplex = `[0:v]scale=w=${params.width}:h=${params.height}:force_original_aspect_ratio=decrease,scale=w='trunc(iw/2)*2':h='trunc(ih/2)*2'`
|
||||
filterComplex = `[0:v]${baseScale}`
|
||||
}
|
||||
|
||||
if (params.frameRate) {
|
||||
@@ -625,6 +794,15 @@ export class TranscodeService {
|
||||
|
||||
args.push('-pix_fmt', 'yuv420p')
|
||||
|
||||
if (isSourceHdr && isHdrOutput) {
|
||||
const isHlg = params.sourceHdrType === 'hlg' || params.sourceColorTransfer === 'arib-std-b67'
|
||||
const trc = isHlg ? 'arib-std-b67' : 'smpte2084'
|
||||
args.push('-color_primaries', 'bt2020', '-color_trc', trc, '-colorspace', 'bt2020nc')
|
||||
if (encoder.name === 'libx264') {
|
||||
args.push('-x264-params', `colorprim=bt2020:transfer=${trc}:colormatrix=bt2020nc`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!params.disableAudio) {
|
||||
args.push('-c:a', 'aac', '-b:a', '128k')
|
||||
}
|
||||
@@ -749,9 +927,22 @@ export class TranscodeService {
|
||||
outputPoster: string,
|
||||
duration: number,
|
||||
signal?: AbortSignal,
|
||||
hdrOptions?: { isHdr?: boolean; hdrType?: HdrType; colorTransfer?: string },
|
||||
): Promise<void> {
|
||||
const spriteFps = 100 / duration
|
||||
const filterComplex = `[0:v]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[0:v]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
|
||||
let filterComplex: string
|
||||
|
||||
if (hdrOptions?.isHdr) {
|
||||
const availableFilters = await this.getAvailableFilters()
|
||||
const tonemap = buildSdrToneMapFilterChain({
|
||||
hdrType: hdrOptions.hdrType,
|
||||
colorTransfer: hdrOptions.colorTransfer,
|
||||
availableFilters,
|
||||
})
|
||||
filterComplex = `[0:v]${tonemap},split=2[v_sprite][v_thumb];[v_sprite]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[v_thumb]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
|
||||
} else {
|
||||
filterComplex = `[0:v]split=2[v_sprite][v_thumb];[v_sprite]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[v_thumb]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
|
||||
}
|
||||
|
||||
const args = [
|
||||
'-i',
|
||||
|
||||
@@ -50,6 +50,7 @@ declare global {
|
||||
// ----------------------------------------------------------------------
|
||||
export type VideoTranscodeStrategy = 'best_match' | 'all'
|
||||
export type HardwareAcceleration = 'off' | 'auto'
|
||||
export type HdrType = 'pq' | 'hlg' | 'dovi_p5' | 'dovi_p8' | 'sdr'
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Collection Filter
|
||||
@@ -104,6 +105,7 @@ declare global {
|
||||
width: number
|
||||
height: number
|
||||
resolution?: string
|
||||
hdr?: boolean
|
||||
}
|
||||
|
||||
export interface ImageTranscode {
|
||||
@@ -130,6 +132,7 @@ declare global {
|
||||
export interface Metadata {
|
||||
originalHeight: number
|
||||
originalWidth: number
|
||||
rotation?: number
|
||||
hasAudio: boolean
|
||||
duration: number
|
||||
bitRate: number
|
||||
@@ -142,6 +145,12 @@ declare global {
|
||||
audioChannels?: number
|
||||
audioSampleRate?: number
|
||||
audioBitDepth?: number
|
||||
colorTransfer?: string
|
||||
colorPrimaries?: string
|
||||
colorSpace?: string
|
||||
isHdr?: boolean
|
||||
hdrType?: HdrType
|
||||
dvProfile?: number
|
||||
format: unknown
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ export const previewInfoSchema = z.object({
|
||||
thumbnailUrl: z.string().optional(),
|
||||
originalHeight: z.number().optional(),
|
||||
originalWidth: z.number().optional(),
|
||||
rotation: z.number().optional(),
|
||||
spriteUrl: z.string().optional(),
|
||||
duration: z.number().optional(),
|
||||
pageCount: z.number().optional(),
|
||||
@@ -60,6 +61,7 @@ export const mediaMetadataSchema = z.object({
|
||||
duration: z.number().optional(),
|
||||
originalWidth: z.number().optional(),
|
||||
originalHeight: z.number().optional(),
|
||||
rotation: z.number().optional(),
|
||||
frameRate: z.number().optional(),
|
||||
totalFrames: z.number().optional(),
|
||||
startTimecode: z.string().optional(),
|
||||
@@ -103,6 +105,7 @@ export const assetInfoSchema = z.object({
|
||||
width: z.number(),
|
||||
height: z.number(),
|
||||
size: z.number(),
|
||||
hdr: z.boolean().optional(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
@@ -335,6 +338,7 @@ export interface VideoTranscode {
|
||||
width: number
|
||||
height: number
|
||||
size: number
|
||||
hdr?: boolean
|
||||
}
|
||||
|
||||
export const postAttachmentRequestSchema = z.object({
|
||||
|
||||
@@ -75,6 +75,7 @@ vi.mock('@shumai/core/src/transcode/transcode', async (importOriginal) => {
|
||||
takeScreenshots: vi.fn(),
|
||||
overlayAnnotations: vi.fn(),
|
||||
renderPdfPages: vi.fn(),
|
||||
getAvailableFilters: vi.fn().mockResolvedValue(new Set(['zscale', 'tonemap'])),
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -184,6 +185,7 @@ describe('Transcode Activities', () => {
|
||||
audioChannels: 2,
|
||||
audioSampleRate: 48000,
|
||||
audioBitDepth: 16,
|
||||
rotation: -90,
|
||||
mimeType: 'video/mp4',
|
||||
})
|
||||
|
||||
@@ -197,6 +199,7 @@ describe('Transcode Activities', () => {
|
||||
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/v.mp4')
|
||||
expect(result.duration).toBe(10)
|
||||
expect(result.metadata?.originalWidth).toBe(1920)
|
||||
expect(result.metadata?.rotation).toBe(-90)
|
||||
expect(result.metadata?.videoBitRate).toBe(850000)
|
||||
expect(result.metadata?.videoCodec).toBe('Advanced Video Coding')
|
||||
expect(result.metadata?.audioCodec).toBe('MPEG-4 Audio')
|
||||
@@ -205,7 +208,10 @@ describe('Transcode Activities', () => {
|
||||
expect(result.metadata?.audioBitDepth).toBe(16)
|
||||
expect(metadataService.updateAssetMetadata).toHaveBeenCalledWith(
|
||||
asset.id,
|
||||
expect.arrayContaining([{ key: 'file_type', value: 'video' }]),
|
||||
expect.arrayContaining([
|
||||
{ key: 'file_type', value: 'video' },
|
||||
{ key: 'rotation', value: -90 },
|
||||
]),
|
||||
true,
|
||||
)
|
||||
})
|
||||
@@ -696,6 +702,37 @@ describe('Transcode Activities', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('transcodeVideoActivity appends -hdr.mp4 suffix and forwards HDR metadata', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
|
||||
const result = await transcodeVideoActivity({
|
||||
assetKey: 'files/asset-1/video.mp4',
|
||||
filePath: '/tmp/video.mp4',
|
||||
videoSpec: { resolution: '1080p', width: 1920, height: 1080, hdr: true },
|
||||
duration: 10,
|
||||
originalFps: 30,
|
||||
sourceIsHdr: true,
|
||||
sourceHdrType: 'pq',
|
||||
sourceColorTransfer: 'smpte2084',
|
||||
sourceColorPrimaries: 'bt2020',
|
||||
sourceColorSpace: 'bt2020nc',
|
||||
})
|
||||
|
||||
expect(result.key).toBe('files/asset-1/video-1080p-hdr.mp4')
|
||||
expect(result.hdr).toBe(true)
|
||||
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
inputFile: '/tmp/video.mp4',
|
||||
hdr: true,
|
||||
sourceIsHdr: true,
|
||||
sourceHdrType: 'pq',
|
||||
sourceColorTransfer: 'smpte2084',
|
||||
sourceColorPrimaries: 'bt2020',
|
||||
sourceColorSpace: 'bt2020nc',
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('should call transcodeService.takeScreenshots', async () => {
|
||||
vi.mocked(transcodeService.takeScreenshots).mockResolvedValue([
|
||||
{ key: 'screenshots/shot1.webp', timestamp: 1.0 },
|
||||
@@ -873,6 +910,44 @@ describe('Transcode Activities', () => {
|
||||
).rejects.toThrowError(/Sprite\/Poster generation failed/)
|
||||
})
|
||||
|
||||
it('generateSpriteActivity forwards HDR options to transcodeService.generateSprite', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
vi.mocked(transcodeService.generateSprite).mockImplementation(
|
||||
async (_in, spriteOut, posterOut) => {
|
||||
fs.writeFileSync(spriteOut, Buffer.from('fake-sprite'))
|
||||
fs.writeFileSync(posterOut, Buffer.from('fake-poster'))
|
||||
},
|
||||
)
|
||||
|
||||
await generateSpriteActivity({
|
||||
assetKey: 'files/asset-1/video.mp4',
|
||||
filePath: '/tmp/video.mp4',
|
||||
mediaInfo: {
|
||||
duration: 10,
|
||||
metadata: {
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
},
|
||||
} as unknown as PrismaJson.MediaInfo,
|
||||
spriteSpec: { key: 'files/asset-1/sprite.webp', frames: 100, tileX: 10, tileY: 10 },
|
||||
posterSpec: { key: 'files/asset-1/poster.webp' },
|
||||
})
|
||||
|
||||
expect(transcodeService.generateSprite).toHaveBeenCalledWith(
|
||||
'/tmp/video.mp4',
|
||||
expect.any(String),
|
||||
expect.any(String),
|
||||
10,
|
||||
undefined,
|
||||
{
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it('should throw non-retryable ApplicationFailure when takeScreenshotsActivity fails with error', async () => {
|
||||
vi.mocked(transcodeService.takeScreenshots).mockRejectedValue(new Error('FFmpeg failed'))
|
||||
|
||||
@@ -1100,6 +1175,41 @@ describe('Transcode Activities', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('extractPosterActivity applies tone mapping filter when isHdr is true', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
vi.mocked(s3Service.resolveInput).mockResolvedValue('https://mock-r2.com/video.mp4')
|
||||
let ffmpegArgs: string[] = []
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(child_process.execFile as any).mockImplementation(
|
||||
(file: string, args: string[], optionsOrCb: unknown, maybeCb?: unknown) => {
|
||||
const cb = typeof optionsOrCb === 'function' ? optionsOrCb : maybeCb
|
||||
if (file === 'ffmpeg') {
|
||||
ffmpegArgs = args
|
||||
const outPath = args[args.length - 1]
|
||||
fs.writeFileSync(outPath, 'fake-poster-bytes')
|
||||
}
|
||||
if (typeof cb === 'function') {
|
||||
cb(null, { stdout: '', stderr: '' })
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
await extractPosterActivity({
|
||||
assetKey: 'video.mp4',
|
||||
posterSpec: { key: 'files/asset-1/poster.webp' },
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
})
|
||||
|
||||
const vfIndex = ffmpegArgs.indexOf('-vf')
|
||||
expect(vfIndex).toBeGreaterThan(-1)
|
||||
const vfArg = ffmpegArgs[vfIndex + 1]
|
||||
expect(vfArg).toContain('zscale=tin=smpte2084')
|
||||
expect(vfArg).toContain('tonemap=tonemap=hable')
|
||||
expect(vfArg).toContain('scale=-2:300')
|
||||
})
|
||||
|
||||
it('should throw non-retryable ApplicationFailure when poster extraction is cancelled with aborted signal', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
const controller = new AbortController()
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { AssetStatus, prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { transcodeService } from '@shumai/core/src/transcode/transcode'
|
||||
import {
|
||||
transcodeService,
|
||||
buildSdrToneMapFilterChain,
|
||||
type HdrType,
|
||||
} from '@shumai/core/src/transcode/transcode'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
import { getDerivedArtifactDirectory, stemFromKey } from '@shumai/core/src/utils/filename'
|
||||
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
|
||||
@@ -142,6 +146,13 @@ export async function getMediaInfoActivity(params: {
|
||||
audioChannels: info.audioChannels,
|
||||
audioSampleRate: info.audioSampleRate,
|
||||
audioBitDepth: info.audioBitDepth,
|
||||
colorTransfer: info.colorTransfer,
|
||||
colorPrimaries: info.colorPrimaries,
|
||||
colorSpace: info.colorSpace,
|
||||
isHdr: info.isHdr,
|
||||
hdrType: info.hdrType,
|
||||
dvProfile: info.dvProfile,
|
||||
rotation: info.rotation,
|
||||
format: {},
|
||||
}
|
||||
metadataUpdates.push(
|
||||
@@ -151,6 +162,12 @@ export async function getMediaInfoActivity(params: {
|
||||
{ key: 'bitRate', value: info.bitRate / 1000 },
|
||||
{ key: 'frame_rate', value: info.frameRate },
|
||||
)
|
||||
if (info.rotation !== undefined)
|
||||
metadataUpdates.push({ key: 'rotation', value: info.rotation })
|
||||
if (info.isHdr !== undefined)
|
||||
metadataUpdates.push({ key: 'is_hdr', value: info.isHdr ? 1 : 0 })
|
||||
if (info.colorTransfer)
|
||||
metadataUpdates.push({ key: 'color_transfer', value: info.colorTransfer })
|
||||
if (info.videoCodec) metadataUpdates.push({ key: 'video_codec', value: info.videoCodec })
|
||||
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
|
||||
if (info.audioChannels !== undefined)
|
||||
@@ -253,6 +270,11 @@ export interface VideoActivityParams {
|
||||
hardwareAcceleration?: PrismaJson.HardwareAcceleration
|
||||
sourceVideoBitrate?: number
|
||||
threads?: number
|
||||
sourceIsHdr?: boolean
|
||||
sourceHdrType?: HdrType
|
||||
sourceColorTransfer?: string
|
||||
sourceColorPrimaries?: string
|
||||
sourceColorSpace?: string
|
||||
}
|
||||
|
||||
export async function transcodeVideoActivity(
|
||||
@@ -261,7 +283,8 @@ export async function transcodeVideoActivity(
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const stem = stemFromKey(params.assetKey)
|
||||
const res = params.videoSpec.resolution || `${params.videoSpec.height}p`
|
||||
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${res}.mp4`)
|
||||
const suffix = params.videoSpec.hdr ? `${res}-hdr` : res
|
||||
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${suffix}.mp4`)
|
||||
|
||||
const signal = getActivityCancellationSignal(params.taskId)
|
||||
if (signal?.aborted) {
|
||||
@@ -279,7 +302,7 @@ export async function transcodeVideoActivity(
|
||||
}
|
||||
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const outputFile = path.join(tmpDir, `${stem}-${res}.mp4`)
|
||||
const outputFile = path.join(tmpDir, `${stem}-${suffix}.mp4`)
|
||||
|
||||
try {
|
||||
let targetFps: number | string = params.originalFps || 30
|
||||
@@ -307,6 +330,12 @@ export async function transcodeVideoActivity(
|
||||
sourceVideoBitrate: params.sourceVideoBitrate,
|
||||
threads: params.threads,
|
||||
signal,
|
||||
hdr: params.videoSpec.hdr,
|
||||
sourceIsHdr: params.sourceIsHdr,
|
||||
sourceHdrType: params.sourceHdrType,
|
||||
sourceColorTransfer: params.sourceColorTransfer,
|
||||
sourceColorPrimaries: params.sourceColorPrimaries,
|
||||
sourceColorSpace: params.sourceColorSpace,
|
||||
})
|
||||
|
||||
const stat = fs.statSync(outputFile)
|
||||
@@ -339,7 +368,9 @@ export async function transcodeVideoActivity(
|
||||
lowerMsg.includes('ffprobe') ||
|
||||
lowerMsg.includes('spawn') ||
|
||||
lowerMsg.includes('format') ||
|
||||
lowerMsg.includes('no video stream found')
|
||||
lowerMsg.includes('no video stream found') ||
|
||||
lowerMsg.includes('zscale') ||
|
||||
lowerMsg.includes('tonemap')
|
||||
) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `Video transcoding failed: ${message}`,
|
||||
@@ -558,6 +589,11 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
|
||||
posterFile,
|
||||
params.mediaInfo.duration,
|
||||
signal,
|
||||
{
|
||||
isHdr: params.mediaInfo.metadata?.isHdr,
|
||||
hdrType: params.mediaInfo.metadata?.hdrType,
|
||||
colorTransfer: params.mediaInfo.metadata?.colorTransfer,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -604,7 +640,9 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
|
||||
lowerMsg.includes('ffmpeg') ||
|
||||
lowerMsg.includes('ffprobe') ||
|
||||
lowerMsg.includes('spawn') ||
|
||||
lowerMsg.includes('format')
|
||||
lowerMsg.includes('format') ||
|
||||
lowerMsg.includes('zscale') ||
|
||||
lowerMsg.includes('tonemap')
|
||||
) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `Sprite/Poster generation failed: ${message}`,
|
||||
@@ -857,6 +895,9 @@ export interface ExtractPosterActivityParams {
|
||||
posterSpec: PrismaJson.PosterInfo
|
||||
taskId?: string
|
||||
signal?: AbortSignal
|
||||
isHdr?: boolean
|
||||
hdrType?: HdrType
|
||||
colorTransfer?: string
|
||||
}
|
||||
|
||||
export async function extractPosterActivity(
|
||||
@@ -885,6 +926,17 @@ export async function extractPosterActivity(
|
||||
const inputSource = await s3Service.resolveInput(bucket, params.assetKey)
|
||||
const isRemote = inputSource.startsWith('http://') || inputSource.startsWith('https://')
|
||||
|
||||
let vf = 'scale=-2:300:force_original_aspect_ratio=decrease'
|
||||
if (params.isHdr) {
|
||||
const availableFilters = await transcodeService.getAvailableFilters()
|
||||
const tonemap = buildSdrToneMapFilterChain({
|
||||
hdrType: params.hdrType,
|
||||
colorTransfer: params.colorTransfer,
|
||||
availableFilters,
|
||||
})
|
||||
vf = `${tonemap},scale=-2:300:force_original_aspect_ratio=decrease`
|
||||
}
|
||||
|
||||
const args = [
|
||||
...(isRemote
|
||||
? ['-reconnect', '1', '-reconnect_streamed', '1', '-reconnect_delay_max', '5']
|
||||
@@ -896,7 +948,7 @@ export async function extractPosterActivity(
|
||||
'-vframes',
|
||||
'1',
|
||||
'-vf',
|
||||
'scale=-2:300:force_original_aspect_ratio=decrease',
|
||||
vf,
|
||||
'-c:v',
|
||||
'libwebp',
|
||||
'-q:v',
|
||||
@@ -938,7 +990,9 @@ export async function extractPosterActivity(
|
||||
lowerMsg.includes('enoent') ||
|
||||
lowerMsg.includes('nosuchkey') ||
|
||||
lowerMsg.includes('ffmpeg') ||
|
||||
lowerMsg.includes('sharp')
|
||||
lowerMsg.includes('sharp') ||
|
||||
lowerMsg.includes('zscale') ||
|
||||
lowerMsg.includes('tonemap')
|
||||
) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `Poster extraction failed: ${message}`,
|
||||
|
||||
@@ -405,6 +405,125 @@ describe('Watermark Activities', () => {
|
||||
|
||||
fs.rmSync(outFilePath, { force: true })
|
||||
})
|
||||
|
||||
it('mirrors both SDR and HDR videoTranscodes preserving HDR flags and -hdr suffix', async () => {
|
||||
const assetKey = 'files/hdr-wm/video.mp4'
|
||||
const storageKey = await prisma.storageKey.create({ data: { key: assetKey } })
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video.mp4',
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
storageKeyId: storageKey.id,
|
||||
mediaType: 'video/mp4',
|
||||
media: {
|
||||
duration: 10,
|
||||
filesize: 0,
|
||||
frames: 300,
|
||||
proxyType: 'video',
|
||||
imageTranscodes: [],
|
||||
videoPreview: { width: 1920, height: 1080 },
|
||||
finishedAt: new Date().toISOString(),
|
||||
original: {
|
||||
key: assetKey,
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
},
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
bitRate: 1000,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
hasAudio: true,
|
||||
format: {},
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
},
|
||||
videoTranscodes: [
|
||||
{
|
||||
key: 'files/hdr-wm/video-1080p.mp4',
|
||||
resolution: '1080p',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: false,
|
||||
},
|
||||
{
|
||||
key: 'files/hdr-wm/video-1080p-hdr.mp4',
|
||||
resolution: '1080p',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: true,
|
||||
},
|
||||
],
|
||||
} as PrismaJson.MediaInfo,
|
||||
},
|
||||
})
|
||||
const config = await seedConfig()
|
||||
|
||||
vi.mocked(transcodeService.getVideoInfo).mockResolvedValue({
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
bitRate: 1000,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
hasAudio: true,
|
||||
mimeType: 'video/mp4',
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
})
|
||||
vi.mocked(s3Service.putObject).mockResolvedValue(undefined as never)
|
||||
|
||||
const sdrOut = path.join('/tmp', `video-watermark-${config.id}-1080p.mp4`)
|
||||
const hdrOut = path.join('/tmp', `video-watermark-${config.id}-1080p-hdr.mp4`)
|
||||
fs.writeFileSync(sdrOut, Buffer.from('fake sdr'))
|
||||
fs.writeFileSync(hdrOut, Buffer.from('fake hdr'))
|
||||
|
||||
const media = await transcodeWatermarkMediaActivity({
|
||||
assetId: asset.id,
|
||||
watermarkConfigId: config.id,
|
||||
})
|
||||
|
||||
expect(media.videoTranscodes).toHaveLength(2)
|
||||
expect(media.videoTranscodes?.[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
resolution: '1080p',
|
||||
hdr: false,
|
||||
key: expect.stringContaining(`video-watermark-${config.id}-1080p.mp4`),
|
||||
}),
|
||||
)
|
||||
expect(media.videoTranscodes?.[1]).toEqual(
|
||||
expect.objectContaining({
|
||||
resolution: '1080p',
|
||||
hdr: true,
|
||||
key: expect.stringContaining(`video-watermark-${config.id}-1080p-hdr.mp4`),
|
||||
}),
|
||||
)
|
||||
|
||||
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
outputFile: sdrOut,
|
||||
hdr: false,
|
||||
sourceIsHdr: true,
|
||||
}),
|
||||
)
|
||||
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
outputFile: hdrOut,
|
||||
hdr: true,
|
||||
sourceIsHdr: true,
|
||||
}),
|
||||
)
|
||||
|
||||
fs.rmSync(sdrOut, { force: true })
|
||||
fs.rmSync(hdrOut, { force: true })
|
||||
})
|
||||
})
|
||||
|
||||
describe('completeWatermarkFileActivity', () => {
|
||||
|
||||
@@ -181,6 +181,12 @@ export async function transcodeWatermarkMediaActivity(
|
||||
let startTimecode = '00:00:00:00'
|
||||
let hasAudio = false
|
||||
let sourceVideoBitrate: number | undefined
|
||||
let colorTransfer: string | undefined
|
||||
let colorPrimaries: string | undefined
|
||||
let colorSpace: string | undefined
|
||||
let isHdr: boolean | undefined
|
||||
let hdrType: PrismaJson.HdrType | undefined
|
||||
let dvProfile: number | undefined
|
||||
|
||||
if (isVideo) {
|
||||
const info = await transcodeService.getVideoInfo(rawFilePath)
|
||||
@@ -194,6 +200,12 @@ export async function transcodeWatermarkMediaActivity(
|
||||
startTimecode = info.startTimecode || '00:00:00:00'
|
||||
hasAudio = info.hasAudio
|
||||
sourceVideoBitrate = info.videoBitRate || info.bitRate
|
||||
colorTransfer = info.colorTransfer
|
||||
colorPrimaries = info.colorPrimaries
|
||||
colorSpace = info.colorSpace
|
||||
isHdr = info.isHdr
|
||||
hdrType = info.hdrType
|
||||
dvProfile = info.dvProfile
|
||||
} else if (isImage) {
|
||||
const info = await transcodeService.getImageInfo(rawFilePath)
|
||||
originalWidth = info.originalWidth
|
||||
@@ -258,6 +270,12 @@ export async function transcodeWatermarkMediaActivity(
|
||||
totalFrames,
|
||||
startTimecode,
|
||||
hasAudio,
|
||||
colorTransfer: colorTransfer ?? originalMedia?.metadata?.colorTransfer,
|
||||
colorPrimaries: colorPrimaries ?? originalMedia?.metadata?.colorPrimaries,
|
||||
colorSpace: colorSpace ?? originalMedia?.metadata?.colorSpace,
|
||||
isHdr: isHdr ?? originalMedia?.metadata?.isHdr,
|
||||
hdrType: hdrType ?? originalMedia?.metadata?.hdrType,
|
||||
dvProfile: dvProfile ?? originalMedia?.metadata?.dvProfile,
|
||||
format: {},
|
||||
},
|
||||
original: {
|
||||
@@ -320,6 +338,8 @@ export async function transcodeWatermarkMediaActivity(
|
||||
const targetWidth = vt.width || originalWidth
|
||||
const targetHeight = vt.height || originalHeight
|
||||
const resolution = vt.resolution || `${targetHeight}p`
|
||||
const isVtHdr = Boolean(vt.hdr)
|
||||
const suffix = isVtHdr ? `${resolution}-hdr` : resolution
|
||||
|
||||
const svgString = generateWatermarkSvg(config, targetWidth, targetHeight, blockImagesMap)
|
||||
const overlayPngBuffer = await transcodeService.renderSvgToPng(svgString)
|
||||
@@ -327,7 +347,7 @@ export async function transcodeWatermarkMediaActivity(
|
||||
const overlayPngPath = path.join(tmpDir, `watermarkOverlay-${i}.png`)
|
||||
fs.writeFileSync(overlayPngPath, overlayPngBuffer)
|
||||
|
||||
const outFileName = `${stem}-watermark-${params.watermarkConfigId}-${resolution}.mp4`
|
||||
const outFileName = `${stem}-watermark-${params.watermarkConfigId}-${suffix}.mp4`
|
||||
const outFilePath = path.join(tmpDir, outFileName)
|
||||
|
||||
await transcodeService.transcodeVideo({
|
||||
@@ -340,6 +360,12 @@ export async function transcodeWatermarkMediaActivity(
|
||||
hardwareAcceleration,
|
||||
sourceVideoBitrate,
|
||||
threads,
|
||||
hdr: isVtHdr,
|
||||
sourceIsHdr: isHdr ?? originalMedia?.metadata?.isHdr,
|
||||
sourceHdrType: hdrType ?? originalMedia?.metadata?.hdrType,
|
||||
sourceColorTransfer: colorTransfer ?? originalMedia?.metadata?.colorTransfer,
|
||||
sourceColorPrimaries: colorPrimaries ?? originalMedia?.metadata?.colorPrimaries,
|
||||
sourceColorSpace: colorSpace ?? originalMedia?.metadata?.colorSpace,
|
||||
})
|
||||
|
||||
const stat = fs.statSync(outFilePath)
|
||||
@@ -359,6 +385,7 @@ export async function transcodeWatermarkMediaActivity(
|
||||
width: targetWidth,
|
||||
height: targetHeight,
|
||||
resolution,
|
||||
hdr: isVtHdr,
|
||||
})
|
||||
}
|
||||
mediaInfo.filesize = totalSize
|
||||
|
||||
@@ -168,4 +168,58 @@ describe('takeVideoScreenshotsWorkflow', () => {
|
||||
annotations: [],
|
||||
})
|
||||
})
|
||||
|
||||
it('should prioritize SDR proxy over higher-resolution HDR proxy to avoid washed-out annotations', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-screenshot-sdr-prioritized',
|
||||
assetId: 'asset-video-hdr',
|
||||
type: WorkflowTaskType.transcode_screenshot,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
screenshot: {
|
||||
start: 2.0,
|
||||
end: 2.0,
|
||||
count: 1,
|
||||
commentTimestamp: 2.0,
|
||||
annotations: [],
|
||||
},
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-video-hdr',
|
||||
storageKey: { key: 'raw-hdr.mp4' },
|
||||
mediaType: 'video/mp4',
|
||||
media: {
|
||||
videoTranscodes: [
|
||||
{ key: 'proxy-1080p-hdr.mp4', height: 1080, width: 1920, hdr: true },
|
||||
{ key: 'proxy-720p.mp4', height: 720, width: 1280, hdr: false },
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
mockActivities.takeScreenshotsActivity.mockResolvedValue([
|
||||
{ key: 'files/asset-video-hdr/screenshots/shot1.webp', timestamp: 2.0 },
|
||||
])
|
||||
|
||||
await takeVideoScreenshotsWorkflow(task)
|
||||
|
||||
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
assetKey: 'proxy-720p.mp4',
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,7 +23,12 @@ export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<
|
||||
if (mediaInfo.videoTranscodes && mediaInfo.videoTranscodes.length > 0) {
|
||||
const sorted = [...mediaInfo.videoTranscodes]
|
||||
.filter((t) => t.key)
|
||||
.sort((a, b) => (b.height || 0) - (a.height || 0))
|
||||
.sort((a, b) => {
|
||||
// Prioritize SDR over HDR to avoid washed out screenshots
|
||||
if (!a.hdr && b.hdr) return -1
|
||||
if (a.hdr && !b.hdr) return 1
|
||||
return (b.height || 0) - (a.height || 0)
|
||||
})
|
||||
if (sorted.length > 0 && sorted[0].key) {
|
||||
targetKey = sorted[0].key
|
||||
}
|
||||
|
||||
@@ -497,4 +497,209 @@ describe('transcodeVideoWorkflow', () => {
|
||||
mockActivities.updateAssetMediaActivity.mock.invocationCallOrder[spriteCommitIndex],
|
||||
).toBeLessThan(firstProxyOrder)
|
||||
})
|
||||
|
||||
it('should transcode only HDR proxies and HDR 180p preview when source is HDR', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-hdr',
|
||||
assetId: 'asset-hdr',
|
||||
type: WorkflowTaskType.transcode_video,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
},
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid-hdr',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-hdr',
|
||||
storageKey: { key: 'hdr-video.mp4' },
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
mockActivities.getMediaInfoActivity.mockResolvedValue({
|
||||
proxyType: 'video',
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
bitRate: 1000,
|
||||
videoBitRate: 850000,
|
||||
hasAudio: false,
|
||||
format: {},
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
colorPrimaries: 'bt2020',
|
||||
colorSpace: 'bt2020nc',
|
||||
},
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
})
|
||||
|
||||
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
|
||||
return {
|
||||
key: `files/asset-hdr/video-${params.videoSpec.resolution}${params.videoSpec.hdr ? '-hdr' : ''}.mp4`,
|
||||
width: params.videoSpec.width,
|
||||
height: params.videoSpec.height,
|
||||
resolution: params.videoSpec.resolution,
|
||||
hdr: params.videoSpec.hdr,
|
||||
}
|
||||
})
|
||||
|
||||
await transcodeVideoWorkflow(task)
|
||||
|
||||
// Poster extraction must use SDR tone mapping
|
||||
expect(mockActivities.extractPosterActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
}),
|
||||
)
|
||||
|
||||
// 180p preview must be generated as HDR (hdr: true)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '180p',
|
||||
hdr: true,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// Main resolution (1080p) must be called as HDR (hdr: true)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '1080p',
|
||||
hdr: true,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// No calls should have been made with hdr: false for HDR source
|
||||
const calls = mockActivities.transcodeVideoActivity.mock.calls
|
||||
const sdrCalls = calls.filter(
|
||||
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === false,
|
||||
)
|
||||
expect(sdrCalls).toHaveLength(0)
|
||||
|
||||
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-hdr',
|
||||
status: WorkflowTaskStatus.completed,
|
||||
})
|
||||
})
|
||||
|
||||
it('should transcode only SDR proxy and SDR 180p preview when source is SDR', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-sdr-source',
|
||||
assetId: 'asset-sdr-source',
|
||||
type: WorkflowTaskType.transcode_video,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
},
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid-sdr-source',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-sdr-source',
|
||||
storageKey: { key: 'sdr-video.mp4' },
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
mockActivities.getMediaInfoActivity.mockResolvedValue({
|
||||
proxyType: 'video',
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
bitRate: 1000,
|
||||
videoBitRate: 850000,
|
||||
hasAudio: false,
|
||||
format: {},
|
||||
isHdr: false,
|
||||
},
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
})
|
||||
|
||||
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
|
||||
return {
|
||||
key: `files/asset-sdr-source/video-${params.videoSpec.resolution}.mp4`,
|
||||
width: params.videoSpec.width,
|
||||
height: params.videoSpec.height,
|
||||
resolution: params.videoSpec.resolution,
|
||||
hdr: params.videoSpec.hdr,
|
||||
}
|
||||
})
|
||||
|
||||
await transcodeVideoWorkflow(task)
|
||||
|
||||
// 180p preview must be generated as SDR (hdr: false)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '180p',
|
||||
hdr: false,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// Main resolution (1080p) must be generated as SDR (hdr: false)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '1080p',
|
||||
hdr: false,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// No calls should have been made with hdr: true for SDR source
|
||||
const calls = mockActivities.transcodeVideoActivity.mock.calls
|
||||
const hdrCalls = calls.filter(
|
||||
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === true,
|
||||
)
|
||||
expect(hdrCalls).toHaveLength(0)
|
||||
|
||||
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-sdr-source',
|
||||
status: WorkflowTaskStatus.completed,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -69,6 +69,9 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
assetKey: key,
|
||||
posterSpec,
|
||||
taskId: task.id,
|
||||
isHdr: mediaInfo.metadata?.isHdr,
|
||||
hdrType: mediaInfo.metadata?.hdrType,
|
||||
colorTransfer: mediaInfo.metadata?.colorTransfer,
|
||||
})
|
||||
mediaInfo.poster = posterResult.poster
|
||||
await executeActivity(workerQueue, updateAssetMediaActivity, {
|
||||
@@ -129,10 +132,42 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
metadata.originalHeight,
|
||||
)
|
||||
|
||||
const isHdr = Boolean(metadata.isHdr)
|
||||
|
||||
if (res === '180p') {
|
||||
const videoSpec: PrismaJson.VideoTranscode = {
|
||||
resolution: res,
|
||||
width,
|
||||
height,
|
||||
hdr: isHdr,
|
||||
}
|
||||
|
||||
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
|
||||
taskId: task.id,
|
||||
assetKey: key,
|
||||
filePath,
|
||||
videoSpec,
|
||||
duration: metadata.duration,
|
||||
originalFps: metadata.frameRate,
|
||||
hardwareAcceleration: spec.hardwareAcceleration,
|
||||
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
|
||||
threads: spec.threads,
|
||||
sourceIsHdr: metadata.isHdr,
|
||||
sourceHdrType: metadata.hdrType,
|
||||
sourceColorTransfer: metadata.colorTransfer,
|
||||
sourceColorPrimaries: metadata.colorPrimaries,
|
||||
sourceColorSpace: metadata.colorSpace,
|
||||
})
|
||||
|
||||
mediaInfo.videoPreview = videoTranscode
|
||||
continue
|
||||
}
|
||||
|
||||
const videoSpec: PrismaJson.VideoTranscode = {
|
||||
resolution: res,
|
||||
width,
|
||||
height,
|
||||
hdr: isHdr,
|
||||
}
|
||||
|
||||
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
|
||||
@@ -145,13 +180,14 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
hardwareAcceleration: spec.hardwareAcceleration,
|
||||
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
|
||||
threads: spec.threads,
|
||||
sourceIsHdr: metadata.isHdr,
|
||||
sourceHdrType: metadata.hdrType,
|
||||
sourceColorTransfer: metadata.colorTransfer,
|
||||
sourceColorPrimaries: metadata.colorPrimaries,
|
||||
sourceColorSpace: metadata.colorSpace,
|
||||
})
|
||||
|
||||
if (res === '180p') {
|
||||
mediaInfo.videoPreview = videoTranscode
|
||||
} else {
|
||||
mediaInfo.videoTranscodes.push(videoTranscode)
|
||||
}
|
||||
mediaInfo.videoTranscodes.push(videoTranscode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ interface BreadcrumbNavProps {
|
||||
key: string
|
||||
width: number
|
||||
height: number
|
||||
hdr?: boolean
|
||||
}>
|
||||
}
|
||||
versions?: Array<{
|
||||
@@ -294,13 +295,14 @@ export function BreadcrumbNav({
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
const label = t.hdr ? `${resolution} (HDR)` : resolution
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={resolution}
|
||||
key={t.key || `${resolution}-${t.hdr ? 'hdr' : 'sdr'}`}
|
||||
onClick={() => handleDownload(t.key)}
|
||||
className="flex items-center justify-between"
|
||||
>
|
||||
<span>{resolution}</span>
|
||||
<span>{label}</span>
|
||||
<span className="text-xs text-muted-foreground">MP4</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ interface CompareControlBarProps {
|
||||
onVolumeChange: (volume: number) => void
|
||||
onToggleMute: () => void
|
||||
onChangePlaybackRate: (rate: number) => void
|
||||
onChangeResolution: (resolution: string) => void
|
||||
onChangeResolution: (resolution: string, hdr?: boolean) => void
|
||||
onZoomIn: () => void
|
||||
onZoomOut: () => void
|
||||
onFit: () => void
|
||||
@@ -65,6 +65,7 @@ export function CompareControlBar({
|
||||
isFullScreen,
|
||||
showFrames: false,
|
||||
currentResolution: v.currentResolution,
|
||||
isCurrentHdr: v.isCurrentHdr,
|
||||
}
|
||||
|
||||
// The active-side asset carries the metadata used for timecode display and
|
||||
@@ -88,7 +89,7 @@ export function CompareControlBar({
|
||||
toggleMute={onToggleMute}
|
||||
handleVolumeChange={onVolumeChange}
|
||||
changePlaybackRate={onChangePlaybackRate}
|
||||
changeResolution={(res: DisplayTranscode) => onChangeResolution(res.resolution)}
|
||||
changeResolution={(res: DisplayTranscode) => onChangeResolution(res.resolution, res.hdr)}
|
||||
handleDownload={(key?: string) => onDownload(key)}
|
||||
toggleFullScreen={onToggleFullScreen}
|
||||
onZoomChange={(nz: number) => (nz >= activeState.zoom ? onZoomIn() : onZoomOut())}
|
||||
|
||||
@@ -213,7 +213,7 @@ export function CompareViewer({
|
||||
)
|
||||
|
||||
const handleChangeResolution = useCallback(
|
||||
(resolution: string) => getActive()?.changeResolution(resolution),
|
||||
(resolution: string, hdr?: boolean) => getActive()?.changeResolution(resolution, hdr),
|
||||
[getActive],
|
||||
)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ export interface PaneReportedState {
|
||||
playbackRate: number
|
||||
isLooping: boolean
|
||||
currentResolution: string
|
||||
isCurrentHdr?: boolean
|
||||
resolutions: DisplayTranscode[]
|
||||
buffered: number
|
||||
}
|
||||
@@ -45,7 +46,7 @@ export interface ComparePaneHandle {
|
||||
setVolume: (volume: number) => void
|
||||
setPlaybackRate: (rate: number) => void
|
||||
toggleLoop: () => void
|
||||
changeResolution: (resolution: string) => void
|
||||
changeResolution: (resolution: string, hdr?: boolean) => void
|
||||
// Zoom / pan (image + video)
|
||||
zoomBy: (factor: number) => void
|
||||
fit: () => void
|
||||
|
||||
@@ -19,7 +19,6 @@ interface DrawingCanvasProps {
|
||||
imageUrl?: string
|
||||
/** A live canvas to draw instead of an image URL (e.g. a PDF.js page render). */
|
||||
canvasElement?: HTMLCanvasElement | null
|
||||
videoElement?: HTMLVideoElement
|
||||
annotations: Annotation[]
|
||||
scale: number
|
||||
offset: { x: number; y: number }
|
||||
@@ -40,7 +39,6 @@ const DrawingCanvas = ({
|
||||
mediaDimensions,
|
||||
imageUrl,
|
||||
canvasElement,
|
||||
videoElement,
|
||||
annotations,
|
||||
scale,
|
||||
offset,
|
||||
@@ -53,7 +51,7 @@ const DrawingCanvas = ({
|
||||
onAddAnnotation,
|
||||
}: DrawingCanvasProps) => {
|
||||
const [loadedImage] = useImage(imageUrl || '', 'anonymous')
|
||||
const imageRef = useRef<Konva.Image>(null)
|
||||
const mediaGroupRef = useRef<Konva.Group>(null)
|
||||
const isDragging = useRef(false)
|
||||
const lastPos = useRef({ x: 0, y: 0 })
|
||||
const startPointRef = useRef<{ x: number; y: number } | null>(null)
|
||||
@@ -66,27 +64,11 @@ const DrawingCanvas = ({
|
||||
// Force a redraw whenever the live canvas source is swapped, so the layer
|
||||
// picks up the new page raster (Konva redraws the source each batchDraw).
|
||||
useEffect(() => {
|
||||
if (canvasElement && imageRef.current) {
|
||||
imageRef.current.getLayer()?.batchDraw()
|
||||
if (canvasElement && mediaGroupRef.current) {
|
||||
mediaGroupRef.current.getLayer()?.batchDraw()
|
||||
}
|
||||
}, [canvasElement])
|
||||
|
||||
// Handle Video Redraw
|
||||
useEffect(() => {
|
||||
if (videoElement && imageRef.current) {
|
||||
const layer = imageRef.current.getLayer()
|
||||
if (!layer) return
|
||||
|
||||
const anim = new Konva.Animation(() => {
|
||||
// Force redraw to update video frame
|
||||
}, layer)
|
||||
anim.start()
|
||||
return () => {
|
||||
anim.stop()
|
||||
}
|
||||
}
|
||||
}, [videoElement])
|
||||
|
||||
// -- Helpers --
|
||||
const getRelativePointerPosition = (
|
||||
node: Konva.Node,
|
||||
@@ -217,7 +199,7 @@ const DrawingCanvas = ({
|
||||
const handleGlobalMove = (e: MouseEvent | TouchEvent) => {
|
||||
if (!isDragging.current) return
|
||||
|
||||
const stage = imageRef.current?.getStage()
|
||||
const stage = mediaGroupRef.current?.getStage()
|
||||
if (!stage) return
|
||||
const container = stage.container()
|
||||
const rect = container.getBoundingClientRect()
|
||||
@@ -255,11 +237,11 @@ const DrawingCanvas = ({
|
||||
if (activeDrawing) {
|
||||
if (tool === 'select') return
|
||||
|
||||
const pos = getRelativePointerPosition(imageRef.current!, true, stagePos)
|
||||
const pos = getRelativePointerPosition(mediaGroupRef.current!, true, stagePos)
|
||||
if (!pos || !startPointRef.current) return
|
||||
const start = startPointRef.current
|
||||
|
||||
const layer = imageRef.current?.getLayer()
|
||||
const layer = mediaGroupRef.current?.getLayer()
|
||||
|
||||
if (tool === 'freehand' && currentLineRef.current) {
|
||||
const newPoints = currentLineRef.current.points().concat([pos.x, pos.y])
|
||||
@@ -317,8 +299,8 @@ const DrawingCanvas = ({
|
||||
const stage = e.target.getStage()
|
||||
if (!stage) return
|
||||
|
||||
// Use imageRef to get coordinates relative to the image (handling zoom/pan)
|
||||
const pos = getRelativePointerPosition(imageRef.current!)
|
||||
// Use mediaGroupRef to get coordinates relative to the media (handling zoom/pan)
|
||||
const pos = getRelativePointerPosition(mediaGroupRef.current!)
|
||||
if (!pos) return
|
||||
|
||||
// Only start drawing if within media bounds
|
||||
@@ -334,7 +316,7 @@ const DrawingCanvas = ({
|
||||
isDragging.current = true
|
||||
startPointRef.current = pos
|
||||
|
||||
const layer = imageRef.current?.getLayer()
|
||||
const layer = mediaGroupRef.current?.getLayer()
|
||||
if (!layer) return
|
||||
|
||||
if (currentTool === 'freehand' && currentLineRef.current) {
|
||||
@@ -474,32 +456,35 @@ const DrawingCanvas = ({
|
||||
onTouchStart={handleMouseDown}
|
||||
>
|
||||
<Layer>
|
||||
<KonvaImage
|
||||
ref={imageRef}
|
||||
image={videoElement || canvasElement || loadedImage}
|
||||
width={mediaDimensions.width}
|
||||
height={mediaDimensions.height}
|
||||
/>
|
||||
{annotations.map(renderAnnotation)}
|
||||
<Group ref={mediaGroupRef} width={mediaDimensions.width} height={mediaDimensions.height}>
|
||||
{(canvasElement || loadedImage) && (
|
||||
<KonvaImage
|
||||
image={canvasElement || loadedImage}
|
||||
width={mediaDimensions.width}
|
||||
height={mediaDimensions.height}
|
||||
/>
|
||||
)}
|
||||
{annotations.map(renderAnnotation)}
|
||||
|
||||
{/* Draft Shapes */}
|
||||
<Group listening={false}>
|
||||
<Line
|
||||
ref={currentLineRef}
|
||||
strokeWidth={2.6 / scale}
|
||||
lineCap="round"
|
||||
lineJoin="round"
|
||||
visible={false}
|
||||
/>
|
||||
<Rect ref={currentRectRef} strokeWidth={2.6 / scale} visible={false} />
|
||||
<Arrow
|
||||
ref={currentArrowRef}
|
||||
points={[]}
|
||||
strokeWidth={2.6 / scale}
|
||||
pointerLength={10 / scale}
|
||||
pointerWidth={10 / scale}
|
||||
visible={false}
|
||||
/>
|
||||
{/* Draft Shapes */}
|
||||
<Group listening={false}>
|
||||
<Line
|
||||
ref={currentLineRef}
|
||||
strokeWidth={2.6 / scale}
|
||||
lineCap="round"
|
||||
lineJoin="round"
|
||||
visible={false}
|
||||
/>
|
||||
<Rect ref={currentRectRef} strokeWidth={2.6 / scale} visible={false} />
|
||||
<Arrow
|
||||
ref={currentArrowRef}
|
||||
points={[]}
|
||||
strokeWidth={2.6 / scale}
|
||||
pointerLength={10 / scale}
|
||||
pointerWidth={10 / scale}
|
||||
visible={false}
|
||||
/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Layer>
|
||||
</Stage>
|
||||
|
||||
@@ -145,6 +145,7 @@ export function MobileFileDetail({
|
||||
key: t.key,
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
hdr: t.hdr,
|
||||
})),
|
||||
}
|
||||
}, [file.media])
|
||||
|
||||
@@ -46,6 +46,7 @@ export interface MobileFileHeaderProps {
|
||||
key: string
|
||||
width: number
|
||||
height: number
|
||||
hdr?: boolean
|
||||
}>
|
||||
}
|
||||
canEdit?: boolean
|
||||
@@ -245,13 +246,14 @@ export function MobileFileHeader({
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
const label = t.hdr ? `${resolution} (HDR)` : resolution
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={resolution}
|
||||
key={t.key || `${resolution}-${t.hdr ? 'hdr' : 'sdr'}`}
|
||||
onClick={() => handleDownload(t.key)}
|
||||
className="flex items-center justify-between text-xs cursor-pointer"
|
||||
>
|
||||
<span>{resolution}</span>
|
||||
<span>{label}</span>
|
||||
<span className="text-[10px] text-muted-foreground">MP4</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
|
||||
@@ -440,6 +440,7 @@ export function PublicShareManager({
|
||||
key: t.key,
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
hdr: t.hdr,
|
||||
})),
|
||||
}
|
||||
: undefined,
|
||||
|
||||
@@ -45,6 +45,28 @@ function computeResolutions(file: AssetInfo): DisplayTranscode[] {
|
||||
})
|
||||
}
|
||||
|
||||
function getInitialResolution(resolutions: DisplayTranscode[]): DisplayTranscode | null {
|
||||
if (resolutions.length === 0) return null
|
||||
if (typeof window === 'undefined') return resolutions[0]
|
||||
|
||||
const prefersHdr =
|
||||
typeof window.matchMedia === 'function' && window.matchMedia('(dynamic-range: high)').matches
|
||||
const hasHdr = resolutions.some((r) => r.hdr)
|
||||
const hasSdr = resolutions.some((r) => !r.hdr)
|
||||
|
||||
let candidates = resolutions
|
||||
if (prefersHdr && hasHdr) {
|
||||
candidates = resolutions.filter((r) => r.hdr)
|
||||
} else if (!prefersHdr && hasSdr) {
|
||||
candidates = resolutions.filter((r) => !r.hdr)
|
||||
}
|
||||
|
||||
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
|
||||
const sorted = [...candidates].sort((a, b) => (a.width ?? 0) - (b.width ?? 0))
|
||||
const bestFit = sorted.find((r) => (r.width ?? 0) >= screenWidth)
|
||||
return bestFit || sorted[sorted.length - 1]
|
||||
}
|
||||
|
||||
export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPaneProps>(
|
||||
function CompareVideoPane(
|
||||
{
|
||||
@@ -66,7 +88,6 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
const videoContainerRef = useRef<HTMLDivElement>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const videoRef = useRef<HTMLVideoElement | null>(null)
|
||||
const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined)
|
||||
|
||||
const {
|
||||
isDrawing,
|
||||
@@ -96,8 +117,9 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
||||
|
||||
const resolutions = computeResolutions(file)
|
||||
const initialRes = resolutions[0]
|
||||
const initialRes = getInitialResolution(resolutions)
|
||||
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? '')
|
||||
const [isCurrentHdr, setIsCurrentHdr] = useState(initialRes?.hdr)
|
||||
const currentSrcRef = useRef(initialRes?.url)
|
||||
|
||||
const isAudio = file.proxyType === 'audio'
|
||||
@@ -137,8 +159,10 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
// if the parent renders this pane without a per-asset `key`. Runs before the
|
||||
// video.js init effect below (declaration order) so the ref is fresh.
|
||||
useEffect(() => {
|
||||
setCurrentResolution(initialRes?.resolution ?? '')
|
||||
currentSrcRef.current = initialRes?.url
|
||||
const res = getInitialResolution(resolutions)
|
||||
setCurrentResolution(res?.resolution ?? '')
|
||||
setIsCurrentHdr(res?.hdr)
|
||||
currentSrcRef.current = res?.url
|
||||
}, [file.id])
|
||||
|
||||
// Initialize video.js
|
||||
@@ -146,7 +170,6 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
if (!videoContainerRef.current) return
|
||||
const videoElement = document.createElement('video-js')
|
||||
videoElement.classList.add('vjs-big-play-centered', '!h-full', '!w-full')
|
||||
videoElement.style.opacity = '0'
|
||||
videoElement.style.pointerEvents = 'none'
|
||||
videoContainerRef.current.appendChild(videoElement)
|
||||
|
||||
@@ -160,13 +183,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
|
||||
const htmlVid = videoElement.querySelector('video')
|
||||
if (htmlVid) {
|
||||
setVideoHtmlEl(htmlVid)
|
||||
videoRef.current = htmlVid
|
||||
} else {
|
||||
player.ready(() => {
|
||||
const techEl = player.tech({ iWillNotUseThisInPlugins: true })?.el() as HTMLVideoElement
|
||||
if (techEl) {
|
||||
setVideoHtmlEl(techEl)
|
||||
videoRef.current = techEl
|
||||
}
|
||||
})
|
||||
@@ -178,13 +199,15 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
})
|
||||
player.on('pause', () => setIsPlaying(false))
|
||||
player.on('ended', () => setIsPlaying(false))
|
||||
player.on('loadedmetadata', () => setIsPlayerReady(true))
|
||||
player.on('loadstart', () => setIsPlayerReady(false))
|
||||
|
||||
player.on('timeupdate', () => {
|
||||
const playerDuration = player.duration() || containerDuration || 0
|
||||
const bufferedEnd = player.bufferedEnd()
|
||||
if (playerDuration > 0) setBuffered((bufferedEnd / playerDuration) * 100)
|
||||
setBuffered(player.bufferedPercent())
|
||||
})
|
||||
|
||||
player.on('loadedmetadata', () => {
|
||||
setIsPlayerReady(true)
|
||||
})
|
||||
player.on('loadstart', () => setIsPlayerReady(false))
|
||||
player.on('volumechange', () => {
|
||||
setPlayerVolume(player.volume() || 0)
|
||||
setPlayerMuted(player.muted() || false)
|
||||
@@ -223,6 +246,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
playbackRate,
|
||||
isLooping,
|
||||
currentResolution,
|
||||
isCurrentHdr,
|
||||
resolutions,
|
||||
buffered,
|
||||
},
|
||||
@@ -239,6 +263,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
playbackRate,
|
||||
isLooping,
|
||||
currentResolution,
|
||||
isCurrentHdr,
|
||||
buffered,
|
||||
])
|
||||
|
||||
@@ -294,14 +319,20 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
)
|
||||
|
||||
const changeResolution = useCallback(
|
||||
(resolution: string) => {
|
||||
(resolution: string, hdr?: boolean) => {
|
||||
const player = playerRef.current
|
||||
if (!player) return
|
||||
const target = resolutions.find((r) => r.resolution === resolution)
|
||||
const target =
|
||||
hdr !== undefined
|
||||
? resolutions.find(
|
||||
(r) => r.resolution === resolution && Boolean(r.hdr) === Boolean(hdr),
|
||||
)
|
||||
: resolutions.find((r) => r.resolution === resolution)
|
||||
if (!target) return
|
||||
const wasPlaying = !player.paused()
|
||||
const currentT = player.currentTime()
|
||||
setCurrentResolution(resolution)
|
||||
setIsCurrentHdr(target.hdr)
|
||||
currentSrcRef.current = target.url
|
||||
player.src({ type: 'video/mp4', src: target.url })
|
||||
player.one('loadedmetadata', () => {
|
||||
@@ -420,7 +451,28 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
onClick={handleAreaClick}
|
||||
data-testid="compare-video-area"
|
||||
>
|
||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
|
||||
{!isAudio && (
|
||||
<div
|
||||
className="absolute pointer-events-none"
|
||||
style={{
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: vidW,
|
||||
height: vidH,
|
||||
transform: `translate(${panX}px, ${panY}px) scale(${scale})`,
|
||||
transformOrigin: '0 0',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
ref={videoContainerRef}
|
||||
className="w-full h-full [&_.video-js]:!w-full [&_.video-js]:!h-full [&_video]:!w-full [&_video]:!h-full [&_video]:!block [&_video]:!object-contain"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isAudio && (
|
||||
<div ref={videoContainerRef} className="absolute inset-0 pointer-events-none opacity-0" />
|
||||
)}
|
||||
|
||||
{isAudio ? (
|
||||
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
|
||||
@@ -432,13 +484,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
videoHtmlEl &&
|
||||
containerSize.width > 0 && (
|
||||
<DrawingCanvas
|
||||
width={containerSize.width}
|
||||
height={containerSize.height}
|
||||
mediaDimensions={{ width: vidW, height: vidH }}
|
||||
videoElement={videoHtmlEl}
|
||||
annotations={displayAnnotations}
|
||||
scale={scale}
|
||||
offset={{ x: panX, y: panY }}
|
||||
|
||||
@@ -93,4 +93,92 @@ describe('MobileVideoControlBar', () => {
|
||||
fireEvent.click(fsBtn)
|
||||
expect(toggleFullScreen).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('renders HDR label on settings button when playing HDR video', () => {
|
||||
render(
|
||||
<MobileVideoControlBar
|
||||
state={{
|
||||
...defaultState,
|
||||
currentResolution: '1080p',
|
||||
isCurrentHdr: true,
|
||||
}}
|
||||
zoom={1}
|
||||
isControlsVisible={true}
|
||||
buffered={50}
|
||||
data={mockData}
|
||||
resolutions={[
|
||||
{
|
||||
key: '1080-hdr.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
resolution: '1080p',
|
||||
hdr: true,
|
||||
} as unknown as DisplayTranscode,
|
||||
]}
|
||||
togglePlay={vi.fn()}
|
||||
toggleLoop={vi.fn()}
|
||||
toggleMute={vi.fn()}
|
||||
handleVolumeChange={vi.fn()}
|
||||
changePlaybackRate={vi.fn()}
|
||||
changeResolution={vi.fn()}
|
||||
handleDownload={vi.fn()}
|
||||
toggleFullScreen={vi.fn()}
|
||||
onZoomChange={vi.fn()}
|
||||
onZoomReset={vi.fn()}
|
||||
frameRate={25}
|
||||
totalFrames={2500}
|
||||
currentFrame={250}
|
||||
seekToFrame={vi.fn()}
|
||||
/>,
|
||||
)
|
||||
|
||||
const settingsBtn = screen.getByLabelText(/Settings/i)
|
||||
expect(settingsBtn).toBeDefined()
|
||||
expect(settingsBtn.textContent).toContain('1080p')
|
||||
expect(settingsBtn.textContent).toContain('HDR')
|
||||
})
|
||||
|
||||
it('does not render HDR label on settings button when playing SDR video', () => {
|
||||
render(
|
||||
<MobileVideoControlBar
|
||||
state={{
|
||||
...defaultState,
|
||||
currentResolution: '1080p',
|
||||
isCurrentHdr: false,
|
||||
}}
|
||||
zoom={1}
|
||||
isControlsVisible={true}
|
||||
buffered={50}
|
||||
data={mockData}
|
||||
resolutions={[
|
||||
{
|
||||
key: '1080.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
resolution: '1080p',
|
||||
hdr: false,
|
||||
} as unknown as DisplayTranscode,
|
||||
]}
|
||||
togglePlay={vi.fn()}
|
||||
toggleLoop={vi.fn()}
|
||||
toggleMute={vi.fn()}
|
||||
handleVolumeChange={vi.fn()}
|
||||
changePlaybackRate={vi.fn()}
|
||||
changeResolution={vi.fn()}
|
||||
handleDownload={vi.fn()}
|
||||
toggleFullScreen={vi.fn()}
|
||||
onZoomChange={vi.fn()}
|
||||
onZoomReset={vi.fn()}
|
||||
frameRate={25}
|
||||
totalFrames={2500}
|
||||
currentFrame={250}
|
||||
seekToFrame={vi.fn()}
|
||||
/>,
|
||||
)
|
||||
|
||||
const settingsBtn = screen.getByLabelText(/Settings/i)
|
||||
expect(settingsBtn).toBeDefined()
|
||||
expect(settingsBtn.textContent).toContain('1080p')
|
||||
expect(settingsBtn.textContent).not.toContain('HDR')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -186,10 +186,19 @@ export const MobileVideoControlBar: React.FC<ControlBarProps> = ({
|
||||
aria-label={m.settings()}
|
||||
>
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span className="text-[11px]">
|
||||
{!isAudio && state.currentResolution
|
||||
? state.currentResolution
|
||||
: `${state.playbackRate}x`}
|
||||
<span className="flex items-center gap-1 text-[11px]">
|
||||
<span>
|
||||
{!isAudio && state.currentResolution
|
||||
? state.currentResolution === 'Original'
|
||||
? m.original()
|
||||
: state.currentResolution
|
||||
: `${state.playbackRate}x`}
|
||||
</span>
|
||||
{!isAudio && state.isCurrentHdr && (
|
||||
<span className="px-1 py-0.2 rounded text-[9px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
|
||||
{m.hdr()}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
@@ -199,23 +208,36 @@ export const MobileVideoControlBar: React.FC<ControlBarProps> = ({
|
||||
<DropdownMenuLabel className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">
|
||||
{m.quality()}
|
||||
</DropdownMenuLabel>
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between text-xs cursor-pointer',
|
||||
state.currentResolution === res.resolution
|
||||
? 'text-primary font-medium'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
{resolutions.map((res) => {
|
||||
const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
|
||||
const isSelected =
|
||||
state.currentResolution === res.resolution &&
|
||||
Boolean(state.isCurrentHdr) === Boolean(res.hdr)
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={itemKey}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between text-xs cursor-pointer',
|
||||
isSelected ? 'text-primary font-medium' : 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span>
|
||||
{res.resolution === 'Original' ? m.original() : res.resolution}
|
||||
</span>
|
||||
{res.hdr && (
|
||||
<span className="px-1 py-0.2 rounded text-[9px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
|
||||
{m.hdr()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
})}
|
||||
<DropdownMenuSeparator />
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { VideoControlBar } from './video-control-bar'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import type { DisplayTranscode, PlayerState } from './video-control-bar'
|
||||
|
||||
describe('VideoControlBar', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
const mockData: AssetInfo = {
|
||||
id: 'video-1',
|
||||
name: 'sample.mp4',
|
||||
proxyType: 'video',
|
||||
media: {
|
||||
original: { key: 'files/sample.mp4' },
|
||||
metadata: {
|
||||
duration: 100,
|
||||
frameRate: 25,
|
||||
},
|
||||
},
|
||||
} as AssetInfo
|
||||
|
||||
const defaultState: PlayerState = {
|
||||
isPlaying: false,
|
||||
progress: 10,
|
||||
currentTime: 10,
|
||||
duration: 100,
|
||||
volume: 1,
|
||||
isMuted: false,
|
||||
isLooping: false,
|
||||
playbackRate: 1,
|
||||
isFullScreen: false,
|
||||
showFrames: false,
|
||||
currentResolution: '1080p',
|
||||
isCurrentHdr: false,
|
||||
}
|
||||
|
||||
const resolutions: DisplayTranscode[] = [
|
||||
{
|
||||
key: '1080.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
resolution: '1080p',
|
||||
hdr: false,
|
||||
} as unknown as DisplayTranscode,
|
||||
{
|
||||
key: '1080-hdr.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
resolution: '1080p',
|
||||
hdr: true,
|
||||
} as unknown as DisplayTranscode,
|
||||
]
|
||||
|
||||
it('renders download menu with HDR badge on HDR download items', async () => {
|
||||
const handleDownload = vi.fn()
|
||||
|
||||
render(
|
||||
<VideoControlBar
|
||||
state={defaultState}
|
||||
zoom={1}
|
||||
isControlsVisible={true}
|
||||
buffered={50}
|
||||
data={mockData}
|
||||
resolutions={resolutions}
|
||||
togglePlay={vi.fn()}
|
||||
toggleLoop={vi.fn()}
|
||||
toggleMute={vi.fn()}
|
||||
handleVolumeChange={vi.fn()}
|
||||
changePlaybackRate={vi.fn()}
|
||||
changeResolution={vi.fn()}
|
||||
handleDownload={handleDownload}
|
||||
toggleFullScreen={vi.fn()}
|
||||
onZoomChange={vi.fn()}
|
||||
onZoomReset={vi.fn()}
|
||||
frameRate={25}
|
||||
totalFrames={2500}
|
||||
currentFrame={250}
|
||||
seekToFrame={vi.fn()}
|
||||
allowDownload={true}
|
||||
/>,
|
||||
)
|
||||
|
||||
const downloadTrigger = screen.getByTitle(/Download/i)
|
||||
expect(downloadTrigger).toBeDefined()
|
||||
fireEvent.pointerDown(downloadTrigger, { button: 0, ctrlKey: false })
|
||||
|
||||
const menuItems = await screen.findAllByRole('menuitem')
|
||||
// We expect: 1080p SDR, 1080p HDR, and Original
|
||||
expect(menuItems.length).toBe(3)
|
||||
|
||||
const sdrItem = menuItems.find(
|
||||
(item) => item.textContent?.includes('1080p') && !item.textContent?.includes('HDR'),
|
||||
)
|
||||
const hdrItem = menuItems.find(
|
||||
(item) => item.textContent?.includes('1080p') && item.textContent?.includes('HDR'),
|
||||
)
|
||||
|
||||
expect(sdrItem).toBeDefined()
|
||||
expect(hdrItem).toBeDefined()
|
||||
|
||||
// Clicking HDR item triggers download with HDR key
|
||||
fireEvent.click(hdrItem!)
|
||||
expect(handleDownload).toHaveBeenCalledWith('1080-hdr.mp4')
|
||||
})
|
||||
})
|
||||
@@ -43,6 +43,7 @@ export interface PlayerState {
|
||||
showFrames: boolean // Toggle between time (02:30) and frames (1234)
|
||||
currentResolution: string // 'Original' or '720p', '480p' etc.
|
||||
currentSrc?: string
|
||||
isCurrentHdr?: boolean
|
||||
}
|
||||
|
||||
export type DisplayTranscode = VideoTranscode & { resolution: string }
|
||||
@@ -317,35 +318,53 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
{!isAudio && resolutions.length > 0 && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
|
||||
<button className="flex items-center gap-1.5 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span>
|
||||
{state.currentResolution === 'Original'
|
||||
? m.original()
|
||||
: state.currentResolution}
|
||||
<span className="flex items-center gap-1">
|
||||
<span>
|
||||
{state.currentResolution === 'Original'
|
||||
? m.original()
|
||||
: state.currentResolution}
|
||||
</span>
|
||||
{state.isCurrentHdr && (
|
||||
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
|
||||
{m.hdr()}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>{m.quality()}</DropdownMenuLabel>
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
state.currentResolution === res.resolution
|
||||
? 'text-primary font-medium'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
{resolutions.map((res) => {
|
||||
const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
|
||||
const isSelected =
|
||||
state.currentResolution === res.resolution &&
|
||||
Boolean(state.isCurrentHdr) === Boolean(res.hdr)
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={itemKey}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
isSelected ? 'text-primary font-medium' : 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
|
||||
{res.hdr && (
|
||||
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
|
||||
{m.hdr()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
@@ -370,16 +389,26 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => handleDownload(res.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">MP4</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
{resolutions.map((res) => {
|
||||
const itemKey = res.key || `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={itemKey}
|
||||
onClick={() => handleDownload(res.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground cursor-pointer"
|
||||
>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span>{res.resolution}</span>
|
||||
{res.hdr && (
|
||||
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
|
||||
{m.hdr()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground">MP4</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
})}
|
||||
{data.media?.original?.key && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
@@ -182,4 +182,126 @@ describe('VideoViewer', () => {
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('auto-selects HDR proxy when display supports HDR (dynamic-range: high)', () => {
|
||||
const originalMatchMedia = window.matchMedia
|
||||
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
||||
matches: query === '(dynamic-range: high)',
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
}))
|
||||
|
||||
const hdrVideo: AssetInfo = {
|
||||
id: 'video-hdr',
|
||||
name: 'video-hdr.mp4',
|
||||
proxyType: 'video',
|
||||
media: {
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
},
|
||||
videoTranscodes: [
|
||||
{
|
||||
resolution: '1080p',
|
||||
url: 'https://cdn.example.com/video-1080p.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: false,
|
||||
},
|
||||
{
|
||||
resolution: '1080p',
|
||||
url: 'https://cdn.example.com/video-1080p-hdr.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
} as unknown as AssetInfo
|
||||
|
||||
render(<VideoViewer file={hdrVideo} />)
|
||||
|
||||
expect(videojsMock).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({
|
||||
sources: [
|
||||
{
|
||||
src: 'https://cdn.example.com/video-1080p-hdr.mp4',
|
||||
type: 'video/mp4',
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
window.matchMedia = originalMatchMedia
|
||||
})
|
||||
|
||||
it('auto-selects SDR proxy when display does not support HDR', () => {
|
||||
const originalMatchMedia = window.matchMedia
|
||||
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
}))
|
||||
|
||||
const hdrVideo: AssetInfo = {
|
||||
id: 'video-sdr-fallback',
|
||||
name: 'video-sdr-fallback.mp4',
|
||||
proxyType: 'video',
|
||||
media: {
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
},
|
||||
videoTranscodes: [
|
||||
{
|
||||
resolution: '1080p',
|
||||
url: 'https://cdn.example.com/video-1080p.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: false,
|
||||
},
|
||||
{
|
||||
resolution: '1080p',
|
||||
url: 'https://cdn.example.com/video-1080p-hdr.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
hdr: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
} as unknown as AssetInfo
|
||||
|
||||
render(<VideoViewer file={hdrVideo} />)
|
||||
|
||||
expect(videojsMock).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({
|
||||
sources: [
|
||||
{
|
||||
src: 'https://cdn.example.com/video-1080p.mp4',
|
||||
type: 'video/mp4',
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
window.matchMedia = originalMatchMedia
|
||||
})
|
||||
})
|
||||
|
||||
@@ -54,17 +54,30 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
// We use a container ref to manually append the video element
|
||||
const videoContainerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// Logic to select best resolution based on screen size
|
||||
// Logic to select best resolution based on screen size and dynamic range
|
||||
const getInitialResolution = (): DisplayTranscode | null => {
|
||||
if (resolutions.length === 0) return null
|
||||
|
||||
if (typeof window === 'undefined') return resolutions[0]
|
||||
|
||||
const prefersHdr =
|
||||
typeof window.matchMedia === 'function' &&
|
||||
window.matchMedia('(dynamic-range: high)').matches
|
||||
const hasHdr = resolutions.some((r) => r.hdr)
|
||||
const hasSdr = resolutions.some((r) => !r.hdr)
|
||||
|
||||
let candidateResolutions = resolutions
|
||||
if (prefersHdr && hasHdr) {
|
||||
candidateResolutions = resolutions.filter((r) => r.hdr)
|
||||
} else if (!prefersHdr && hasSdr) {
|
||||
candidateResolutions = resolutions.filter((r) => !r.hdr)
|
||||
}
|
||||
|
||||
// Use device pixel ratio for high DPI screens
|
||||
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
|
||||
|
||||
// 1. Sort by width ascending
|
||||
const sortedResolutions = [...resolutions].sort((a, b) => {
|
||||
const sortedResolutions = [...candidateResolutions].sort((a, b) => {
|
||||
const wA = a.width ?? 0
|
||||
const wB = b.width ?? 0
|
||||
return wA - wB
|
||||
@@ -93,6 +106,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
showFrames: false,
|
||||
currentResolution: initialRes?.resolution ?? '',
|
||||
currentSrc: initialRes?.url ?? '',
|
||||
isCurrentHdr: initialRes?.hdr ?? false,
|
||||
})
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
@@ -140,6 +154,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
duration: data.media?.metadata?.duration || 0,
|
||||
currentResolution: res?.resolution ?? '',
|
||||
currentSrc: res?.url ?? '',
|
||||
isCurrentHdr: res?.hdr ?? false,
|
||||
}))
|
||||
setHasManuallyZoomed(false)
|
||||
setIsPlayerReady(false)
|
||||
@@ -284,8 +299,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
const videoElement = document.createElement('video-js')
|
||||
videoElement.classList.add('vjs-big-play-centered', '!h-full', '!w-full')
|
||||
|
||||
// Hide it, but keep it in DOM
|
||||
videoElement.style.opacity = '0'
|
||||
// Keep it in DOM, enable visible rendering
|
||||
videoElement.style.pointerEvents = 'none'
|
||||
|
||||
// Append to our container
|
||||
@@ -600,6 +614,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
...prev,
|
||||
currentResolution: res.resolution,
|
||||
currentSrc: res.url,
|
||||
isCurrentHdr: res.hdr ?? false,
|
||||
}))
|
||||
|
||||
player.src({ type: 'video/mp4', src: res.url })
|
||||
@@ -758,8 +773,31 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
data-vjs-player
|
||||
data-testid="video-area"
|
||||
>
|
||||
{/* Hidden VideoJS container */}
|
||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
|
||||
{!isAudio && (
|
||||
<div
|
||||
className="absolute pointer-events-none"
|
||||
style={{
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: vidW,
|
||||
height: vidH,
|
||||
transform: `translate(${pan.x}px, ${pan.y}px) scale(${scale})`,
|
||||
transformOrigin: '0 0',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
ref={videoContainerRef}
|
||||
className="w-full h-full [&_.video-js]:!w-full [&_.video-js]:!h-full [&_video]:!w-full [&_video]:!h-full [&_video]:!block [&_video]:!object-contain"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isAudio && (
|
||||
<div
|
||||
ref={videoContainerRef}
|
||||
className="absolute inset-0 pointer-events-none opacity-0"
|
||||
/>
|
||||
)}
|
||||
|
||||
{isAudio ? (
|
||||
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
|
||||
@@ -771,8 +809,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
/* Drawing Canvas (Visible) */
|
||||
videoHtmlEl &&
|
||||
/* Drawing Canvas (Transparent Overlay for annotations) */
|
||||
containerSize.width > 0 && (
|
||||
<DrawingCanvas
|
||||
width={containerSize.width}
|
||||
@@ -781,7 +818,6 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
width: vidW,
|
||||
height: vidH,
|
||||
}}
|
||||
videoElement={videoHtmlEl}
|
||||
annotations={displayAnnotations}
|
||||
scale={scale}
|
||||
offset={pan}
|
||||
|
||||
@@ -265,6 +265,8 @@
|
||||
"ffmpeg_threads_description": "Maximum number of CPU threads used by FFmpeg during transcoding. Set to 0 for Auto.",
|
||||
"threads_auto": "Auto",
|
||||
"threads_count": "{count} threads",
|
||||
"hdr": "HDR",
|
||||
"sdr": "SDR",
|
||||
|
||||
"notification_settings": "Notification Settings",
|
||||
"notifications_description": "Configure your personal notification preferences for this team.",
|
||||
|
||||
@@ -265,6 +265,8 @@
|
||||
"ffmpeg_threads_description": "FFmpeg 转码时使用的最大 CPU 线程数。设置为 0 表示自动。",
|
||||
"threads_auto": "自动",
|
||||
"threads_count": "{count} 线程",
|
||||
"hdr": "HDR",
|
||||
"sdr": "SDR",
|
||||
|
||||
"notification_settings": "通知设置",
|
||||
"notifications_description": "配置您在此团队的个人通知偏好。",
|
||||
|
||||
@@ -300,6 +300,7 @@ function FileViewPage() {
|
||||
key: t.key,
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
hdr: t.hdr,
|
||||
})),
|
||||
},
|
||||
versions: versionsDataList,
|
||||
|
||||
@@ -23,6 +23,7 @@ export interface TopNavProjectState {
|
||||
key: string
|
||||
width: number
|
||||
height: number
|
||||
hdr?: boolean
|
||||
}>
|
||||
}
|
||||
versions?: Array<{
|
||||
|
||||
Reference in New Issue
Block a user