feat(transcode): add hardware-accelerated video transcoding support (#352)

* feat(transcode): add hardware-accelerated video transcoding support

* feat(transcode): use encoder quality modes and source-capped maxrate for video transcode

* fix(transcode): scale max bitrate for downsampled preview framerates

* fix(transcode): propagate videoBitRate in getMediaInfoActivity and update auto description
This commit is contained in:
Yiling-J
2026-08-26 16:28:14 +08:00
committed by GitHub
parent 7b1428bf51
commit 8f55ba1d37
29 changed files with 1272 additions and 11 deletions
+5
View File
@@ -254,6 +254,11 @@
"best_match_description": "Generates a single optimal resolution matching the source quality.",
"all_resolutions": "All resolutions",
"all_resolutions_description": "Generates all supported resolutions up to the source quality.",
"hardware_acceleration": "Hardware Acceleration",
"hardware_acceleration_off": "Disabled (Software)",
"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.",
"notification_settings": "Notification Settings",
"notifications_description": "Configure your personal notification preferences for this team.",
+5
View File
@@ -254,6 +254,11 @@
"best_match_description": "生成与源质量匹配的单一最优分辨率。",
"all_resolutions": "所有分辨率",
"all_resolutions_description": "生成不超过源质量的所有支持分辨率。",
"hardware_acceleration": "硬件加速",
"hardware_acceleration_off": "已禁用 (软件编码)",
"hardware_acceleration_off_description": "使用 CPU 的 libx264 软件编码器及 CRF 恒定画质模式。",
"hardware_acceleration_auto": "自动检测",
"hardware_acceleration_auto_description": "自动检测并使用 GPU/硬件加速(NVENC、QSV、AMF、VideoToolbox)。若宿主硬件不支持加速,视频转码可能会失败。",
"notification_settings": "通知设置",
"notifications_description": "配置您在此团队的个人通知偏好。",
+5
View File
@@ -241,6 +241,11 @@ export * from "./best_match.js";
export * from "./best_match_description.js";
export * from "./all_resolutions.js";
export * from "./all_resolutions_description.js";
export * from "./hardware_acceleration.js";
export * from "./hardware_acceleration_off.js";
export * from "./hardware_acceleration_off_description.js";
export * from "./hardware_acceleration_auto.js";
export * from "./hardware_acceleration_auto_description.js";
export * from "./notification_settings.js";
export * from "./notifications_description.js";
export * from "./notification_settings_updated.js";
+5
View File
@@ -243,6 +243,11 @@ export * from './best_match.js'
export * from './best_match_description.js'
export * from './all_resolutions.js'
export * from './all_resolutions_description.js'
export * from './hardware_acceleration.js'
export * from './hardware_acceleration_off.js'
export * from './hardware_acceleration_off_description.js'
export * from './hardware_acceleration_auto.js'
export * from './hardware_acceleration_auto_description.js'
export * from './notification_settings.js'
export * from './notifications_description.js'
export * from './notification_settings_updated.js'
+16
View File
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Hardware Acceleration" |
*
* @param {Hardware_AccelerationInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration: ((inputs?: Hardware_AccelerationInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Hardware_AccelerationInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Hardware_AccelerationInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Hardware_AccelerationInputs */
const en_hardware_acceleration = /** @type {(inputs: Hardware_AccelerationInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Hardware Acceleration`)
};
const zh_hardware_acceleration = /** @type {(inputs: Hardware_AccelerationInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`硬件加速`)
};
/**
* | output |
* | --- |
* | "Hardware Acceleration" |
*
* @param {Hardware_AccelerationInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration = /** @type {((inputs?: Hardware_AccelerationInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Hardware_AccelerationInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_hardware_acceleration(inputs)
return zh_hardware_acceleration(inputs)
});
+16
View File
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Auto Detect" |
*
* @param {Hardware_Acceleration_AutoInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_auto: ((inputs?: Hardware_Acceleration_AutoInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Hardware_Acceleration_AutoInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Hardware_Acceleration_AutoInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Hardware_Acceleration_AutoInputs */
const en_hardware_acceleration_auto = /** @type {(inputs: Hardware_Acceleration_AutoInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Auto Detect`)
};
const zh_hardware_acceleration_auto = /** @type {(inputs: Hardware_Acceleration_AutoInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`自动检测`)
};
/**
* | output |
* | --- |
* | "Auto Detect" |
*
* @param {Hardware_Acceleration_AutoInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_auto = /** @type {((inputs?: Hardware_Acceleration_AutoInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Hardware_Acceleration_AutoInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_hardware_acceleration_auto(inputs)
return zh_hardware_acceleration_auto(inputs)
});
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Automatically probes and uses GPU/Hardware acceleration (NVENC, QSV, AMF, VideoToolbox). If hardware acceleration is unsupported on the host, video transcodi..." |
*
* @param {Hardware_Acceleration_Auto_DescriptionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_auto_description: ((inputs?: Hardware_Acceleration_Auto_DescriptionInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Hardware_Acceleration_Auto_DescriptionInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Hardware_Acceleration_Auto_DescriptionInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Hardware_Acceleration_Auto_DescriptionInputs */
const en_hardware_acceleration_auto_description = /** @type {(inputs: Hardware_Acceleration_Auto_DescriptionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Automatically probes and uses GPU/Hardware acceleration (NVENC, QSV, AMF, VideoToolbox). If hardware acceleration is unsupported on the host, video transcoding may fail.`)
};
const zh_hardware_acceleration_auto_description = /** @type {(inputs: Hardware_Acceleration_Auto_DescriptionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`自动检测并使用 GPU/硬件加速(NVENC、QSV、AMF、VideoToolbox)。若宿主硬件不支持加速,视频转码可能会失败。`)
};
/**
* | output |
* | --- |
* | "Automatically probes and uses GPU/Hardware acceleration (NVENC, QSV, AMF, VideoToolbox). If hardware acceleration is unsupported on the host, video transcodi..." |
*
* @param {Hardware_Acceleration_Auto_DescriptionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_auto_description = /** @type {((inputs?: Hardware_Acceleration_Auto_DescriptionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Hardware_Acceleration_Auto_DescriptionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_hardware_acceleration_auto_description(inputs)
return zh_hardware_acceleration_auto_description(inputs)
});
+16
View File
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Disabled (Software)" |
*
* @param {Hardware_Acceleration_OffInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_off: ((inputs?: Hardware_Acceleration_OffInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Hardware_Acceleration_OffInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Hardware_Acceleration_OffInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Hardware_Acceleration_OffInputs */
const en_hardware_acceleration_off = /** @type {(inputs: Hardware_Acceleration_OffInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Disabled (Software)`)
};
const zh_hardware_acceleration_off = /** @type {(inputs: Hardware_Acceleration_OffInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`已禁用 (软件编码)`)
};
/**
* | output |
* | --- |
* | "Disabled (Software)" |
*
* @param {Hardware_Acceleration_OffInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_off = /** @type {((inputs?: Hardware_Acceleration_OffInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Hardware_Acceleration_OffInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_hardware_acceleration_off(inputs)
return zh_hardware_acceleration_off(inputs)
});
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Uses software libx264 encoder with constant rate factor (CRF)." |
*
* @param {Hardware_Acceleration_Off_DescriptionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_off_description: ((inputs?: Hardware_Acceleration_Off_DescriptionInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Hardware_Acceleration_Off_DescriptionInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Hardware_Acceleration_Off_DescriptionInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Hardware_Acceleration_Off_DescriptionInputs */
const en_hardware_acceleration_off_description = /** @type {(inputs: Hardware_Acceleration_Off_DescriptionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Uses software libx264 encoder with constant rate factor (CRF).`)
};
const zh_hardware_acceleration_off_description = /** @type {(inputs: Hardware_Acceleration_Off_DescriptionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`使用 CPU 的 libx264 软件编码器及 CRF 恒定画质模式。`)
};
/**
* | output |
* | --- |
* | "Uses software libx264 encoder with constant rate factor (CRF)." |
*
* @param {Hardware_Acceleration_Off_DescriptionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const hardware_acceleration_off_description = /** @type {((inputs?: Hardware_Acceleration_Off_DescriptionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Hardware_Acceleration_Off_DescriptionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_hardware_acceleration_off_description(inputs)
return zh_hardware_acceleration_off_description(inputs)
});
@@ -1,5 +1,9 @@
import { createLazyFileRoute } from '@tanstack/react-router'
import { VideoTranscodeStrategy, UpdateTeamSettingsRequest } from '@shumai/dtos'
import {
VideoTranscodeStrategy,
HardwareAcceleration,
UpdateTeamSettingsRequest,
} from '@shumai/dtos'
import { client } from '@/ui/api/client'
import { AgentsSettings } from '@/ui/components/settings/AgentsSettings'
import { ProvidersSettings } from '@/ui/components/settings/ProvidersSettings'
@@ -244,6 +248,16 @@ function TeamSettingsPage() {
})
}
const handleHardwareAccelerationChange = (value: HardwareAcceleration) => {
updateSettings({
teamId,
data: {
key: 'transcode.hardwareAcceleration',
value: value,
},
})
}
if (isSettingsLoading || isMeLoading) {
return (
<div className="flex h-screen items-center justify-center">
@@ -265,6 +279,10 @@ function TeamSettingsPage() {
currentVideoStrategy = VideoTranscodeStrategy.all
}
const currentHardwareAcceleration =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(settings as any)?.transcode?.hardwareAcceleration || HardwareAcceleration.off
return (
<div className="h-full bg-background font-sans selection:bg-primary/20 transition-colors duration-300">
<div className="flex flex-col md:flex-row h-full">
@@ -667,6 +685,46 @@ function TeamSettingsPage() {
</div>
</div>
</div>
{/* Hardware Acceleration */}
<div className="space-y-3 pt-6 border-t border-border">
<h3 className="text-lg font-medium">{m.hardware_acceleration()}</h3>
<div className="space-y-3">
<div
className={cn(
'cursor-pointer rounded-lg border p-4 transition-all hover:border-primary',
currentHardwareAcceleration === HardwareAcceleration.off
? 'border-primary bg-primary/5'
: 'border-border',
)}
onClick={() =>
handleHardwareAccelerationChange(HardwareAcceleration.off)
}
>
<div className="font-semibold">{m.hardware_acceleration_off()}</div>
<div className="text-sm text-muted-foreground">
{m.hardware_acceleration_off_description()}
</div>
</div>
<div
className={cn(
'cursor-pointer rounded-lg border p-4 transition-all hover:border-primary',
currentHardwareAcceleration === HardwareAcceleration.auto
? 'border-primary bg-primary/5'
: 'border-border',
)}
onClick={() =>
handleHardwareAccelerationChange(HardwareAcceleration.auto)
}
>
<div className="font-semibold">{m.hardware_acceleration_auto()}</div>
<div className="text-sm text-muted-foreground">
{m.hardware_acceleration_auto_description()}
</div>
</div>
</div>
</div>
</CardContent>
</Card>
</div>