Fix excessive memory usage on chrome+webkit

This commit is contained in:
mrjvs 2023-10-18 15:30:04 +02:00
parent 0ca585f70a
commit 037960f587
3 changed files with 7 additions and 12 deletions

View File

@ -81,6 +81,7 @@ export function CaptionsView({ id }: { id: string }) {
<CaptionOption onClick={() => disableCaption()}>Off</CaptionOption> <CaptionOption onClick={() => disableCaption()}>Off</CaptionOption>
{langs.map((v) => ( {langs.map((v) => (
<CaptionOption <CaptionOption
key={v.lang}
countryCode={v.lang} countryCode={v.lang}
selected={lang === v.lang} selected={lang === v.lang}
onClick={() => updateCaption()} onClick={() => updateCaption()}

View File

@ -1,10 +1,7 @@
import { ReactNode, useEffect, useMemo, useRef } from "react"; import { ReactNode, useEffect, useMemo, useRef } from "react";
import { makeVideoElementDisplayInterface } from "@/components/player/display/base"; import { makeVideoElementDisplayInterface } from "@/components/player/display/base";
import { import { convertSubtitlesToDataurl } from "@/components/player/utils/captions";
convertSubtitlesToVtt,
vttToDataurl,
} from "@/components/player/utils/captions";
import { playerStatus } from "@/stores/player/slices/source"; import { playerStatus } from "@/stores/player/slices/source";
import { usePlayerStore } from "@/stores/player/store"; import { usePlayerStore } from "@/stores/player/store";
@ -47,10 +44,9 @@ function VideoElement() {
const captionAsTrack = usePlayerStore((s) => s.caption.asTrack); const captionAsTrack = usePlayerStore((s) => s.caption.asTrack);
const language = usePlayerStore((s) => s.caption.selected?.language); const language = usePlayerStore((s) => s.caption.selected?.language);
const trackData = useMemo( const trackData = useMemo(() => {
() => (srtData ? vttToDataurl(convertSubtitlesToVtt(srtData)) : null), return srtData ? convertSubtitlesToDataurl(srtData) : null;
[srtData] }, [srtData]);
);
// report video element to display interface // report video element to display interface
useEffect(() => { useEffect(() => {

View File

@ -40,8 +40,6 @@ export function parseSubtitles(text: string): CaptionCueType[] {
return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[]; return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[];
} }
export function vttToDataurl(vtt: string): string { export function convertSubtitlesToDataurl(text: string): string {
const bytes = new TextEncoder().encode(vtt); return `data:text/vtt;${convertSubtitlesToVtt(text)}`;
const encoded = btoa(String.fromCodePoint(...bytes));
return `data:text/vtt;base64,${encoded}`;
} }