Misc fixes (#18289)

* Fix key not moved

* Account for HLS start offset when seeking and calculating update time
This commit is contained in:
Nicolas Mowen 2025-05-18 17:23:01 -06:00 committed by GitHub
parent f4d5ebf4db
commit 717517aeb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 10 deletions

View File

@ -37,6 +37,7 @@ type HlsVideoPlayerProps = {
supportsFullscreen: boolean;
fullscreen: boolean;
frigateControls?: boolean;
inpointOffset?: number;
onClipEnded?: () => void;
onPlayerLoaded?: () => void;
onTimeUpdate?: (time: number) => void;
@ -55,6 +56,7 @@ export default function HlsVideoPlayer({
supportsFullscreen,
fullscreen,
frigateControls = true,
inpointOffset = 0,
onClipEnded,
onPlayerLoaded,
onTimeUpdate,
@ -187,6 +189,16 @@ export default function HlsVideoPlayer({
};
}, [videoRef, controlsOpen]);
const getVideoTime = useCallback(() => {
const currentTime = videoRef.current?.currentTime;
if (!currentTime) {
return undefined;
}
return currentTime + inpointOffset;
}, [videoRef, inpointOffset]);
return (
<TransformWrapper
minScale={1.0}
@ -218,7 +230,7 @@ export default function HlsVideoPlayer({
hotKeys={hotKeys}
onPlayPause={onPlayPause}
onSeek={(diff) => {
const currentTime = videoRef.current?.currentTime;
const currentTime = getVideoTime();
if (!videoRef.current || !currentTime) {
return;
@ -234,8 +246,10 @@ export default function HlsVideoPlayer({
}
}}
onUploadFrame={async () => {
if (videoRef.current && onUploadFrame) {
const resp = await onUploadFrame(videoRef.current.currentTime);
const frameTime = getVideoTime();
if (frameTime && onUploadFrame) {
const resp = await onUploadFrame(frameTime);
if (resp && resp.status == 200) {
toast.success(t("toast.success.submittedFrigatePlus"), {
@ -335,11 +349,17 @@ export default function HlsVideoPlayer({
}
}
}}
onTimeUpdate={() =>
onTimeUpdate && videoRef.current
? onTimeUpdate(videoRef.current.currentTime)
: undefined
}
onTimeUpdate={() => {
if (!onTimeUpdate) {
return;
}
const frameTime = getVideoTime();
if (frameTime) {
onTimeUpdate(frameTime);
}
}}
onLoadedData={() => {
onPlayerLoaded?.();
handleLoadedMetadata();

View File

@ -17,6 +17,7 @@ export class DynamicVideoController {
// playback
private recordings: Recording[] = [];
private timeRange: TimeRange = { after: 0, before: 0 };
private inpointOffset: number = 0;
private annotationOffset: number;
private timeToStart: number | undefined = undefined;
@ -41,6 +42,7 @@ export class DynamicVideoController {
newPlayback(newPlayback: DynamicPlayback) {
this.recordings = newPlayback.recordings;
this.timeRange = newPlayback.timeRange;
this.inpointOffset = this.timeRange.after - this.recordings[0].start_time;
if (this.timeToStart) {
this.seekToTimestamp(this.timeToStart);
@ -92,6 +94,9 @@ export class DynamicVideoController {
return true;
});
// adjust for HLS inpoint offset
seekSeconds -= this.inpointOffset;
if (seekSeconds != 0) {
this.playerController.currentTime = seekSeconds;

View File

@ -197,6 +197,19 @@ export default function DynamicVideoPlayer({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [controller, recordings]);
/** 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.
*/
const inpointOffset = useMemo(() => {
if (!recordingParams || !recordings) {
return 0;
}
return recordingParams.after - recordings[0].start_time;
}, [recordingParams, recordings]);
return (
<>
<HlsVideoPlayer
@ -207,6 +220,7 @@ export default function DynamicVideoPlayer({
hotKeys={hotKeys}
supportsFullscreen={supportsFullscreen}
fullscreen={fullscreen}
inpointOffset={inpointOffset}
onTimeUpdate={onTimeUpdate}
onPlayerLoaded={onPlayerLoaded}
onClipEnded={onClipEnded}

View File

@ -675,10 +675,9 @@ export function RecordingView({
}
return (
<Tooltip>
<Tooltip key={cam}>
<TooltipTrigger asChild>
<div
key={cam}
className={
mainCameraAspect == "tall" ? "w-full" : "h-full"
}