HTML5视频截图
我正在尝试截取电影中预定义时间的视频屏幕截图。所以我尝试使用canvas元素。问题是,当您绘制视频图像时,视频必须正在播放,但我需要图像仍然暂停。所以我尝试了这个:
video.play();
context.drawImage(video,0,0,canvas.width,canvas.height);
video.pause();
但正如你可能想象的那样,视频在画布完成绘制之前暂停,导致没有屏幕截图。那么drawImage有回调函数吗?就我而言,绘制过程大约需要 50 毫秒,但这样做并不安全:
setTimeout(function() { video.pause(); }, 50);
I'm trying to take a screenshot of video with predefined time in the movie. So I tried it with the canvas element. The thing is that the video must be playing when you draw the image of the video, but I need the image to still be paused. So I tried this:
video.play();
context.drawImage(video,0,0,canvas.width,canvas.height);
video.pause();
But as you probably can imagine, the video pauses before the canvas is done drawing, resulting in no screenshot. So is there a callback function for drawImage? In my case, the drawing process takes about 50ms, but it doesn't feel safe to do:
setTimeout(function() { video.pause(); }, 50);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试将视频的播放速率设置为非常低的值(如果可行的话为零?),而不是暂停:
这将有效地为您暂停视频。
您还可以将画布设置为黑色,透明度为 0.99,然后在超时时间内扫描生成的图像以查找非黑色像素:
使用最后一种方法时,视频必须来自与脚本相同的域,并且无法在本地运行由于安全限制而导致的文件。
Rather than pausing you could try setting the video's playbackrate to something very low (or zero if that works?):
This will effectively pause the video for you.
You could also set the canvas to black, tranparency 0.99 and then scan the resulting image in your timeout for a non-black pixel:
When using the last method the video must be from the same domain as the script, and will not work on local files because of security constraints.
我不确定这就是您想要的,但是您是否尝试过使用 MWSnap 手动截取屏幕截图?当您截屏时它会冻结屏幕,所以我想它可能对您有用。
I'm not sure this is what you're after, but have you tried taking the screenshot manually using MWSnap? It freezes the screen while you are taking the screenshot so I guess it might work for you.
嗯...似乎实际上可以从暂停的视频中绘制图像。只要从一开始就保持间隔即可。
Hm...it seems like it actually is possible to draw an image from a paused video. Just keep the interval going from the beginning.