aboutsummaryrefslogtreecommitdiff
path: root/web/script/player/mediacaps.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/script/player/mediacaps.ts')
-rw-r--r--web/script/player/mediacaps.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/web/script/player/mediacaps.ts b/web/script/player/mediacaps.ts
index b722904..1fec967 100644
--- a/web/script/player/mediacaps.ts
+++ b/web/script/player/mediacaps.ts
@@ -1,4 +1,4 @@
-import { SourceTrack, SourceTrackKind } from "./jhls.d.ts";
+import { EncodingProfile, SourceTrack, SourceTrackKind } from "./jhls.d.ts";
const cache = new Map<string, boolean>()
@@ -47,6 +47,29 @@ async function test_media_capability_inner(track: SourceTrack) {
return res?.supported ?? false
}
+export function track_to_content_type(track: SourceTrack): string | undefined {
+ const codec = MASTROSKA_CODEC_MAP[track.codec]
+ if (!codec) return
+ return `${get_track_kind(track.kind)}/webm; codecs="${codec}"`
+}
+export function profile_to_partial_track(profile: EncodingProfile): SourceTrack {
+ if (profile.audio) {
+ return {
+ codec: FFMPEG_ENCODER_CODEC_MAP[profile.audio.codec],
+ kind: { audio: { bit_depth: 16, channels: 2, sample_rate: 48000 } },
+ name: "test audio",
+ language: "en"
+ }
+ } else if (profile.video) {
+ return {
+ codec: FFMPEG_ENCODER_CODEC_MAP[profile.video.codec],
+ kind: { video: { fps: 30, height: 1080, width: 1090 } },
+ language: "en",
+ name: "test video"
+ }
+ } else throw new Error("todo: subtitles");
+}
+
const MASTROSKA_CODEC_MAP: { [key: string]: string } = {
"V_VP9": "vp9",
"V_VP8": "vp8",
@@ -58,6 +81,14 @@ const MASTROSKA_CODEC_MAP: { [key: string]: string } = {
"S_TEXT/WEBVTT": "webvtt",
}
+const FFMPEG_ENCODER_CODEC_MAP: { [key: string]: string } = {
+ "libsvtav1": "V_AV1",
+ "libvpx": "V_VP8",
+ "libvpx-vp9": "V_VP9",
+ "opus": "A_OPUS",
+ "libopus": "A_OPUS",
+}
+
export function get_track_kind(track: SourceTrackKind): "audio" | "video" | "subtitles" {
if (track.audio) return "audio"
if (track.video) return "video"