feat(settings): add FFmpeg threads setting for media processing (#415)

* feat(settings): add FFmpeg threads setting for media processing

* style(settings): add bottom padding to media processing page
This commit is contained in:
Yiling-J
2026-09-18 13:30:33 +08:00
committed by GitHub
parent 3a509537fd
commit a91d8c4521
20 changed files with 355 additions and 17 deletions
@@ -606,6 +606,7 @@ describe('Transcode Activities', () => {
originalFps: 30,
hardwareAcceleration: 'auto',
sourceVideoBitrate: 600_000,
threads: 8,
})
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
@@ -613,6 +614,7 @@ describe('Transcode Activities', () => {
inputFile: '/tmp/v.mp4',
hardwareAcceleration: 'auto',
sourceVideoBitrate: 600_000,
threads: 8,
}),
)
})
@@ -1013,12 +1015,14 @@ describe('Transcode Activities', () => {
const res = await transcodeAudioActivity({
assetKey: 'files/proj-123/a.wav',
filePath: '/tmp/a.wav',
threads: 4,
})
expect(transcodeService.transcodeAudio).toHaveBeenCalledWith({
inputFile: '/tmp/a.wav',
outputFile: expect.stringContaining('a-audio-proxy.mp4'),
bitrate: '128k',
threads: 4,
})
expect(s3Service.putObject).toHaveBeenCalledWith(
@@ -223,6 +223,7 @@ export interface VideoActivityParams {
originalFps: number
hardwareAcceleration?: PrismaJson.HardwareAcceleration
sourceVideoBitrate?: number
threads?: number
}
export async function transcodeVideoActivity(
@@ -267,6 +268,7 @@ export async function transcodeVideoActivity(
disableAudio,
hardwareAcceleration: params.hardwareAcceleration,
sourceVideoBitrate: params.sourceVideoBitrate,
threads: params.threads,
})
const stat = fs.statSync(outputFile)
@@ -302,6 +304,7 @@ export async function transcodeVideoActivity(
export interface AudioActivityParams {
assetKey: string
filePath: string
threads?: number
}
export async function transcodeAudioActivity(
@@ -326,6 +329,7 @@ export async function transcodeAudioActivity(
inputFile: params.filePath,
outputFile,
bitrate: '128k',
threads: params.threads,
})
const stat = fs.statSync(outputFile)
@@ -352,6 +352,7 @@ describe('Watermark Activities', () => {
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'auto',
threads: 6,
},
},
},
@@ -398,6 +399,7 @@ describe('Watermark Activities', () => {
hardwareAcceleration: 'auto',
sourceVideoBitrate: 1800000,
disableAudio: true,
threads: 6,
}),
)
@@ -150,6 +150,7 @@ export async function transcodeWatermarkMediaActivity(
const teamSettings = asset.project?.team?.settings as PrismaJson.Settings | null
const hardwareAcceleration = teamSettings?.transcode?.hardwareAcceleration ?? 'off'
const threads = teamSettings?.transcode?.threads ?? 0
// The config column is declared as PrismaJson.WatermarkConfigSpec, which is
// structurally identical to the DTO type, so no cast is required.
@@ -338,6 +339,7 @@ export async function transcodeWatermarkMediaActivity(
overlayFile: overlayPngPath,
hardwareAcceleration,
sourceVideoBitrate,
threads,
})
const stat = fs.statSync(outFilePath)
+7
View File
@@ -29,6 +29,13 @@ export class VideoTranscoder {
return this
}
setThreads(threads?: number): this {
if (threads !== undefined) {
this.spec.threads = threads
}
return this
}
withSprite(): this {
this.spec.sprite = true
return this
@@ -187,6 +187,7 @@ describe('transcodeVideoWorkflow', () => {
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'auto',
threads: 8,
},
},
createdAt: new Date(),
@@ -238,6 +239,7 @@ describe('transcodeVideoWorkflow', () => {
filePath: '/tmp/video.mp4',
hardwareAcceleration: 'auto',
sourceVideoBitrate: 850000,
threads: 8,
}),
)
})
@@ -252,7 +254,9 @@ describe('transcodeVideoWorkflow', () => {
output: null,
payload: {
projectId: 'proj-1',
transcode: {},
transcode: {
threads: 4,
},
},
createdAt: new Date(),
updatedAt: new Date(),
@@ -303,6 +307,7 @@ describe('transcodeVideoWorkflow', () => {
expect(mockActivities.transcodeAudioActivity).toHaveBeenCalledWith({
assetKey: 'audio.wav',
filePath: '/tmp/video.mp4',
threads: 4,
})
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
@@ -105,6 +105,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
originalFps: metadata.frameRate,
hardwareAcceleration: spec.hardwareAcceleration,
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
threads: spec.threads,
})
if (res === '180p') {
@@ -120,6 +121,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
const audioTranscode = await executeActivity(workerQueue, transcodeAudioActivity, {
assetKey: key,
filePath,
threads: spec.threads,
})
mediaInfo.videoTranscodes.push(audioTranscode)
}