use recording snapshot for frigate+ frame submission from VideoControls

rather than a canvas grab/paint, which may not always align with an ffmpeg snapshot due to keyframes
This commit is contained in:
Josh Hawkins 2026-04-19 12:29:42 -05:00
parent 899b4ed230
commit b1d5b12aeb
5 changed files with 70 additions and 7 deletions

View File

@ -4,7 +4,8 @@
"noPreviewFoundFor": "No Preview Found for {{cameraName}}", "noPreviewFoundFor": "No Preview Found for {{cameraName}}",
"submitFrigatePlus": { "submitFrigatePlus": {
"title": "Submit this frame to Frigate+?", "title": "Submit this frame to Frigate+?",
"submit": "Submit" "submit": "Submit",
"previewError": "Could not load snapshot preview. The recording may not be available at this time."
}, },
"livePlayerRequiredIOSVersion": "iOS 17.1 or greater is required for this live stream type.", "livePlayerRequiredIOSVersion": "iOS 17.1 or greater is required for this live stream type.",
"streamOffline": { "streamOffline": {

View File

@ -636,6 +636,13 @@ export function TrackingDetails({
return axios.post(`/${event.camera}/plus/${currentTime}`); return axios.post(`/${event.camera}/plus/${currentTime}`);
}, [event.camera, currentTime]); }, [event.camera, currentTime]);
const getSnapshotUrlForPlus = useCallback(() => {
if (!currentTime) {
return undefined;
}
return `${apiHost}api/${event.camera}/recordings/${currentTime}/snapshot.jpg?height=500`;
}, [apiHost, event.camera, currentTime]);
if (!config) { if (!config) {
return <ActivityIndicator />; return <ActivityIndicator />;
} }
@ -683,6 +690,7 @@ export function TrackingDetails({
onTimeUpdate={handleTimeUpdate} onTimeUpdate={handleTimeUpdate}
onSeekToTime={handleSeekToTime} onSeekToTime={handleSeekToTime}
onUploadFrame={onUploadFrameToPlus} onUploadFrame={onUploadFrameToPlus}
getSnapshotUrl={getSnapshotUrlForPlus}
onPlaying={() => setIsVideoLoading(false)} onPlaying={() => setIsVideoLoading(false)}
setFullResolution={setFullResolution} setFullResolution={setFullResolution}
toggleFullscreen={toggleFullscreen} toggleFullscreen={toggleFullscreen}

View File

@ -53,6 +53,7 @@ type HlsVideoPlayerProps = {
onSeekToTime?: (timestamp: number, play?: boolean) => void; onSeekToTime?: (timestamp: number, play?: boolean) => void;
setFullResolution?: React.Dispatch<React.SetStateAction<VideoResolutionType>>; setFullResolution?: React.Dispatch<React.SetStateAction<VideoResolutionType>>;
onUploadFrame?: (playTime: number) => Promise<AxiosResponse> | undefined; onUploadFrame?: (playTime: number) => Promise<AxiosResponse> | undefined;
getSnapshotUrl?: (playTime: number) => string | undefined;
toggleFullscreen?: () => void; toggleFullscreen?: () => void;
onError?: (error: RecordingPlayerError) => void; onError?: (error: RecordingPlayerError) => void;
isDetailMode?: boolean; isDetailMode?: boolean;
@ -78,6 +79,7 @@ export default function HlsVideoPlayer({
onSeekToTime, onSeekToTime,
setFullResolution, setFullResolution,
onUploadFrame, onUploadFrame,
getSnapshotUrl,
toggleFullscreen, toggleFullscreen,
onError, onError,
isDetailMode = false, isDetailMode = false,
@ -331,6 +333,13 @@ export default function HlsVideoPlayer({
videoRef.current.playbackRate = rate; videoRef.current.playbackRate = rate;
} }
}} }}
getSnapshotUrl={() => {
const frameTime = getVideoTime();
if (!frameTime || !getSnapshotUrl) {
return undefined;
}
return getSnapshotUrl(frameTime);
}}
onUploadFrame={async () => { onUploadFrame={async () => {
const frameTime = getVideoTime(); const frameTime = getVideoTime();

View File

@ -1,4 +1,5 @@
import { useCallback, useMemo, useRef, useState } from "react"; import { useCallback, useMemo, useRef, useState } from "react";
import { LuFolderX } from "react-icons/lu";
import { isDesktop, isMobileOnly, isSafari } from "react-device-detect"; import { isDesktop, isMobileOnly, isSafari } from "react-device-detect";
import { LuPause, LuPlay } from "react-icons/lu"; import { LuPause, LuPlay } from "react-icons/lu";
import { import {
@ -71,6 +72,7 @@ type VideoControlsProps = {
onSeek: (diff: number) => void; onSeek: (diff: number) => void;
onSetPlaybackRate: (rate: number) => void; onSetPlaybackRate: (rate: number) => void;
onUploadFrame?: () => void; onUploadFrame?: () => void;
getSnapshotUrl?: () => string | undefined;
toggleFullscreen?: () => void; toggleFullscreen?: () => void;
containerRef?: React.MutableRefObject<HTMLDivElement | null>; containerRef?: React.MutableRefObject<HTMLDivElement | null>;
}; };
@ -92,6 +94,7 @@ export default function VideoControls({
onSeek, onSeek,
onSetPlaybackRate, onSetPlaybackRate,
onUploadFrame, onUploadFrame,
getSnapshotUrl,
toggleFullscreen, toggleFullscreen,
containerRef, containerRef,
}: VideoControlsProps) { }: VideoControlsProps) {
@ -288,6 +291,7 @@ export default function VideoControls({
} }
}} }}
onUploadFrame={onUploadFrame} onUploadFrame={onUploadFrame}
getSnapshotUrl={getSnapshotUrl}
containerRef={containerRef} containerRef={containerRef}
fullscreen={fullscreen} fullscreen={fullscreen}
/> />
@ -306,6 +310,7 @@ type FrigatePlusUploadButtonProps = {
onOpen: () => void; onOpen: () => void;
onClose: () => void; onClose: () => void;
onUploadFrame: () => void; onUploadFrame: () => void;
getSnapshotUrl?: () => string | undefined;
containerRef?: React.MutableRefObject<HTMLDivElement | null>; containerRef?: React.MutableRefObject<HTMLDivElement | null>;
fullscreen?: boolean; fullscreen?: boolean;
}; };
@ -314,12 +319,14 @@ function FrigatePlusUploadButton({
onOpen, onOpen,
onClose, onClose,
onUploadFrame, onUploadFrame,
getSnapshotUrl,
containerRef, containerRef,
fullscreen, fullscreen,
}: FrigatePlusUploadButtonProps) { }: FrigatePlusUploadButtonProps) {
const { t } = useTranslation(["components/player"]); const { t } = useTranslation(["components/player"]);
const [videoImg, setVideoImg] = useState<string>(); const [previewUrl, setPreviewUrl] = useState<string>();
const [previewError, setPreviewError] = useState(false);
return ( return (
<AlertDialog <AlertDialog
@ -334,6 +341,13 @@ function FrigatePlusUploadButton({
className="size-5 cursor-pointer" className="size-5 cursor-pointer"
onClick={() => { onClick={() => {
onOpen(); onOpen();
setPreviewError(false);
const snapshotUrl = getSnapshotUrl?.();
if (snapshotUrl) {
setPreviewUrl(snapshotUrl);
return;
}
if (video) { if (video) {
const videoSize = [video.clientWidth, video.clientHeight]; const videoSize = [video.clientWidth, video.clientHeight];
@ -345,7 +359,7 @@ function FrigatePlusUploadButton({
if (context) { if (context) {
context.drawImage(video, 0, 0, videoSize[0], videoSize[1]); context.drawImage(video, 0, 0, videoSize[0], videoSize[1]);
setVideoImg(canvas.toDataURL("image/webp")); setPreviewUrl(canvas.toDataURL("image/webp"));
} }
} }
}} }}
@ -362,14 +376,29 @@ function FrigatePlusUploadButton({
<AlertDialogHeader> <AlertDialogHeader>
<AlertDialogTitle>{t("submitFrigatePlus.title")}</AlertDialogTitle> <AlertDialogTitle>{t("submitFrigatePlus.title")}</AlertDialogTitle>
</AlertDialogHeader> </AlertDialogHeader>
<img className="aspect-video w-full object-contain" src={videoImg} /> {previewError ? (
<div className="flex aspect-video w-full flex-col items-center justify-center gap-2 text-center text-muted-foreground">
<LuFolderX className="size-12" />
<span>{t("submitFrigatePlus.previewError")}</span>
</div>
) : (
<img
className="aspect-video w-full object-contain"
src={previewUrl}
onError={() => setPreviewError(true)}
/>
)}
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogAction className="bg-selected" onClick={onUploadFrame}>
{t("submitFrigatePlus.submit")}
</AlertDialogAction>
<AlertDialogCancel> <AlertDialogCancel>
{t("button.cancel", { ns: "common" })} {t("button.cancel", { ns: "common" })}
</AlertDialogCancel> </AlertDialogCancel>
<AlertDialogAction
className="bg-selected text-white"
onClick={onUploadFrame}
disabled={previewError}
>
{t("submitFrigatePlus.submit")}
</AlertDialogAction>
</AlertDialogFooter> </AlertDialogFooter>
</AlertDialogContent> </AlertDialogContent>
</AlertDialog> </AlertDialog>

View File

@ -181,6 +181,21 @@ export default function DynamicVideoPlayer({
[camera, controller], [camera, controller],
); );
const getSnapshotUrlForPlus = useCallback(
(playTime: number) => {
if (!controller) {
return undefined;
}
const time = controller.getProgress(playTime);
if (!time) {
return undefined;
}
return `${apiHost}api/${camera}/recordings/${time}/snapshot.jpg?height=500`;
},
[apiHost, camera, controller],
);
// state of playback player // state of playback player
const recordingParams = useMemo( const recordingParams = useMemo(
@ -312,6 +327,7 @@ export default function DynamicVideoPlayer({
}} }}
setFullResolution={setFullResolution} setFullResolution={setFullResolution}
onUploadFrame={onUploadFrameToPlus} onUploadFrame={onUploadFrameToPlus}
getSnapshotUrl={getSnapshotUrlForPlus}
toggleFullscreen={toggleFullscreen} toggleFullscreen={toggleFullscreen}
onError={(error) => { onError={(error) => {
if (error == "stalled" && !isScrubbing) { if (error == "stalled" && !isScrubbing) {