Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically using the first frame as poster in HTML5 video?

I'm wondering if there's any straightforward way to achieve this effect, without needing backend code to extract a frame, save it as a jpg and database it somewhere.

An effect whereby the first frame of the video just shows up as the poster when the video loads would be so helpful (it would only work if the browser can play back the video obviously, which might be a little different from how poster traditionally works, but that is not a concern.

like image 926
Damon Avatar asked Sep 06 '11 16:09

Damon


People also ask

How do I show the first frame of a video in HTML?

You can set preload='auto' on the video element to load the first frame of the video automatically.

How do I make a video poster in HTML?

The HTML <video> poster Attribute is used to display the image while video downloading or when user click the play button. If this image not set then it will take the first frame of video as a poster image. Attribute Values: It contains a single value URL which specifies the link of source image.

What is the use of poster attribute of video tag in html5?

The poster attribute specifies an image to be shown while the video is downloading, or until the user hits the play button. If this is not included, the first frame of the video will be used instead.


2 Answers

Did you try the following?

just append time in seconds #t={seconds} to source URL:

  <video controls width="360">     <source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4#t=0.1" type="video/mp4" />   </video>

I have chosen a fraction of second (0.1) to keep number of frames small, because I have the suspect that if you put 1 second, it would "preload" the first 1 second of video (i.e. 24 frames or more ....). Just in case ...

Works fine on Chrome and Firefox on desktop :)
Works not on Android mobile, though :(
I did not test on iOS, iPhone, IE yet ??

Edit May 2021:

I realized that many modern browsers now show automatically a poster of first frame.

Seems like they heard us :-)

like image 62
Jürgen Fink Avatar answered Sep 24 '22 09:09

Jürgen Fink


To make it simple you can just add preload="metadata" to your video tag and the second of the first frame #t=0.5 to your video source:

<video width="400" controls="controls" preload="metadata">    <source src="https://www.w3schools.com/html/mov_bbb.mp4#t=0.5" type="video/mp4">  </video>

Best of luck!

like image 42
coinhive Avatar answered Sep 24 '22 09:09

coinhive