Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions public/opencv-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ function blurGray(src, dst) {
}

self.onmessage = async (event) => {
// Dedicated worker messages should only come from the creating page.
if (event.origin !== "" && event.origin !== self.location.origin) {
return;
}

const msg = event.data;
const { id, type } = msg;

Expand Down
18 changes: 9 additions & 9 deletions src/webcam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,23 @@ export function countWebmFrames(blob: Blob): Promise<{ frameCount: number; durat
const video = document.createElement("video");
video.preload = "auto";
video.muted = true;

const blobUrl = URL.createObjectURL(blob);
video.src = blobUrl;
// Prefer srcObject over createObjectURL+.src so the blob is not reinterpreted as an HTML URL.
video.srcObject = blob;

let lastPresentedFrames = 0;
let settled = false;

const timeoutId = setTimeout(() => {
if (!settled) {
settled = true;
URL.revokeObjectURL(blobUrl);
video.srcObject = null;
reject(new Error("Timeout counting WebM frames"));
}
}, 60000);

const cleanup = () => {
clearTimeout(timeoutId);
URL.revokeObjectURL(blobUrl);
video.srcObject = null;
};

video.addEventListener("ended", () => {
Expand Down Expand Up @@ -509,7 +508,7 @@ export async function estimateVideoFrameRate(
);

const deviation = Math.abs(empiricalFps - closestCommon);
let confidence: "high" | "medium" | "low" = "medium";
let confidence: "high" | "medium" | "low";

if (deviation < 1) {
confidence = "high";
Expand Down Expand Up @@ -638,11 +637,12 @@ export async function extractVideoFileMetadata(file: File, defaultFps: number):

// Generic video: probe duration via a temporary video element.
return new Promise<VideoFileMetadata>((resolve) => {
const tempUrl = URL.createObjectURL(file);
const tempVideo = document.createElement("video");
tempVideo.preload = "metadata";
tempVideo.src = tempUrl;
const cleanup = () => URL.revokeObjectURL(tempUrl);
tempVideo.srcObject = file;
const cleanup = () => {
tempVideo.srcObject = null;
};
tempVideo.addEventListener(
"loadedmetadata",
() => {
Expand Down