Only calculate inpoint offset for beginning of hour segment

This commit is contained in:
Nicolas Mowen 2025-05-19 08:06:08 -06:00
parent 14e9b66e98
commit 9bcfb5a852
4 changed files with 40 additions and 1 deletions

View File

@ -109,6 +109,7 @@ imdecode
imencode
imread
imwrite
inpoint
interp
iostat
iotop

View File

@ -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);

View File

@ -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 (
<>

View File

@ -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;
}