Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set image height to make bandwidth usage lower #12024

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions web/src/components/camera/CameraImage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useApiHost } from "@/api";
import { useEffect, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import useSWR from "swr";
import ActivityIndicator from "../indicators/activity-indicator";
import { useResizeObserver } from "@/hooks/resize-observer";
Expand Down Expand Up @@ -27,18 +27,29 @@ export default function CameraImage({
const enabled = config ? config.cameras[camera].enabled : "True";
const [isPortraitImage, setIsPortraitImage] = useState(false);

const [{ width: containerWidth, height: containerHeight }] =
useResizeObserver(containerRef);

const requestHeight = useMemo(() => {
if (!config || containerHeight == 0) {
return 360;
}

return Math.min(
config.cameras[camera].detect.height,
Math.round(containerHeight * 1.1),
);
}, [config, camera, containerHeight]);

useEffect(() => {
if (!config || !imgRef.current) {
return;
}

imgRef.current.src = `${apiHost}api/${name}/latest.jpg${
Copy link
Sponsor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can def see a reduction of image quality on my mobile now. Looks worse. I liked the high quality previews before. Anyway we can have this as a configurable option?

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bandwidth usage was considerable and it had the possibility of causing live to take longer to startup. It is possible adjustments will be made to the quality but I don't see this being configurable

Copy link
Sponsor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The quality looks pretty bad for me and is a big downgrade. I hope that can be addressed

searchParams ? `?${searchParams}` : ""
imgRef.current.src = `${apiHost}api/${name}/latest.jpg?h=${requestHeight}${
searchParams ? `&${searchParams}` : ""
}`;
}, [apiHost, name, imgRef, searchParams, config]);

const [{ width: containerWidth, height: containerHeight }] =
useResizeObserver(containerRef);
}, [apiHost, name, imgRef, searchParams, requestHeight, config]);

return (
<div className={className} ref={containerRef}>
Expand Down
Loading