mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-09 08:37:37 +03:00
Merge bef2ecdc23 into 8f13932c64
This commit is contained in:
commit
8de4b3f4d6
@ -22,6 +22,11 @@ import { ASPECT_VERTICAL_LAYOUT, RecordingPlayerError } from "@/types/record";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import ObjectTrackOverlay from "@/components/overlay/ObjectTrackOverlay";
|
import ObjectTrackOverlay from "@/components/overlay/ObjectTrackOverlay";
|
||||||
import { useIsAdmin } from "@/hooks/use-is-admin";
|
import { useIsAdmin } from "@/hooks/use-is-admin";
|
||||||
|
import {
|
||||||
|
downloadSnapshot,
|
||||||
|
generateSnapshotFilename,
|
||||||
|
grabVideoSnapshot,
|
||||||
|
} from "@/utils/snapshotUtil";
|
||||||
|
|
||||||
// Android native hls does not seek correctly
|
// Android native hls does not seek correctly
|
||||||
const USE_NATIVE_HLS = false;
|
const USE_NATIVE_HLS = false;
|
||||||
@ -85,7 +90,7 @@ export default function HlsVideoPlayer({
|
|||||||
currentTimeOverride,
|
currentTimeOverride,
|
||||||
transformedOverlay,
|
transformedOverlay,
|
||||||
}: HlsVideoPlayerProps) {
|
}: HlsVideoPlayerProps) {
|
||||||
const { t } = useTranslation("components/player");
|
const { t } = useTranslation(["components/player", "views/live"]);
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
|
|
||||||
@ -226,6 +231,7 @@ export default function HlsVideoPlayer({
|
|||||||
const [mobileCtrlTimeout, setMobileCtrlTimeout] = useState<NodeJS.Timeout>();
|
const [mobileCtrlTimeout, setMobileCtrlTimeout] = useState<NodeJS.Timeout>();
|
||||||
const [controls, setControls] = useState(isMobile);
|
const [controls, setControls] = useState(isMobile);
|
||||||
const [controlsOpen, setControlsOpen] = useState(false);
|
const [controlsOpen, setControlsOpen] = useState(false);
|
||||||
|
const [isSnapshotLoading, setIsSnapshotLoading] = useState(false);
|
||||||
const [zoomScale, setZoomScale] = useState(1.0);
|
const [zoomScale, setZoomScale] = useState(1.0);
|
||||||
const [videoDimensions, setVideoDimensions] = useState<{
|
const [videoDimensions, setVideoDimensions] = useState<{
|
||||||
width: number;
|
width: number;
|
||||||
@ -271,6 +277,35 @@ export default function HlsVideoPlayer({
|
|||||||
return currentTime + inpointOffset;
|
return currentTime + inpointOffset;
|
||||||
}, [videoRef, inpointOffset]);
|
}, [videoRef, inpointOffset]);
|
||||||
|
|
||||||
|
const handleSnapshot = useCallback(async () => {
|
||||||
|
setIsSnapshotLoading(true);
|
||||||
|
try {
|
||||||
|
const frameTime = getVideoTime();
|
||||||
|
const result = await grabVideoSnapshot(videoRef.current);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
downloadSnapshot(
|
||||||
|
result.data.dataUrl,
|
||||||
|
generateSnapshotFilename(
|
||||||
|
camera ?? "recording",
|
||||||
|
currentTime ?? frameTime,
|
||||||
|
config?.ui?.timezone,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
toast.success(t("snapshot.downloadStarted", { ns: "views/live" }), {
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast.error(t("snapshot.captureFailed", { ns: "views/live" }), {
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setIsSnapshotLoading(false);
|
||||||
|
}
|
||||||
|
}, [camera, config?.ui?.timezone, currentTime, getVideoTime, t, videoRef]);
|
||||||
|
const onSnapshot = camera ? handleSnapshot : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TransformWrapper
|
<TransformWrapper
|
||||||
minScale={1.0}
|
minScale={1.0}
|
||||||
@ -294,6 +329,7 @@ export default function HlsVideoPlayer({
|
|||||||
seek: true,
|
seek: true,
|
||||||
playbackRate: true,
|
playbackRate: true,
|
||||||
plusUpload: isAdmin && config?.plus?.enabled == true,
|
plusUpload: isAdmin && config?.plus?.enabled == true,
|
||||||
|
snapshot: !!onSnapshot,
|
||||||
fullscreen: supportsFullscreen,
|
fullscreen: supportsFullscreen,
|
||||||
}}
|
}}
|
||||||
setControlsOpen={setControlsOpen}
|
setControlsOpen={setControlsOpen}
|
||||||
@ -334,6 +370,9 @@ export default function HlsVideoPlayer({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onSnapshot={onSnapshot}
|
||||||
|
snapshotLoading={isSnapshotLoading}
|
||||||
|
snapshotTitle={t("snapshot.takeSnapshot", { ns: "views/live" })}
|
||||||
fullscreen={fullscreen}
|
fullscreen={fullscreen}
|
||||||
toggleFullscreen={toggleFullscreen}
|
toggleFullscreen={toggleFullscreen}
|
||||||
containerRef={containerRef}
|
containerRef={containerRef}
|
||||||
|
|||||||
@ -34,12 +34,14 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { FaCompress, FaExpand } from "react-icons/fa";
|
import { FaCompress, FaExpand } from "react-icons/fa";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { TbCameraDown } from "react-icons/tb";
|
||||||
|
|
||||||
type VideoControls = {
|
type VideoControls = {
|
||||||
volume?: boolean;
|
volume?: boolean;
|
||||||
seek?: boolean;
|
seek?: boolean;
|
||||||
playbackRate?: boolean;
|
playbackRate?: boolean;
|
||||||
plusUpload?: boolean;
|
plusUpload?: boolean;
|
||||||
|
snapshot?: boolean;
|
||||||
fullscreen?: boolean;
|
fullscreen?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,6 +50,7 @@ const CONTROLS_DEFAULT: VideoControls = {
|
|||||||
seek: true,
|
seek: true,
|
||||||
playbackRate: true,
|
playbackRate: true,
|
||||||
plusUpload: false,
|
plusUpload: false,
|
||||||
|
snapshot: false,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
};
|
};
|
||||||
const PLAYBACK_RATE_DEFAULT = isSafari ? [0.5, 1, 2] : [0.5, 1, 2, 4, 8, 16];
|
const PLAYBACK_RATE_DEFAULT = isSafari ? [0.5, 1, 2] : [0.5, 1, 2, 4, 8, 16];
|
||||||
@ -71,6 +74,9 @@ type VideoControlsProps = {
|
|||||||
onSeek: (diff: number) => void;
|
onSeek: (diff: number) => void;
|
||||||
onSetPlaybackRate: (rate: number) => void;
|
onSetPlaybackRate: (rate: number) => void;
|
||||||
onUploadFrame?: () => void;
|
onUploadFrame?: () => void;
|
||||||
|
onSnapshot?: () => void;
|
||||||
|
snapshotLoading?: boolean;
|
||||||
|
snapshotTitle?: string;
|
||||||
toggleFullscreen?: () => void;
|
toggleFullscreen?: () => void;
|
||||||
containerRef?: React.MutableRefObject<HTMLDivElement | null>;
|
containerRef?: React.MutableRefObject<HTMLDivElement | null>;
|
||||||
};
|
};
|
||||||
@ -92,6 +98,9 @@ export default function VideoControls({
|
|||||||
onSeek,
|
onSeek,
|
||||||
onSetPlaybackRate,
|
onSetPlaybackRate,
|
||||||
onUploadFrame,
|
onUploadFrame,
|
||||||
|
onSnapshot,
|
||||||
|
snapshotLoading = false,
|
||||||
|
snapshotTitle,
|
||||||
toggleFullscreen,
|
toggleFullscreen,
|
||||||
containerRef,
|
containerRef,
|
||||||
}: VideoControlsProps) {
|
}: VideoControlsProps) {
|
||||||
@ -292,6 +301,26 @@ export default function VideoControls({
|
|||||||
fullscreen={fullscreen}
|
fullscreen={fullscreen}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{features.snapshot && onSnapshot && (
|
||||||
|
<TbCameraDown
|
||||||
|
aria-label={snapshotTitle}
|
||||||
|
aria-disabled={snapshotLoading}
|
||||||
|
className={cn(
|
||||||
|
"size-5",
|
||||||
|
snapshotLoading
|
||||||
|
? "cursor-not-allowed opacity-50"
|
||||||
|
: "cursor-pointer",
|
||||||
|
)}
|
||||||
|
title={snapshotTitle}
|
||||||
|
onClick={(e: React.MouseEvent<SVGElement>) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
if (snapshotLoading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onSnapshot();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{features.fullscreen && toggleFullscreen && (
|
{features.fullscreen && toggleFullscreen && (
|
||||||
<div className="cursor-pointer" onClick={toggleFullscreen}>
|
<div className="cursor-pointer" onClick={toggleFullscreen}>
|
||||||
{fullscreen ? <FaCompress /> : <FaExpand />}
|
{fullscreen ? <FaCompress /> : <FaExpand />}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { baseUrl } from "@/api/baseUrl";
|
import { baseUrl } from "@/api/baseUrl";
|
||||||
|
import { formatUnixTimestampToDateTime } from "@/utils/dateUtil";
|
||||||
|
|
||||||
type SnapshotResponse = {
|
type SnapshotResponse = {
|
||||||
dataUrl: string;
|
dataUrl: string;
|
||||||
@ -97,17 +98,29 @@ export function downloadSnapshot(dataUrl: string, filename: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateSnapshotFilename(cameraName: string): string {
|
export function generateSnapshotFilename(
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, -5);
|
cameraName: string,
|
||||||
|
timestampSeconds?: number,
|
||||||
|
timezone?: string,
|
||||||
|
): string {
|
||||||
|
const seconds =
|
||||||
|
typeof timestampSeconds === "number" && Number.isFinite(timestampSeconds)
|
||||||
|
? timestampSeconds
|
||||||
|
: Date.now() / 1000;
|
||||||
|
const timestamp = formatUnixTimestampToDateTime(seconds, {
|
||||||
|
timezone,
|
||||||
|
date_format: "yyyy-MM-dd'T'HH-mm-ss",
|
||||||
|
});
|
||||||
return `${cameraName}_snapshot_${timestamp}.jpg`;
|
return `${cameraName}_snapshot_${timestamp}.jpg`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function grabVideoSnapshot(): Promise<SnapshotResult> {
|
export async function grabVideoSnapshot(
|
||||||
|
targetVideo?: HTMLVideoElement | null,
|
||||||
|
): Promise<SnapshotResult> {
|
||||||
try {
|
try {
|
||||||
// Find the video element in the player
|
const videoElement =
|
||||||
const videoElement = document.querySelector(
|
targetVideo ??
|
||||||
"#player-container video",
|
(document.querySelector("#player-container video") as HTMLVideoElement);
|
||||||
) as HTMLVideoElement;
|
|
||||||
|
|
||||||
if (!videoElement) {
|
if (!videoElement) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user