mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
fix(video): transcribe from the smallest full proxy
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { execFile } from 'node:child_process'
|
||||
import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { basename, join } from 'node:path'
|
||||
import { promisify } from 'node:util'
|
||||
import { initAgentWorkflows } from '@shumai/agent'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { transcriptService } from '@shumai/core/src/transcript/transcript'
|
||||
import { transcodeService } from '@shumai/core/src/transcode/transcode'
|
||||
import { prisma } from '@shumai/db'
|
||||
import { setupTestDbHooks } from '@shumai/db/test'
|
||||
import { TaskQueueAgent, workflowService } from '@shumai/workflow-core'
|
||||
@@ -13,6 +14,8 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vites
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const bucket = 'shumai-e2e-transcript'
|
||||
const preview = { key: 'video/180p.mp4', resolution: '180p', width: 32, height: 32 }
|
||||
const largerProxy = { key: 'video/720p.mp4', resolution: '720p', width: 96, height: 96 }
|
||||
const languages = {
|
||||
model: 'whisper-tiny',
|
||||
languages: [
|
||||
@@ -57,17 +60,23 @@ describe('Transcribe video workflow', () => {
|
||||
'pcm_s16le',
|
||||
join(directory, 'audio.mkv'),
|
||||
])
|
||||
await execFileAsync('ffmpeg', [
|
||||
'-v',
|
||||
'error',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=size=64x64:duration=1',
|
||||
'-c:v',
|
||||
'mpeg4',
|
||||
join(directory, 'silent.mkv'),
|
||||
])
|
||||
const fullProxy = { width: 64, height: 64 }
|
||||
for (const [fileName, { width, height }, disableAudio] of [
|
||||
['audio.mp4', fullProxy, false],
|
||||
['silent.mp4', fullProxy, true],
|
||||
['720p.mp4', largerProxy, true],
|
||||
['180p.mp4', preview, true],
|
||||
] as const) {
|
||||
await transcodeService.transcodeVideo({
|
||||
inputFile: join(directory, 'audio.mkv'),
|
||||
outputFile: join(directory, fileName),
|
||||
width,
|
||||
height,
|
||||
frameRate: 25,
|
||||
disableAudio,
|
||||
hardwareAcceleration: 'off',
|
||||
})
|
||||
}
|
||||
// Replace only the inference server and inspect what the worker sends over HTTP.
|
||||
provider = Bun.serve({
|
||||
hostname: '127.0.0.1',
|
||||
@@ -123,8 +132,12 @@ describe('Transcribe video workflow', () => {
|
||||
async function submitVideo(name: string, language: string | null) {
|
||||
const team = await prisma.team.create({ data: { name: 'Transcription E2E' } })
|
||||
const project = await prisma.project.create({ data: { name: 'Videos', teamId: team.id } })
|
||||
const key = `video/${name}`
|
||||
await s3Service.uploadFileToKey(join(directory, name), key, 'video/x-matroska')
|
||||
const fullProxy = { key: `video/${name}`, resolution: '480p', width: 64, height: 64 }
|
||||
await Promise.all(
|
||||
[preview, largerProxy, fullProxy].map(({ key }) =>
|
||||
s3Service.uploadFileToKey(join(directory, basename(key)), key, 'video/mp4'),
|
||||
),
|
||||
)
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name,
|
||||
@@ -132,7 +145,19 @@ describe('Transcribe video workflow', () => {
|
||||
status: 'processed',
|
||||
project: { connect: { id: project.id } },
|
||||
mediaType: 'video/x-matroska',
|
||||
storageKey: { create: { key } },
|
||||
storageKey: { create: { key: 'video/unavailable-original.mkv' } },
|
||||
media: {
|
||||
proxyType: 'video',
|
||||
videoTranscodes: [largerProxy, preview, fullProxy],
|
||||
videoPreview: preview,
|
||||
imageTranscodes: [],
|
||||
duration: 2,
|
||||
filesize: 0,
|
||||
frames: 50,
|
||||
finishedAt: new Date().toISOString(),
|
||||
metadata: null,
|
||||
original: null,
|
||||
},
|
||||
},
|
||||
})
|
||||
const result = await transcriptService.generate(asset.id, language)
|
||||
@@ -143,9 +168,9 @@ describe('Transcribe video workflow', () => {
|
||||
}
|
||||
}
|
||||
|
||||
it('sends a timeline-aligned WAV and saves the detected language and segments after retrying a busy server', async () => {
|
||||
it('uses the smallest full proxy to send a timeline-aligned WAV and saves the detected language and segments after retrying a busy server', async () => {
|
||||
firstRequestBusy = true
|
||||
const { task, assetId } = await submitVideo('audio.mkv', null)
|
||||
const { task, assetId } = await submitVideo('audio.mp4', null)
|
||||
await workflowService.executeWait(task, 20_000)
|
||||
|
||||
expect(uploads).toHaveLength(2)
|
||||
@@ -181,7 +206,7 @@ describe('Transcribe video workflow', () => {
|
||||
|
||||
it('passes an explicit language and treats an upload limit error as permanent', async () => {
|
||||
responseStatus = 413
|
||||
const { task, assetId } = await submitVideo('audio.mkv', 'zh')
|
||||
const { task, assetId } = await submitVideo('audio.mp4', 'zh')
|
||||
await expect(workflowService.executeWait(task, 20_000)).rejects.toThrow(
|
||||
'Audio exceeds the embedding server upload limit',
|
||||
)
|
||||
@@ -199,7 +224,7 @@ describe('Transcribe video workflow', () => {
|
||||
}, 24_000)
|
||||
|
||||
it('fails with a clear message when the video has no audio track', async () => {
|
||||
const { task, assetId } = await submitVideo('silent.mkv', null)
|
||||
const { task, assetId } = await submitVideo('silent.mp4', null)
|
||||
await expect(workflowService.executeWait(task, 20_000)).rejects.toThrow(
|
||||
'The video does not contain an audio track',
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user