diff --git a/CHANGELOG.md b/CHANGELOG.md index 030c7486..2ec8f821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - **changelog**: Introduce Keep a Changelog support, historical release summaries, and automated release notes extraction - **release**: Automatically populate GitHub release bodies from CHANGELOG.md and promote unreleased notes during version bumps +- **settings**: Add FFmpeg threads slider to team media processing settings ## [0.4.6] - 2026-09-17 diff --git a/packages/api/src/team.test.ts b/packages/api/src/team.test.ts index a89bb0b3..d713e2b6 100644 --- a/packages/api/src/team.test.ts +++ b/packages/api/src/team.test.ts @@ -260,6 +260,44 @@ describe('team api', () => { expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'transcode.hardwareAcceleration', 'auto') }) + it('PATCH /teams/:teamId/settings updates transcode.threads', async () => { + mockUpdateSettings.mockResolvedValue({ transcode: { threads: 8 } }) + + const res = await app.request('/teams/t1/settings', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ key: 'transcode.threads', value: 8 }), + }) + + expect(res.status).toBe(200) + const data = await res.json() + expect(data.transcode.threads).toBe(8) + expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'transcode.threads', 8) + }) + + it('PATCH /teams/:teamId/settings rejects invalid transcode.threads', async () => { + const resNegative = await app.request('/teams/t1/settings', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ key: 'transcode.threads', value: -1 }), + }) + expect(resNegative.status).toBe(400) + + const resTooLarge = await app.request('/teams/t1/settings', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ key: 'transcode.threads', value: 33 }), + }) + expect(resTooLarge.status).toBe(400) + + const resFloat = await app.request('/teams/t1/settings', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ key: 'transcode.threads', value: 4.5 }), + }) + expect(resFloat.status).toBe(400) + }) + it('PATCH /teams/:teamId/settings updates appearance.hideAgent', async () => { mockUpdateSettings.mockResolvedValue({ appearance: { hideAgent: true } }) diff --git a/packages/core/src/team/team.test.ts b/packages/core/src/team/team.test.ts index 9a1a7fb4..69edff2d 100644 --- a/packages/core/src/team/team.test.ts +++ b/packages/core/src/team/team.test.ts @@ -2,6 +2,7 @@ import { prisma } from '@shumai/db' import { setupTestDbHooks } from '@shumai/db/test' import { teamService } from '@shumai/core/src/team/team' import { describe, expect, it } from 'vitest' +import type { TeamSettingsResponse } from '@shumai/dtos' describe('TeamService', () => { setupTestDbHooks() @@ -10,6 +11,7 @@ describe('TeamService', () => { const team = await teamService.ensureDefaultTeam() expect(team).toBeDefined() expect(team.name).toBe('Default Team') + expect((team.settings as TeamSettingsResponse | null)?.transcode?.threads).toBe(0) }) it('should create team', async () => { @@ -376,12 +378,13 @@ describe('TeamService', () => { await teamService.updateSettings(team.id, 'transcode.videoStrategy', 'all') await teamService.updateSettings(team.id, 'transcode.hardwareAcceleration', 'auto') + await teamService.updateSettings(team.id, 'transcode.threads', 4) await teamService.updateSettings(team.id, 'appearance.hideAgent', true) const finalSettings = await teamService.getSettings(team.id) expect(finalSettings).toEqual({ theme: 'dark', - transcode: { videoStrategy: 'all', hardwareAcceleration: 'auto' }, + transcode: { videoStrategy: 'all', hardwareAcceleration: 'auto', threads: 4 }, appearance: { hideAgent: true }, semanticSearchEnabled: false, }) diff --git a/packages/core/src/team/team.ts b/packages/core/src/team/team.ts index 5778153b..eac50cfa 100644 --- a/packages/core/src/team/team.ts +++ b/packages/core/src/team/team.ts @@ -33,7 +33,7 @@ export class TeamService { data: { name: 'Default Team', settings: { - transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off' }, + transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off', threads: 0 }, }, sandbox: { create: {} }, }, @@ -332,6 +332,12 @@ export class TeamService { TeamSettingsResponse['transcode'] >['hardwareAcceleration'] delete settings['transcode.hardwareAcceleration'] + } else if (key === 'transcode.threads') { + if (!settings.transcode) { + settings.transcode = {} + } + settings.transcode.threads = Number(value) + delete settings['transcode.threads'] } else if (key === 'appearance.hideAgent') { if (!settings.appearance) { settings.appearance = {} diff --git a/packages/core/src/transcode/transcode.test.ts b/packages/core/src/transcode/transcode.test.ts index e943ed24..24318beb 100644 --- a/packages/core/src/transcode/transcode.test.ts +++ b/packages/core/src/transcode/transcode.test.ts @@ -614,6 +614,76 @@ describe('TranscodeService', () => { ) }) + it('transcodeAudio should pass -threads when threads > 0', async () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ;(child_process.execFile as any).mockImplementation((file: string, args: string[], cb: any) => { + cb(null, { stdout: '', stderr: '' }) + }) + + await transcodeService.transcodeAudio({ + inputFile: 'input.wav', + outputFile: 'output.mp4', + bitrate: '128k', + threads: 4, + }) + + expect(child_process.execFile).toHaveBeenCalledWith( + 'ffmpeg', + [ + '-y', + '-loglevel', + 'warning', + '-i', + 'input.wav', + '-vn', + '-c:a', + 'aac', + '-b:a', + '128k', + '-ac', + '2', + '-threads', + '4', + 'output.mp4', + ], + expect.any(Function), + ) + }) + + it('transcodeAudio should omit -threads when threads is 0', async () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ;(child_process.execFile as any).mockImplementation((file: string, args: string[], cb: any) => { + cb(null, { stdout: '', stderr: '' }) + }) + + await transcodeService.transcodeAudio({ + inputFile: 'input.wav', + outputFile: 'output.mp4', + bitrate: '128k', + threads: 0, + }) + + expect(child_process.execFile).toHaveBeenCalledWith( + 'ffmpeg', + [ + '-y', + '-loglevel', + 'warning', + '-i', + 'input.wav', + '-vn', + '-c:a', + 'aac', + '-b:a', + '128k', + '-ac', + '2', + 'output.mp4', + ], + expect.any(Function), + ) + }) + it('should generate PDF sprite sheet and poster using pdftoppm, ffmpeg, and sharp', async () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any ;(child_process.execFile as any).mockImplementation( @@ -1638,5 +1708,73 @@ describe('TranscodeService', () => { expect.any(Function), ) }) + + it('transcodeVideo with threads > 0 should pass -threads to ffmpeg', async () => { + vi.mocked(execFile).mockImplementation( + ( + _cmd: unknown, + _args: unknown, + callback: unknown, + ): ReturnType => { + const cb = callback as ( + err: Error | null, + result: { stdout: string; stderr: string }, + ) => void + if (typeof cb === 'function') { + cb(null, { stdout: '', stderr: '' }) + } + return {} as ReturnType + }, + ) + + const outputFile = path.join(tempDir, 'out_threads.mp4') + await transcodeService.transcodeVideo({ + inputFile: 'input.mp4', + outputFile, + width: 1280, + height: 720, + threads: 6, + }) + + expect(child_process.execFile).toHaveBeenCalledWith( + 'ffmpeg', + expect.arrayContaining(['-threads', '6']), + expect.any(Function), + ) + }) + + it('transcodeVideo with threads 0 or undefined should omit -threads', async () => { + vi.mocked(execFile).mockImplementation( + ( + _cmd: unknown, + _args: unknown, + callback: unknown, + ): ReturnType => { + const cb = callback as ( + err: Error | null, + result: { stdout: string; stderr: string }, + ) => void + if (typeof cb === 'function') { + cb(null, { stdout: '', stderr: '' }) + } + return {} as ReturnType + }, + ) + + const outputFile = path.join(tempDir, 'out_threads_0.mp4') + await transcodeService.transcodeVideo({ + inputFile: 'input.mp4', + outputFile, + width: 1280, + height: 720, + threads: 0, + }) + + expect(child_process.execFile).not.toHaveBeenCalledWith( + 'ffmpeg', + expect.arrayContaining(['-threads']), + expect.any(Function), + ) + }) }) }) diff --git a/packages/core/src/transcode/transcode.ts b/packages/core/src/transcode/transcode.ts index 037449cb..e876f5dc 100644 --- a/packages/core/src/transcode/transcode.ts +++ b/packages/core/src/transcode/transcode.ts @@ -116,6 +116,7 @@ export interface TranscodeVideoParams { hardwareAcceleration?: 'off' | 'auto' videoBitrate?: string sourceVideoBitrate?: number + threads?: number } export interface EncoderConfig { @@ -627,6 +628,10 @@ export class TranscodeService { args.push('-c:a', 'aac', '-b:a', '128k') } + if (params.threads && params.threads > 0) { + args.push('-threads', params.threads.toString()) + } + args.push('-movflags', '+faststart', '-max_muxing_queue_size', '1024', params.outputFile) await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args]) @@ -1084,20 +1089,14 @@ export class TranscodeService { inputFile: string outputFile: string bitrate?: string + threads?: number }): Promise { const bitrate = params.bitrate || '128k' - const args = [ - '-i', - params.inputFile, - '-vn', - '-c:a', - 'aac', - '-b:a', - bitrate, - '-ac', - '2', - params.outputFile, - ] + const args = ['-i', params.inputFile, '-vn', '-c:a', 'aac', '-b:a', bitrate, '-ac', '2'] + if (params.threads && params.threads > 0) { + args.push('-threads', params.threads.toString()) + } + args.push(params.outputFile) await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args]) } diff --git a/packages/core/src/upload/upload.test.ts b/packages/core/src/upload/upload.test.ts index 78a1d434..dd29f182 100644 --- a/packages/core/src/upload/upload.test.ts +++ b/packages/core/src/upload/upload.test.ts @@ -195,6 +195,58 @@ describe('UploadService', () => { transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off', + threads: 0, + sprite: true, + poster: true, + }, + }) + }) + + it('should pass custom transcode.threads from team settings to transcode task', async () => { + await prisma.team.update({ + where: { id: teamId }, + data: { + settings: { + transcode: { + videoStrategy: 'all', + hardwareAcceleration: 'auto', + threads: 12, + }, + }, + }, + }) + + const task = await prisma.task.create({ + data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' }, + }) + const asset = await prisma.asset.create({ + data: { + name: 'video-custom-threads.mp4', + type: AssetType.file, + project: { connect: { id: projectId } }, + parent: { connect: { id: parentId } }, + status: AssetStatus.uploading, + storageKey: { + connectOrCreate: { + where: { key: 'test-key-threads' }, + create: { key: 'test-key-threads' }, + }, + }, + }, + }) + + await uploadService.confirmFileUpload(userId, task.id, { fileId: asset.id }) + + const workflowTask = await prisma.workflowTask.findFirst({ + where: { assetId: asset.id, type: WorkflowTaskType.transcode_video }, + }) + expect(workflowTask).toBeDefined() + expect(workflowTask?.payload).toEqual({ + projectId: projectId, + transcode: { + videoStrategy: 'all', + hardwareAcceleration: 'auto', + threads: 12, sprite: true, poster: true, }, diff --git a/packages/core/src/upload/upload.ts b/packages/core/src/upload/upload.ts index e1c91c97..be7dfde4 100644 --- a/packages/core/src/upload/upload.ts +++ b/packages/core/src/upload/upload.ts @@ -331,6 +331,7 @@ export class UploadService { }) } else { const settings = team.settings as PrismaJson.Settings | null + const threads = settings?.transcode?.threads ?? 0 if (isVideo) { const strategy = settings?.transcode?.videoStrategy || 'best_match' const hardwareAcceleration = settings?.transcode?.hardwareAcceleration || 'off' @@ -338,12 +339,15 @@ export class UploadService { await new VideoTranscoder(tx as any, asset.id, team.id, projectId) .setStrategy(strategy) .setHardwareAcceleration(hardwareAcceleration) + .setThreads(threads) .withSprite() .withPoster() .submit() } else if (isAudio) { // eslint-disable-next-line @typescript-eslint/no-explicit-any - await new VideoTranscoder(tx as any, asset.id, team.id, projectId).submit() + await new VideoTranscoder(tx as any, asset.id, team.id, projectId) + .setThreads(threads) + .submit() } else if (isImage) { // eslint-disable-next-line @typescript-eslint/no-explicit-any await new ImageTranscoder(tx as any, asset.id, team.id, projectId).withThumbnail().submit() diff --git a/packages/db/src/prisma-json-types.ts b/packages/db/src/prisma-json-types.ts index 40862444..82ebe3da 100644 --- a/packages/db/src/prisma-json-types.ts +++ b/packages/db/src/prisma-json-types.ts @@ -59,6 +59,7 @@ declare global { export interface TranscodeSettings { videoStrategy: VideoTranscodeStrategy hardwareAcceleration?: HardwareAcceleration + threads?: number } export interface MediaProviderConfig { @@ -314,6 +315,7 @@ declare global { export interface TaskSpec { videoStrategy?: VideoTranscodeStrategy hardwareAcceleration?: HardwareAcceleration + threads?: number thumbnail?: boolean sprite?: boolean poster?: boolean diff --git a/packages/dtos/src/team.ts b/packages/dtos/src/team.ts index a5d0db61..de2dfe58 100644 --- a/packages/dtos/src/team.ts +++ b/packages/dtos/src/team.ts @@ -89,6 +89,10 @@ export const updateTeamSettingsRequestSchema = z.union([ key: z.literal('transcode.hardwareAcceleration'), value: z.nativeEnum(HardwareAcceleration), }), + z.object({ + key: z.literal('transcode.threads'), + value: z.number().int().min(0).max(32), + }), z.object({ key: z.literal('appearance.hideAgent'), value: z.boolean(), @@ -104,6 +108,7 @@ export interface TeamSettingsResponse { transcode?: { videoStrategy?: VideoTranscodeStrategy hardwareAcceleration?: HardwareAcceleration + threads?: number } appearance?: TeamAppearanceSettings semanticSearchEnabled?: boolean diff --git a/packages/transcode/src/activities/transcode.test.ts b/packages/transcode/src/activities/transcode.test.ts index 945903d2..ca783acc 100644 --- a/packages/transcode/src/activities/transcode.test.ts +++ b/packages/transcode/src/activities/transcode.test.ts @@ -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( diff --git a/packages/transcode/src/activities/transcode.ts b/packages/transcode/src/activities/transcode.ts index c9b6ba53..821199e4 100644 --- a/packages/transcode/src/activities/transcode.ts +++ b/packages/transcode/src/activities/transcode.ts @@ -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) diff --git a/packages/transcode/src/activities/watermark.test.ts b/packages/transcode/src/activities/watermark.test.ts index 5a342c01..65bae30e 100644 --- a/packages/transcode/src/activities/watermark.test.ts +++ b/packages/transcode/src/activities/watermark.test.ts @@ -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, }), ) diff --git a/packages/transcode/src/activities/watermark.ts b/packages/transcode/src/activities/watermark.ts index 0c8160ef..e399099e 100644 --- a/packages/transcode/src/activities/watermark.ts +++ b/packages/transcode/src/activities/watermark.ts @@ -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) diff --git a/packages/transcode/src/transcoder.ts b/packages/transcode/src/transcoder.ts index 234c5367..7c95a889 100644 --- a/packages/transcode/src/transcoder.ts +++ b/packages/transcode/src/transcoder.ts @@ -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 diff --git a/packages/transcode/src/workflows/transcode-video.test.ts b/packages/transcode/src/workflows/transcode-video.test.ts index 423f5d1c..0fe8144b 100644 --- a/packages/transcode/src/workflows/transcode-video.test.ts +++ b/packages/transcode/src/workflows/transcode-video.test.ts @@ -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({ diff --git a/packages/transcode/src/workflows/transcode-video.ts b/packages/transcode/src/workflows/transcode-video.ts index 52c002dd..325cef81 100644 --- a/packages/transcode/src/workflows/transcode-video.ts +++ b/packages/transcode/src/workflows/transcode-video.ts @@ -105,6 +105,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise 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 const audioTranscode = await executeActivity(workerQueue, transcodeAudioActivity, { assetKey: key, filePath, + threads: spec.threads, }) mediaInfo.videoTranscodes.push(audioTranscode) } diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index b8b8a9b8..2b9d79c8 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -260,6 +260,10 @@ "hardware_acceleration_off_description": "Uses software libx264 encoder with constant rate factor (CRF).", "hardware_acceleration_auto": "Auto Detect", "hardware_acceleration_auto_description": "Automatically probes and uses GPU/Hardware acceleration (NVENC, QSV, AMF, VideoToolbox). If hardware acceleration is unsupported on the host, video transcoding may fail.", + "ffmpeg_threads": "FFmpeg Threads", + "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", "notification_settings": "Notification Settings", "notifications_description": "Configure your personal notification preferences for this team.", diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index d054aa58..d6420c74 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -260,6 +260,10 @@ "hardware_acceleration_off_description": "使用 CPU 的 libx264 软件编码器及 CRF 恒定画质模式。", "hardware_acceleration_auto": "自动检测", "hardware_acceleration_auto_description": "自动检测并使用 GPU/硬件加速(NVENC、QSV、AMF、VideoToolbox)。若宿主硬件不支持加速,视频转码可能会失败。", + "ffmpeg_threads": "FFmpeg 线程数", + "ffmpeg_threads_description": "FFmpeg 转码时使用的最大 CPU 线程数。设置为 0 表示自动。", + "threads_auto": "自动", + "threads_count": "{count} 线程", "notification_settings": "通知设置", "notifications_description": "配置您在此团队的个人通知偏好。", diff --git a/packages/webui/routes/teams/$teamId/settings.lazy.tsx b/packages/webui/routes/teams/$teamId/settings.lazy.tsx index 3e0abb04..167bf18b 100644 --- a/packages/webui/routes/teams/$teamId/settings.lazy.tsx +++ b/packages/webui/routes/teams/$teamId/settings.lazy.tsx @@ -3,6 +3,7 @@ import { VideoTranscodeStrategy, HardwareAcceleration, UpdateTeamSettingsRequest, + TeamSettingsResponse, } from '@shumai/dtos' import { client } from '@/ui/api/client' import { AgentsSettings } from '@/ui/components/settings/AgentsSettings' @@ -16,6 +17,7 @@ import { QuotasSettings } from '@/ui/components/settings/QuotasSettings' import { AppearanceSettings } from '@/ui/components/settings/AppearanceSettings' import { ImageVideoGenerationSettings } from '@/ui/components/settings/ImageVideoGenerationSettings' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card' +import { Slider } from '@/ui/components/ui/slider' import { cn } from '@/ui/lib/utils' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { @@ -309,6 +311,23 @@ function TeamSettingsPage() { }) } + const [localThreads, setLocalThreads] = useState(null) + const serverThreads = (settings as TeamSettingsResponse | undefined)?.transcode?.threads ?? 0 + + useEffect(() => { + setLocalThreads(null) + }, [serverThreads]) + + const handleThreadsChange = (value: number) => { + updateSettings({ + teamId, + data: { + key: 'transcode.threads', + value, + }, + }) + } + if (isSettingsLoading || isMeLoading) { return (
@@ -334,6 +353,8 @@ function TeamSettingsPage() { // eslint-disable-next-line @typescript-eslint/no-explicit-any (settings as any)?.transcode?.hardwareAcceleration || HardwareAcceleration.off + const currentThreads = localThreads ?? serverThreads + return (
@@ -725,7 +746,7 @@ function TeamSettingsPage() { )} {activeTab === 'transcode' && ( -
+
{m.transcode_settings()} @@ -812,6 +833,41 @@ function TeamSettingsPage() {
+ + {/* FFmpeg Threads */} +
+
+
+

{m.ffmpeg_threads()}

+

+ {m.ffmpeg_threads_description()} +

+
+ + {currentThreads === 0 + ? m.threads_auto() + : m.threads_count({ count: currentThreads })} + +
+
+ setLocalThreads(val)} + onValueCommit={([val]) => { + setLocalThreads(val) + handleThreadsChange(val) + }} + /> +
+ {m.threads_auto()} (0) + 16 + 32 +
+
+