Capturing Video Frame and then Exporting as Bitmap in HTML5

ε祈祈猫儿з 提交于 2019-11-27 20:20:15

问题


I have a web application where I play back video.

I am considering using the HTML5 <video> element and have determined it will allow me to meet all of my requirements except one: allowing the user to take a snapshot of the current video frame and save it as a raster image format (i.e. JPG).

For this requirement I have not found a solution, and any guidance on this matter would be greatly appreciated.

To help answer the question here are more details. I will download the video files from a server via HTTP and then play them back in the browser. This will not be a video stream, but instead a download with playback starting after the file has been received. The video will be in the MP4 format.

The solution only needs to run in IE 9. (Although naturally I would like the solution to be as cross-browser/platform as possible.)


回答1:


Capture the image to a canvas element:

var video  = document.getElementById(videoId);
var canvas = document.createElement('canvas');
canvas.width  = video.videoWidth;
canvas.height = video.videoHeight;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0);

Then use the toDataURL() method to get the image:

canvas.toDataURL('image/jpeg');

Be aware that for all this to work the video has to be from the same origin as the page.




回答2:


but see this Flash example, where the author encodes a webcam frame in Flash and passes it to Javascript. http://code.google.com/p/flashcam



来源:https://stackoverflow.com/questions/5372501/capturing-video-frame-and-then-exporting-as-bitmap-in-html5

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