views:

168

answers:

2

How can I get the first frame of a video file in javascript as an image?

A: 

Javascript is not capable of doing this.

Josh Stodola
not client side atleast.
Pim Jager
Javascript runs on the client side, brainiac.
Josh Stodola
+1  A: 

As mentioned, Javascript is not able to do this.

If you want to create thumbnails for your videos you have to create the thumbnail server side and then simply serve up the image on the client as you would any other image.

My method of choice for accomplishing this is the ffmpeg decoder. It can handle a multitude of file formats and is able to do what you want. So if you have a video named hello.avi, you might do:

ffmpeg -itsoffset -1 -i /path/to/hello.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 200x150 /path/to/hello.jpg

You can run this command (fixing the paths and dimensions...) with whatever server-side language you are using and it would create a thumbnail of the video file.

Paolo Bergantino