Set Video height in HTML5

情到浓时终转凉″ 提交于 2019-12-05 00:40:29

You can't change aspect ratio in <video> tag.

However you can read your video content and write it to <canvas> element.

For example:

<canvas id="canvas" height="768" width="1024"></canvas>

And JS:

function updateVideo( ) {
    var canvas = document.getElementById( 'canvas' );
    var ctx = canvas.getContext( '2d' );
    var myVideo = document.getElementById( 'video' );
    ctx.drawImage( myVideo, 0, 0, 640, 480 );
}
setInterval ( updateVideo, 24 );
Musa

Here is simple CSS trick, you don't need to add any JavaScript or jQuery code. Use object-fit CSS property on video tag.

HTML

<video controls="controls" id="video">
<source src="sintel-trailer.ogv" type='video/ogg; codecs="theora, vorbis"'>
<source src="sintel-trailer.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>

CSS

#video{
  object-fit: initial;
  width: 400px;
  height: 300px;
}

See Fiddle

You can use css to work around.

#video {
   width:1000px;
   height:auto;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!