admin管理员组文章数量:1333201
I have an animation happening in a div element. I want to record the div element in a given frame rate and resolution and export it as a file. How can do it in JS. I already searched quite a bit but all JS video recording samples I found are about WebRTC. But I do not want to record a webrtc stream. I just want to record a div element in 1280x720 sizes with 60fps.
I have an animation happening in a div element. I want to record the div element in a given frame rate and resolution and export it as a file. How can do it in JS. I already searched quite a bit but all JS video recording samples I found are about WebRTC. But I do not want to record a webrtc stream. I just want to record a div element in 1280x720 sizes with 60fps.
Share Improve this question asked Oct 19, 2019 at 20:50 chickenschickens 22.4k7 gold badges61 silver badges57 bronze badges2 Answers
Reset to default 6AFAIK there are no ways of recording real time video from regular div elements. You can however fairly easily record media elements, such as canvas
, video
and audio
elements. If you want to record an arbitrary animation, your best bet is probably to draw the animation to a canvas element and record it from there.
The approach looks like this:
Create a canvas(/video/audio)-element, draw your animations in realtime to the canvas
Use the method
HTMLCanvasElement.captureStream(framerate)
to initiate capturing the stream and getting the handler to the stream instance (see https://developer.mozilla/en-US/docs/Web/API/HTMLCanvasElement/captureStream)Use the MediaStream Recording API to start recording on the stream instance (see https://developer.mozilla/en-US/docs/Web/API/MediaStream_Recording_API)
When finished recording, you can export the result to a media-download link, upload the data blob to a server, etc.
You can use timecut JS lib to record. It uses puppeteer to take high quality screenshots and create a video of it. It can also record a specific div element and very high frame rate.
https://github./tungs/timecut
本文标签: javascriptHow can I video record a div in JSStack Overflow
版权声明:本文标题:javascript - How can I video record a div in JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281024a2446082.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论