training_extensions icon indicating copy to clipboard operation
training_extensions copied to clipboard

Ensure video stream correctly scales to window container size

Open andersendsa opened this issue 5 months ago • 4 comments

Summary

Added a window resize event listener in use-container-size to properly track dimensions. The resize observer alone doesn't trigger accurately on initial render when children elements like videos or canvases are styled with relative dimensions (100%).

Closes:#6843

How to test

  1. Start the application backend and frontend.
  2. In the UI, set up an IP camera or video input source.
  3. Select a model, start the pipeline, and start the stream.
  4. Observe the inference on the running source. The stream video should immediately scale correctly to fill the available window area without needing a page refresh (F5).
  5. Resize your browser window. The video feed should react seamlessly and adjust to the new window dimension immediately.

Checklist

  • [x] The PR title and description are clear and descriptive
  • [x] I have manually tested the changes
  • [x] All changes are covered by automated tests
  • [x] All related issues are linked to this PR (if applicable)
  • [ ] Documentation has been updated (if applicable)

andersendsa avatar Jun 20 '26 13:06 andersendsa

@andersendsa instead of changing the zoom which affects everything else, we should target the video stream instead. On stream.tsx you can leverage video's "onResize" method to accomplish this. You can for instance use

const updateSizeFromVideo = (video: HTMLVideoElement) => {
        const { videoWidth, videoHeight } = video;

        if (videoWidth && videoHeight) {
            setVideoSize((prev) =>
                prev.width === videoWidth && prev.height === videoHeight
                    ? prev
                    : { width: videoWidth, height: videoHeight }
            );
        }
    };

and add this to the onResize

jpggvilaca avatar Jun 23 '26 07:06 jpggvilaca

@andersendsa instead of changing the zoom which affects everything else, we should target the video stream instead. On stream.tsx you can leverage video's "onResize" method to accomplish this. You can for instance use

const updateSizeFromVideo = (video: HTMLVideoElement) => {
        const { videoWidth, videoHeight } = video;

        if (videoWidth && videoHeight) {
            setVideoSize((prev) =>
                prev.width === videoWidth && prev.height === videoHeight
                    ? prev
                    : { width: videoWidth, height: videoHeight }
            );
        }
    };

and add this to the onResize

Thank you for the suggestion will work on it and will revert

andersendsa avatar Jun 23 '26 07:06 andersendsa

@andersendsa instead of changing the zoom which affects everything else, we should target the video stream instead. On stream.tsx you can leverage video's "onResize" method to accomplish this. You can for instance use

const updateSizeFromVideo = (video: HTMLVideoElement) => {
        const { videoWidth, videoHeight } = video;

        if (videoWidth && videoHeight) {
            setVideoSize((prev) =>
                prev.width === videoWidth && prev.height === videoHeight
                    ? prev
                    : { width: videoWidth, height: videoHeight }
            );
        }
    };

and add this to the onResize

Hi @jpggvilaca i have implemented the changes the pr is ready for review

andersendsa avatar Jun 23 '26 08:06 andersendsa

Hi @jpggvilaca could you pls let me know if this pr needs any changes or if it is good to merge

andersendsa avatar Jun 26 '26 07:06 andersendsa