Skip to content

Commit

Permalink
add video capture js
Browse files Browse the repository at this point in the history
  • Loading branch information
yashrajbharti committed Apr 27, 2024
1 parent e5a343e commit 9893b66
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/video-capture-and-save.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export let mediaRecorder = null;
let chunks = [];
let startTime = null;
let timerInterval;
const recordingIndicator = document.createElement("div");

export const captureVideo = () => {
Expand Down Expand Up @@ -30,7 +31,11 @@ const recordVideo = async (isMirrored = false, facingModeButton) => {
startTime = Date.now(); // Start time for elapsed time calculation
mediaRecorder.start();
mediaRecorder.ondataavailable = (event) => {
chunks.push(event.data);
const blob = new Blob([event.data], {
type: "video/mp4",
});
chunks.push(blob);
console.log(chunks);
};

// Start recording indicator
Expand All @@ -39,7 +44,7 @@ const recordVideo = async (isMirrored = false, facingModeButton) => {
document.body.appendChild(recordingIndicator);

// Update recording indicator at regular intervals
const timerInterval = setInterval(() => {
timerInterval = setInterval(() => {
const elapsedTime = Date.now() - startTime;
recordingIndicator.textContent = formatTime(elapsedTime);
}, 1000);
Expand Down

0 comments on commit 9893b66

Please sign in to comment.