Cant track size of underlying video #1809
Replies: 4 comments
-
Maybe quite late, but I don't think this is the right way to go at it. Personally I would try making a responsive div with a fixed ratio of e.g. 16:9 around the player and let the video adapt to it. Meaning if it is a 4:3 video the height will be filled and leave you with blank space to the right and left (if centered) and with 0 spacing if it is an actual 16:9 video. Btw. you can enable syntax highlighting for code-blocks, makes it just way easier to read code snippets. |
Beta Was this translation helpful? Give feedback.
-
Did you find any solution for this? I need to do this exact same thing to overlay a drawing canvass over the video and to automatically resize on different screens size. |
Beta Was this translation helpful? Give feedback.
-
@franciscojs12 I can try to follow up with additional details on how I did this. |
Beta Was this translation helpful? Give feedback.
-
It would be still really convenient to at least have the video dimensions! |
Beta Was this translation helpful? Give feedback.
-
Hi.
What I'm trying to do:
I want to create a transparent div that exactly overlays the underlying ReactPlayer video imagery. This overlay div should exactly overlay the video imagery, and should not include any border that comes from the preservation of the aspect ratio.
I am not sure how to do this.
Questions I have that relate to this:
Further Details:
Because ReactPlayer preserves aspect ratio (as it should in my case), the instantiated player might have a border portion (either horizontally or vertically) that is not the actual video imagery.
The code I am currently working with looks like this:
In the following picture the portion in orange is part of the styling used for the ReactPlayer.
You'll notice in the element hierarchy I've clicked on the video that ReactPlayer creates. This is 900px by 400px.
But the actual image is less than 900 pixel wide as seen by the orange border (part of the div that ReactPlayer wraps around the video).
You'll also see in the element hierarchy the outerWrapper (which is blue), and an innerWrapper (which happens to be green and exactly wraps the RP div (whereas I want it to wrap the actual imagery that RP displays).
This becomes even more clear once I further tweak the sizes:
Now we see that the overlay div does exactly track the ReactPlayer div, however I want it t overlay the actual video imagery.
The first method I tried was to track the size of the player.. however I think this was overly complicated, and I dont believe that I was on the right track since I haven't seen that ReactPlayer exposes the X, Y position of the video imagery, nor its width/height.
The second method I tried is close, and has led to the code you see above.
Even More Details Follow (but I'm not sure they add any more clarity to my questions above).
I've kept Method 1 for reference. However Method 2 seems close (except for the red border you will see in the image at the very bottom of Method 2.
Method 1 (Original Attempt was to use use-resize-observer, however this I've given up on)
I've begun to experiment with a mechanism that allows me to use use-resize-observer to track the width and the height of the underlying video. I was then going to figure out how to constrain the upper left hand corner of that video to a known pixel location, then I would be able to create a div that floats properly over the video. With this approach, as long as I can track the exact width and height of the video in pixels then I would be able to create that overlay. There may be a simpler approach.
I am trying to use use-resize-observer to keep track of the size of the underlying video div (the parent div of the video tag highlighted in the image at the bottom of this question). That div is specified to have a width and height of 80% in the following code snippet. I need to specify this as a percentage, however I need access to the actual width and height in pixels.
I am able to track the size of the ReactPlayer container div (ref={playerContainerRef}) as in the following:
However if I try to use the resize observer
const { width=1, height=1} = useResizeObserver({ref: playerRef});
on the ref passed into ReactPlayer, rather than on the playerContainerRef I see the following problem
How can I get access to the actual width and height of the "video" frame?
In the following image I have highlighted the "video" tag that I am trying to get the exact size of.
We see that it is about 519 x 432 in size. You can also see the size of the div that I've referenced as playerContainerRef. As you see its size is tracked as 649 x 540
Method 2 (This was my second attempt at creating a video overlay and led to the code I presented above)
In the following I have an overlay with a red background. It was relatively simple to achieve this. The overlay exactly overlays the ReactPlayer div and video tags. However the red border on the sides is not really part of the underlying video stream. I think its there because ReactPlayer preserves the aspect ratio of the video (which I want).
Is it possible to create an overlay that only overlays the actual content of the video?
The code I have so far is like this:
where
and
Beta Was this translation helpful? Give feedback.
All reactions