feat(transcode): smart poster frame selection and decoupled generation (#428)

* feat(transcode): smart poster frame selection and decoupled generation

* fix(transcode): detect MPEG-TS extension from URL pathname for signed remote sources
This commit is contained in:
Yiling-J
2026-09-25 16:37:16 +08:00
committed by GitHub
parent 59742dde78
commit 941bf0fd1b
5 changed files with 361 additions and 186 deletions
+7 -37
View File
@@ -1,10 +1,6 @@
import { AssetStatus, prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
import { s3Service } from '@shumai/core/src/s3/s3'
import {
transcodeService,
buildSdrToneMapFilterChain,
type HdrType,
} from '@shumai/core/src/transcode/transcode'
import { transcodeService, 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'
@@ -924,38 +920,12 @@ export async function extractPosterActivity(
try {
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']
: []),
'-ss',
'0',
'-i',
inputSource,
'-vframes',
'1',
'-vf',
vf,
'-c:v',
'libwebp',
'-q:v',
'75',
posterFile,
]
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args], { signal })
await transcodeService.generatePoster(inputSource, posterFile, {
isHdr: params.isHdr,
hdrType: params.hdrType,
colorTransfer: params.colorTransfer,
signal,
})
const posterBuffer = fs.readFileSync(posterFile)
await ensureAssetNotPurging(params.assetKey)