import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "../ui/dialog"; import ActivityIndicator from "../indicators/activity-indicator"; import { Ffprobe } from "@/types/stats"; import { Button } from "../ui/button"; import copy from "copy-to-clipboard"; import { CameraConfig } from "@/types/frigateConfig"; import { useEffect, useState } from "react"; import axios from "axios"; import { toast } from "sonner"; import { Toaster } from "../ui/sonner"; type CameraInfoDialogProps = { camera: CameraConfig; showCameraInfoDialog: boolean; setShowCameraInfoDialog: React.Dispatch>; }; export default function CameraInfoDialog({ camera, showCameraInfoDialog, setShowCameraInfoDialog, }: CameraInfoDialogProps) { const [ffprobeInfo, setFfprobeInfo] = useState(); useEffect(() => { axios .get("ffprobe", { params: { paths: `camera:${camera.name}`, }, }) .then((res) => { if (res.status === 200) { setFfprobeInfo(res.data); } else { toast.error(`Unable to probe camera: ${res.statusText}`, { position: "top-center", }); } }) .catch((error) => { toast.error(`Unable to probe camera: ${error.response.data.message}`, { position: "top-center", }); }); // we know that these deps are correct // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const onCopyFfprobe = async () => { copy(JSON.stringify(ffprobeInfo)); toast.success("Copied probe data to clipboard."); }; function gcd(a: number, b: number): number { return b === 0 ? a : gcd(b, a % b); } return ( <> {camera.name.replaceAll("_", " ")} Camera Probe Info Stream data is obtained with ffprobe.
{ffprobeInfo ? (
{ffprobeInfo.map((stream, idx) => (
Stream {idx + 1}
{stream.return_code == 0 ? (
{stream.stdout.streams.map((codec, idx) => (
{codec.width ? (
Video:
Codec: {" "} {codec.codec_long_name}
{codec.width && codec.height ? ( <> Resolution:{" "} {" "} {codec.width}x{codec.height} ( {codec.width / gcd(codec.width, codec.height)} / {codec.height / gcd(codec.width, codec.height)}{" "} aspect ratio) ) : ( Resolution:{" "} Unknown )}
FPS:{" "} {codec.avg_frame_rate == "0/0" ? "Unknown" : codec.avg_frame_rate}
) : (
Audio:
Codec:{" "} {codec.codec_long_name}
)}
))}
) : (
Error: {stream.stderr}
)}
))}
) : (
Fetching Camera Data
)}
); }