当前位置:网站首页>JS realizes video recording - Take cesium as an example
JS realizes video recording - Take cesium as an example
2022-07-27 20:15:00 【giao00000】
JS Video recording - With Cesium For example
List of articles
1. Requirements describe
It is required to be able to Cesium The motion of the three-dimensional earth is recorded as a video .
2. Concrete realization
2.1 Main principle
You can directly call MediaStream Recording API, Video recording . The core sample code is as follows :
var canvas = document.querySelector("canvas");
// Optional frames per second argument.
var stream = canvas.captureStream(25);
var recordedChunks = [];
console.log(stream);
var options = {
mimeType: "video/webm; codecs=vp9" };
mediaRecorder = new MediaRecorder(stream, options);
mediaRecorder.ondataavailable = handleDataAvailable;
mediaRecorder.start();
function handleDataAvailable(event) {
console.log("data-available");
if (event.data.size > 0) {
recordedChunks.push(event.data);
console.log(recordedChunks);
download();
} else {
// ...
}
}
function download() {
var blob = new Blob(recordedChunks, {
type: "video/webm"
});
// Create a pointer to binary data URL
var url = URL.createObjectURL(blob);
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = "test.webm";
a.click();
// Release URL
window.URL.revokeObjectURL(url);
}
// demo: to download after 9sec
setTimeout(event => {
console.log("stopping");
mediaRecorder.stop();
}, 9000);
2.2 Complete example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Include the CesiumJS JavaScript and CSS files -->
<script src="https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Cesium.js"></script>
<link href="https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
<div id="cesiumContainer">
<button onclick="startRecord()"> record video </button>
<button onclick="stopRecord()"> The end of the recording </button>
</div>
<script> // Your access token can be found at: https://cesium.com/ion/tokens. // Replace `your_access_token` with your Cesium ion access token. // Cesium.Ion.defaultAccessToken = 'your_access_token'; // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID. const viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider: Cesium.createWorldTerrain() }); // Fly the camera to San Francisco at the given longitude, latitude, and height. viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400), orientation: {
heading: Cesium.Math.toRadians(0.0), pitch: Cesium.Math.toRadians(-15.0), } }); var mediaRecorder, recordedChunks; setTimeout(() => {
// video recording var canvas = document.querySelector(".cesium-widget>canvas"); // Optional frames per second argument. var stream = canvas.captureStream(25); recordedChunks = []; console.log(stream); var options = {
mimeType: "video/webm; codecs=vp9" }; mediaRecorder = new MediaRecorder(stream, options); mediaRecorder.ondataavailable = handleDataAvailable; }, 2000); function handleDataAvailable(event) {
console.log("data-available"); if (event.data.size > 0) {
recordedChunks.push(event.data); console.log(recordedChunks); download(); } else {
// ... } } function download() {
var blob = new Blob(recordedChunks, {
type: "video/webm" }); var url = URL.createObjectURL(blob); var a = document.createElement("a"); document.body.appendChild(a); a.style = "display: none"; a.href = url; a.download = "test.webm"; a.click(); window.URL.revokeObjectURL(url); } // Start recording function startRecord() {
console.log("starting"); mediaRecorder.start(); } // The end of the recording function stopRecord() {
console.log("stopping"); mediaRecorder.stop(); } </script>
</div>
</body>
</html>
3. Effect of the sample

4. Reference link
边栏推荐
- 京东:按关键字搜索商品 API
- 22年PMP考试【全真敏捷试题】
- LG集团宣布将向湖北捐赠300万元现金、120万个口罩、1万套防护服
- How to run kevinchappell / FormBuilder
- MongoDB 学习笔记: BSON 结构分析
- PMP practice once a day | don't get lost in the exam -7.27 (including agility + multiple choices)
- Huawei connect conference 2022 opens Bangkok trip; Facebook pushes the video revenue sharing function, and the creator can get 20% share
- conda常用命令
- 产品经理:排查下线上哪里冒出个“系统异常”的错误提示
- pytorch lstm+attention
猜你喜欢

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte

Chapter 3 basic operation

Datepicker date selector in viewui compatible solution in ie11 browser

连接池-归还连接详解(上)

Online judge output overrun

ViewUI 中 DatePicker 日期选择器在 IE11 浏览器中兼容解决方案

1.2、基于增量式生成遮挡与对抗抑制的行人再识别(代码理解与实验进度+报告)

聊聊 Redis 是如何进行请求处理

PyQt5快速开发与实战 4.3 QLabel and 4.4 文本框类控件

Compiling ncnn with vs
随机推荐
电容串联与并联以及电容串联与平衡电阻
Detailed introduction to common coordinate system of cesium
C# 后台GC 的前因后果
C background GC cause and effect
JS 数组方法 forEach 和 map 比较
LED高精度体重秤方案规格书
内置函数其它函数
ECU software and hardware architecture
Qtexttospeech class of QT realizes voice broadcast function
transformers-bert
汇顶科技:收购恩智浦VAS业务已完成交割
Chapter 2 Introduction
Use cpolar to build a business website (5)
康佳首批10万颗存储主控芯片售罄,2020年预计销量1亿颗
ViewUI 中 DatePicker 日期选择器在 IE11 浏览器中兼容解决方案
pytorch lstm+attention
办公自动化解决方案——DocuWare Cloud 将应用程序和流程迁移到云端的完整的解决方案
shell
MongoDB 学习笔记: BSON 结构分析
继华为、联发科之后,这家手机芯片厂商宣布向武汉捐款700万