fix(video): transcribe from the smallest full proxy

This commit is contained in:
yiling
2026-12-03 21:05:40 +08:00
parent cdd45429c4
commit 659ed5dab4
15 changed files with 210 additions and 53 deletions
+1
View File
@@ -86,6 +86,7 @@ export const assetInfoSchema = z.object({
type: z.string(),
targetType: z.string().optional().nullable(),
status: z.string(),
mediaType: z.string().nullable().optional(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
latestChildren: z.array(childPreviewSchema).optional(),
preview: previewInfoSchema.nullable().optional(),
+27
View File
@@ -26,8 +26,35 @@ export const transcriptLanguagesSchema = z.object({
languages: z.array(z.object({ code: transcriptLanguageCodeSchema, name: z.string().min(1) })),
})
interface TranscriptVideoProxy {
key?: string
resolution?: string
width: number
height: number
}
export function selectTranscriptVideoProxyKey(
media?: { videoTranscodes?: TranscriptVideoProxy[]; videoPreview?: { key?: string } } | null,
): string | undefined {
let selectedKey: string | undefined
let smallestArea = Infinity
for (const proxy of media?.videoTranscodes ?? []) {
if (!proxy.key || proxy.key === media?.videoPreview?.key || proxy.resolution === '180p') {
continue
}
const area = proxy.width > 0 && proxy.height > 0 ? proxy.width * proxy.height : Infinity
if (area < smallestArea) {
selectedKey = proxy.key
smallestArea = area
}
}
return selectedKey
}
export const transcriptionErrors = {
noAudio: 'The video does not contain an audio track',
noProxy: 'A completed full video proxy is required to generate transcripts',
tooLarge: 'Audio exceeds the embedding server upload limit',
} as const