diff options
| author | metamuffin <metamuffin@disroot.org> | 2023-10-02 23:53:29 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2023-10-02 23:53:29 +0200 | 
| commit | 985d94d1a9a2712f51dc41a0312f9a7053211e85 (patch) | |
| tree | 7479035c95f2dfb3ad1925622d9132aa29beaaff /web/script/player/profiles.ts | |
| parent | 1f11c16aefe71d68605d2cd0ad5da9c016aa3570 (diff) | |
| download | jellything-985d94d1a9a2712f51dc41a0312f9a7053211e85.tar jellything-985d94d1a9a2712f51dc41a0312f9a7053211e85.tar.bz2 jellything-985d94d1a9a2712f51dc41a0312f9a7053211e85.tar.zst  | |
"working" adaptive br with hardcoded remux br
Diffstat (limited to 'web/script/player/profiles.ts')
| -rw-r--r-- | web/script/player/profiles.ts | 29 | 
1 files changed, 20 insertions, 9 deletions
diff --git a/web/script/player/profiles.ts b/web/script/player/profiles.ts index b4de534..50be9d3 100644 --- a/web/script/player/profiles.ts +++ b/web/script/player/profiles.ts @@ -1,6 +1,8 @@  import { OVar } from "../jshelper/mod.ts";  import { EncodingProfile, JhlsMetadata } from "./jhls.d.ts"; +const PROFILE_UP_FAC = 0.7 +  export interface EncodingProfileExt extends EncodingProfile { id: number, order: number }  export class ProfileSelector {      profiles_video: EncodingProfileExt[] = [] @@ -30,17 +32,26 @@ export class ProfileSelector {          return []      }      select_optimal_profile(track: number, profile: OVar<EncodingProfileExt | undefined>) { -        if (this.bandwidth.value < 5000 * 1000) { -            profile.value = this.profile_list_for_track(track)[0] -        } else { -            profile.value = undefined +        const profs = this.profile_list_for_track(track) + +        const co = profile.value?.order ?? -1 +        const current_bitrate = profile_bw(profs[co], 5000 * 1000) +        const next_bitrate = profile_bw(profs[co - 1], 5000 * 1000) +        console.log({ current_bitrate, next_bitrate, co, bandwidth: this.bandwidth.value * 8 }); +        if (current_bitrate > this.bandwidth.value * 8 && co + 1 < profs.length) { +            console.log("profile up"); +            profile.value = profs[co + 1] +        } +        if (next_bitrate < this.bandwidth.value * 8 * PROFILE_UP_FAC && co >= 0) { +            console.log("profile down"); +            profile.value = profs[co - 1]          }      }  } -function profile_bw(p: EncodingProfile): number { -    if (p.audio) return p.audio.bitrate / 8 -    if (p.video) return p.video.bitrate / 8 -    if (p.subtitles) return 100 -    return 0 +function profile_bw(p?: EncodingProfile, fallback = 0): number { +    if (p?.audio) return p.audio.bitrate / 8 +    if (p?.video) return p.video.bitrate / 8 +    if (p?.subtitles) return 100 +    return fallback  }  |