Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make HTML 5 video playback fit to frame instead of maintaining aspect ratio?

Tags:

html

video

I've been experimenting with HTML5 video playback. For example I have this video object embedded on my page:

<video width="480" height="380" class="ecard" tabindex="0">
   <source type="video/ogg; codecs=&quot;theora, vorbis&quot;" src="videos/1156 In your honor we'll be dancing.ogv"></source>
   <source type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;" src="videos/1156 In your honor we'll be dancing.mp4"></source>
</video>

My problem is the video element preserves it's aspect ratio whereas I would prefer to force the playback to fit to frame. Does anyone know a way to do this?

like image 236
Jim Jeffers Avatar asked Mar 03 '10 12:03

Jim Jeffers


3 Answers

There is currently no way of doing this, but with the CCS3 image-fit property it will become possible. No browser supports it yet, though. Then you could use this to make all videos stretch to width/height:

video {
  image-fit: fill;
}

See spec at http://dev.w3.org/csswg/css3-page/#propdef-image-fit

like image 197
foolip Avatar answered Oct 20 '22 04:10

foolip


A little late now, but the object-fit CSS3 property will satisfy this need. http://dev.w3.org/csswg/css3-images/#object-fit It is already implemented in Opera, see http://my.opera.com/desktopteam/blog/2010/08/03/presto-update .

like image 20
Silvia Avatar answered Oct 20 '22 04:10

Silvia


If you want the video to fill the entire frame AND maintain its aspect ratio, use the following:

video
{
  object-fit: cover;
  height: 100%;
  width: 100%;
}
like image 40
Simon Mattes Avatar answered Oct 20 '22 03:10

Simon Mattes