Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept Multiple video Resolutions and Canvas Recording #427

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/ui/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,65 @@ module.exports = function Interface(options) {
$("[rel=popover]").popover()
return true;
});
//Start Handle multiple webcam resolutions
function changeResolution(w, h){
document.getElementById('image').setAttribute("width",w);
document.getElementById('image').setAttribute("height",h);
}
$('#qvga').click(function(e){
changeResolution('100px','100px')
});
$('#vga').click(function(e){
changeResolution('800px','600px')
});
$('#hd').click(function(e){
changeResolution('2400px','1800px')
})
$('#full-hd').click(function(e){
changeResolution('6000px','4000px')
});
//End Handling of Multiple webcam resolutions

//Start Canvas Recording and Download

const canvas = document.getElementById('image');
const ctx = canvas.getContext('2d');
var x = 0;
const stream = canvas.captureStream(); // grab our canvas MediaStream
const rec = new MediaRecorder(stream);

function exportVid(blob) {
const vid = document.createElement('video');
vid.src = URL.createObjectURL(blob);
vid.controls = true;
vid.style.display='none';
document.body.appendChild(vid);
const a = document.createElement('a');
a.style.display = 'none';
a.href = vid.src;
a.download = 'infragramVideo.mp4';
document.body.appendChild(a);
a.click();
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(vid.src);
}, 100);
}
$('#startRecord').click(function(e){
const chunks = [];

rec.ondataavailable = e => chunks.push(e.data);
rec.onstop = e => exportVid(new Blob(chunks, {type: 'video/h264'}));
rec.start();
document.getElementById('startRecord').style.display='none';
document.getElementById('stopRecord').style.display='block';
})
$('#stopRecord').click(function(e){
rec.stop();
document.getElementById('stopRecord').style.display='none';
document.getElementById('startRecord').style.display='block';
document.getElementById('downloadButton').style.display='block';
})

//End Canvas Recording and Download
}