Cesium recording canvas video
Using H5 API Mediarecorder and borrow canvas.capturestream to record the screen.
Direct upper code (Vue lower)
recorderCanvas () {
let that = this
let viewer = window.earth
const stream = viewer.canvas.captureStream()
const recorder = new MediaRecorder(stream, { MimeType: 'video/webm' })
that.data = []
recorder.ondataavailable = function (event) {
if (event.data && event.data.size) {
that.data.push(event.data)
}
}
recorder.onstop = () => {
that.url = URL.createObjectURL(new Blob(that.data, { type: 'video/webm' }))
that.startDownload(that.url)
}
recorder.start()
setTimeout(() => {
recorder.stop()
}, 10000)
},
Disadvantages: only canvas can be recorded, and other DOM pages cannot be recorded.
Add a camera to open the video, also using mediarecorder or Mediastreamrecorder, mediastreamrecorder provides more control means, and the corresponding JS files need to be imported.
Mediastreamrecorder GitHub address
Mediarecorder mode
Note that when creating a mediarecorder instance, you should correctly set the value of mimeType. Otherwise, the downloaded video will be black. In addition, the video format chrome seems to only support WEMP format.
Calling mediarecorder. Stop() does not turn off the camera. You need to manually turn off video and audio by stream.gettracks.
makeRecordes () {
if (navigator.mediaDevices) {
console.log('getUserMedia supported.')
var constraints = { audio: true, video: { width: 1280, height: 720 } }
var chunks = []
let that = this
navigator.mediaDevices.getUserMedia(constraints)
.then(function (stream) {
var mediaRecorder = new MediaRecorder(stream, { mimeType: 'video/webm;codecs=vp8,opus' })
mediaRecorder.start()
mediaRecorder.ondataavailable = function (e) {
chunks.push(e.data)
}
setTimeout(() => {
mediaRecorder.stop()
stream.getTracks().forEach(function (track) {
track.stop()
})
mediaRecorder.onstop = () => {
const videoBlob = new Blob(chunks, { 'type': 'video/webm' })
let videoUrl = window.URL.createObjectURL(videoBlob)
that.startDownload(videoUrl)
}
}, 10000)
})
.catch(function (err) {
console.log('The following error occurred: ' + err)
})
}
},
If you need more control, such as pause, and don’t want to implement it yourself, use mediastreamrecorder
Also set the value mimeType correctly, otherwise the recorded video will be black.
makeRecordesByMSR () {
if (navigator.mediaDevices) {
console.log('getUserMedia supported.')
var constraints = { audio: true, video: { width: 1280, height: 720 } }
navigator.mediaDevices.getUserMedia(constraints)
.then(function (stream) {
// eslint-disable-next-line no-undef
var mediaRecorder = new MediaStreamRecorder(stream)
mediaRecorder.stream = stream
mediaRecorder.width = window.screen.width
mediaRecorder.height = window.screen.height
mediaRecorder.mimeType = 'video/webm;codecs=vp8,opus'
mediaRecorder.ondataavailable = function (blob) {
mediaRecorder.save(blob, 'myName.webm')
}
mediaRecorder.start(6000)
setTimeout(() => {
mediaRecorder.stream.stop()
}, 12000)
})
.catch(function (err) {
console.log('The following error occurred: ' + err)
})
}
}
Read More:
- How do I download or save a YouTube video to my computer?
- Raspberry Pi USB drive-free camera error libv4l2: error setting pixformat: Device or resource busy, etc.
- Some index files failed to download. They have been ignored, or old ones used instead
- The computer can’t turn on ERROR: NO BOOT DISK HAS BEEN DETECTED OR THE DISK HAS FAILED
- Ora-02292: integrity constraint (XX) violated – child record found foreign key Association, record cannot be deleted
- Opencv opencvsharpexternal compilation and recording process
- Keil prompts the stlink download program to prompt error: Flash download failed – target DLL has been cancelled
- Solution to the problem that the camera can’t display when ROS running
- Bug: unable to download source code in idea, error cannot download sources sources not found for:XXX
- Recording some pits of VTK + QT
- How to turn off merge request in gitlab
- How to turn your project into a jar package in idea
- VIDEOIO ERROR: V4L: can’t open camera by index 0
- Error in loading online pictures on billboard in cesium tainted canvas may not be loaded
- Google cloud disk: too many users have recently viewed or downloaded this file. Please try to access this file later. (How to Bypass Google Drive Download Limit (Quota Exceeded) Error)
- Linux turn off enable firewall command
- Error record: this.requestWindowFeature ( Window.FEATURE_ NO_ Title) error or no effect
- Video download problem of blob type URL
- Utraiso recording DVD application area failed power calibration area error
- Turn on / off Ubuntu 20.04 graphical interface