From 9bcfb5a8524835ecfaee8e4853ac2d612dcfb302 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 19 May 2025 08:06:08 -0600 Subject: [PATCH] Only calculate inpoint offset for beginning of hour segment --- .cspell/frigate-dictionary.txt | 1 + .../player/dynamic/DynamicVideoController.ts | 6 ++++- .../player/dynamic/DynamicVideoPlayer.tsx | 8 ++++++ web/src/utils/videoUtil.ts | 26 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 web/src/utils/videoUtil.ts diff --git a/.cspell/frigate-dictionary.txt b/.cspell/frigate-dictionary.txt index e9405c9f7..6e66a4704 100644 --- a/.cspell/frigate-dictionary.txt +++ b/.cspell/frigate-dictionary.txt @@ -109,6 +109,7 @@ imdecode imencode imread imwrite +inpoint interp iostat iotop diff --git a/web/src/components/player/dynamic/DynamicVideoController.ts b/web/src/components/player/dynamic/DynamicVideoController.ts index a820c8aae..0683481c6 100644 --- a/web/src/components/player/dynamic/DynamicVideoController.ts +++ b/web/src/components/player/dynamic/DynamicVideoController.ts @@ -2,6 +2,7 @@ import { Recording } from "@/types/record"; import { DynamicPlayback } from "@/types/playback"; import { PreviewController } from "../PreviewPlayer"; import { TimeRange, ObjectLifecycleSequence } from "@/types/timeline"; +import { calculateInpointOffset } from "@/utils/videoUtil"; type PlayerMode = "playback" | "scrubbing"; @@ -42,7 +43,10 @@ export class DynamicVideoController { newPlayback(newPlayback: DynamicPlayback) { this.recordings = newPlayback.recordings; this.timeRange = newPlayback.timeRange; - this.inpointOffset = this.timeRange.after - this.recordings[0].start_time; + this.inpointOffset = calculateInpointOffset( + this.timeRange.after, + this.recordings[0], + ); if (this.timeToStart) { this.seekToTimestamp(this.timeToStart); diff --git a/web/src/components/player/dynamic/DynamicVideoPlayer.tsx b/web/src/components/player/dynamic/DynamicVideoPlayer.tsx index 10b15312a..3c20a8b30 100644 --- a/web/src/components/player/dynamic/DynamicVideoPlayer.tsx +++ b/web/src/components/player/dynamic/DynamicVideoPlayer.tsx @@ -13,6 +13,7 @@ import { VideoResolutionType } from "@/types/live"; import axios from "axios"; import { cn } from "@/lib/utils"; import { useTranslation } from "react-i18next"; +import { calculateInpointOffset } from "@/utils/videoUtil"; /** * Dynamically switches between video playback and scrubbing preview player. @@ -197,6 +198,7 @@ export default function DynamicVideoPlayer({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [controller, recordings]); +<<<<<<< Updated upstream /** the HLS endpoint returns the vod segments with the first * segment of the hour trimmed, meaning it will start at * the beginning of the hour, cutting off any difference @@ -209,6 +211,12 @@ export default function DynamicVideoPlayer({ return recordingParams.after - recordings[0].start_time; }, [recordingParams, recordings]); +======= + const inpointOffset = useMemo( + () => calculateInpointOffset(recordingParams.after, (recordings || [])[0]), + [recordingParams, recordings], + ); +>>>>>>> Stashed changes return ( <> diff --git a/web/src/utils/videoUtil.ts b/web/src/utils/videoUtil.ts new file mode 100644 index 000000000..9f22e19d7 --- /dev/null +++ b/web/src/utils/videoUtil.ts @@ -0,0 +1,26 @@ +import { Recording } from "@/types/record"; + +/** the HLS endpoint returns the vod segments with the first + * segment of the hour trimmed, meaning it will start at + * the beginning of the hour, cutting off any difference + * that the segment has. + */ +export function calculateInpointOffset( + timeRangeStart: number | undefined, + firstRecordingSegment: Recording | undefined, +): number { + if (!timeRangeStart || !firstRecordingSegment) { + return 0; + } + + // if the first recording segment does not cross over + // the beginning of the time range then there is no offset + if ( + firstRecordingSegment.start_time < timeRangeStart && + firstRecordingSegment.end_time > timeRangeStart + ) { + return timeRangeStart - firstRecordingSegment.start_time; + } + + return 0; +}