Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
How to Maintain the HTML5 Video Aspect Ratio according to Div Size

I am using react with typescript. In my project, I have JSON data that contains the information of the faces detected on the video. Now I am creating bounding boxes on faces in the video, but I am facing one problem is that the bounding box information is for the video resolution 3840 x 2160, but my div has height is 500px and width is 800px and I am also using object-fill property as fill. Now when I am rendering the bounding boxes on video it displays out from the div.

How to do this so that bounding boxes display an accurate position on the div.

sample JSON data look like this:

[
  { "frame": 2, "x": 2943, "y": 503, "width": 266, "height": 354 }

]

and my code:

<div ref={divRef}>
        <Video videoSource={source} ref={vRef}/>
        <svg id="svg" ref={sRef}>
        }
        </svg>
      </div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maybe I am missing something here, but it should be a simple math problem.

1) Get the height and width of the div that contains the video (500 X 800) . 2) See how many times it is smaller than the origin (3840 X 2160)

small video width / big video width = X ratio
    
small video height / big video height = Y ratio

Multiple X and Y values with these to find the right location at smaller video.

For frame 0, X should be : Old X * X aspect ratio

For frame 0, Y should be : Old Y * Y aspect ratio

That same logic goes for width and height. So you can loop through the JSON object to create a new object with expected values and map it in SVG.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda