diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-27 14:47:15 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-27 14:47:15 +0200 |
commit | 0ed5ae95283c4820a5bf165d0971ba021bed9320 (patch) | |
tree | b2a57f5509148f388209ec3cdf835cee109be800 /web/script/player/mediacaps.ts | |
parent | f881372c0a024e534d87844040a0c8678a39d85d (diff) | |
download | jellything-0ed5ae95283c4820a5bf165d0971ba021bed9320.tar jellything-0ed5ae95283c4820a5bf165d0971ba021bed9320.tar.bz2 jellything-0ed5ae95283c4820a5bf165d0971ba021bed9320.tar.zst |
not hardcoding source source codecs
Diffstat (limited to 'web/script/player/mediacaps.ts')
-rw-r--r-- | web/script/player/mediacaps.ts | 33 |
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" |