mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-01 03:56:38 +08:00
优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { Media } from '../types'
|
||||
import { isRemoteEmbyID } from '../utils/remoteEmby'
|
||||
|
||||
export type PlayerMode = 'direct' | 'hls'
|
||||
|
||||
@@ -6,16 +7,27 @@ const directContainers = ['mp4', 'webm', 'm4v']
|
||||
const directVideoCodecs = ['h264', 'avc', 'avc1']
|
||||
const directAudioCodecs = ['aac', 'mp3', 'opus']
|
||||
|
||||
/**
|
||||
* 判断媒体是否为远程直链或挂载直连流媒体(STRM 或 Emby 远程挂载)。
|
||||
* 这类媒体服务端 302 重定向到直链或进行原生流中继,本地不具备原始文件,
|
||||
* 无法也不应该进行 ffmpeg 转码,恒走直连播放。
|
||||
*/
|
||||
export function isDirectStreamMedia(media?: Media | null): boolean {
|
||||
if (!media) return false
|
||||
if (isRemoteEmbyID(media.id)) return true
|
||||
const container = (media.container ?? '').toLowerCase()
|
||||
return container.includes('strm') || String(media.strm_url ?? '').trim() !== ''
|
||||
}
|
||||
|
||||
export function pickPlayerMode(media: Media): PlayerMode {
|
||||
return needsTranscodeForBrowser(media) ? 'hls' : 'direct'
|
||||
}
|
||||
|
||||
export function needsTranscodeForBrowser(media: Media): boolean {
|
||||
// Emby 远程挂载与 .strm 媒体一样,均为直连流,无法进行本地转码,恒走 direct play。
|
||||
if (isDirectStreamMedia(media)) return false
|
||||
|
||||
const container = (media.container ?? '').toLowerCase()
|
||||
// .strm 媒体内容是远程直链(服务端 302 到播放 CDN 或反向代理),
|
||||
// 浏览器直接播放该远程流即可,转码无意义且必然失败(ffmpeg 无法读取
|
||||
// 文本 strm),恒走 direct play。
|
||||
if (container.includes('strm') || String(media.strm_url ?? '').trim() !== '') return false
|
||||
const videoCodec = (media.video_codec ?? '').toLowerCase()
|
||||
const audioCodec = (media.audio_codec ?? '').toLowerCase()
|
||||
const containerOK = directContainers.some((item) => container.includes(item))
|
||||
@@ -23,3 +35,4 @@ export function needsTranscodeForBrowser(media: Media): boolean {
|
||||
const audioOK = !audioCodec || directAudioCodecs.some((item) => audioCodec.includes(item))
|
||||
return !(containerOK && videoOK && audioOK)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user