Skip to content

Commit a07fcb7

Browse files
committed
feat(media): support cloud codec via ffmpeg
1 parent d49747e commit a07fcb7

6 files changed

Lines changed: 50 additions & 17 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@types/sha256": "^0.2.2",
4747
"@types/streamsaver": "^2.0.5",
4848
"@vitejs/plugin-legacy": "^8.0.1",
49+
"baseline-browser-mapping": "^2.10.29",
4950
"cross-env": "^10.1.0",
5051
"husky": "^9.1.7",
5152
"lint-staged": "^16.4.0",

pnpm-lock.yaml

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lang/en/manage.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"media_music": "Music",
3434
"media_image": "Images",
3535
"media_book": "Books",
36-
"media_settings": "Settings"
36+
"media_settings": "Settings",
37+
"transcode": "Transcode"
3738
},
3839
"title": "OpenList Management",
3940
"not_admin": "You are not an admin user, please login with an admin account.",

src/pages/home/previews/video.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { ArtPlayerIconsSubtitle } from "~/components/icons"
4242
import { useNavigate } from "@solidjs/router"
4343
import "./artplayer.css"
4444
import { registerAc3Decoder } from "@mediabunny/ac3"
45+
import { requestTranscodePlay } from "~/utils/media_api"
4546
// 仅在启用 MediaBunny 时注册 AC3 解码器
4647
if (isMediaBunnyEnabled()) {
4748
registerAc3Decoder()
@@ -350,17 +351,43 @@ const Preview = () => {
350351
},
351352
})
352353

353-
onMount(() => {
354-
// 预下载视频文件的前几个区块(不阻塞,与 Artplayer 初始化同时进行)
355-
if (objStore.raw_url) {
354+
onMount(async () => {
355+
// ---- 云端转码判断 ----
356+
// 播放前先调用后端转码决策接口,如果需要转码则使用 HLS master_url 播放
357+
let useTranscode = false
358+
try {
359+
const tcResp = await requestTranscodePlay(pathname())
360+
if (
361+
tcResp.code === 200 &&
362+
tcResp.data?.transcode &&
363+
tcResp.data.master_url
364+
) {
365+
useTranscode = true
366+
option.url = tcResp.data.master_url
367+
option.type = "m3u8"
368+
console.log(
369+
`[transcode] 使用云端转码播放: job=${tcResp.data.job_id}, profile=${tcResp.data.profile}`,
370+
)
371+
}
372+
} catch (e) {
373+
// 转码接口失败(可能未开启),静默降级到直链播放
374+
console.debug("[transcode] 转码接口不可用,使用直链播放", e)
375+
}
376+
377+
// 预下载视频文件的前几个区块(仅直链模式,转码模式由 HLS.js 管理)
378+
if (!useTranscode && objStore.raw_url) {
356379
void prefetchVideoChunks(objStore.raw_url, {
357380
byteRange: 8 * 1024 * 1024,
358381
timeoutMs: 3000,
359382
})
360383
}
361384
player = new Artplayer(option)
362-
// “仅音频”模式:原生 <video> 解码视频,mediabunny 只提供音轨
363-
if (getMediaBunnyMode() === "audio_only" && objStore.raw_url) {
385+
// "仅音频"模式:原生 <video> 解码视频,mediabunny 只提供音轨(仅直链模式)
386+
if (
387+
!useTranscode &&
388+
getMediaBunnyMode() === "audio_only" &&
389+
objStore.raw_url
390+
) {
364391
attachMediabunnyAudio(player, objStore.raw_url)
365392
}
366393
let auto_fullscreen: boolean

src/pages/manage/sidemenu_items.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ export const side_menu_items: SideMenuItem[] = [
9999
to: "/@manage/settings/traffic",
100100
component: () => <CommonSettings group={Group.TRAFFIC} />,
101101
},
102+
{
103+
title: "manage.sidemenu.transcode",
104+
icon: BsCameraFill,
105+
to: "/@manage/settings/transcode",
106+
component: () => <CommonSettings group={Group.TRANSCODE} />,
107+
},
102108
{
103109
title: "manage.sidemenu.other",
104110
icon: BsMedium,

src/types/setting.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum Group {
1414
FTP,
1515
TRAFFIC,
1616
MEDIA,
17+
TRANSCODE,
1718
}
1819
export enum Flag {
1920
PUBLIC,

0 commit comments

Comments
 (0)