Ghongha007 commited on
Commit
5dba712
·
verified ·
1 Parent(s): e9b0d10

video-keyframes 3af4fc5 from GitHub

Browse files
Files changed (8) hide show
  1. .gitattributes +1 -0
  2. LICENSE +21 -0
  3. README.md +21 -5
  4. app.js +197 -0
  5. core.js +104 -0
  6. examples/expo-sample.mp4 +3 -0
  7. index.html +90 -17
  8. style.css +72 -26
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ examples/expo-sample.mp4 filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OSINT JOURNO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,10 +1,26 @@
1
  ---
2
- title: Video Keyframes
3
- emoji: 📈
4
- colorFrom: gray
5
- colorTo: green
6
  sdk: static
 
7
  pinned: false
 
 
 
 
 
 
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
1
  ---
2
+ title: video-keyframes
3
+ emoji: 🎞️
4
+ colorFrom: purple
5
+ colorTo: gray
6
  sdk: static
7
+ app_file: index.html
8
  pinned: false
9
+ license: mit
10
+ short_description: Sharp keyframes from each scene, for reverse image search
11
+ tags:
12
+ - osint
13
+ - verification
14
+ - video
15
+ - reverse-image-search
16
+ - journalism
17
  ---
18
 
19
+ # video-keyframes
20
+
21
+ Drop in a video and get the sharpest frame from each scene, with its timestamp, ready for reverse image search. Or take
22
+ a frame every few seconds, or grab frames by hand. Download them as PNGs or one ZIP, or copy one to paste into a search
23
+ engine.
24
+
25
+ The video is read by your browser and not uploaded. Code: [github.com/Ghongha007/video-keyframes](https://github.com/Ghongha007/video-keyframes) (MIT).
26
+ Made by [OSINT JOURNO](https://huggingface.co/OSINT-JOURNO).
app.js ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // video-keyframes page. Plain script (no modules, no fetch of our own files except the optional sample),
2
+ // so it works offline and inside sandboxed frames. Uses KF from core.js.
3
+ (function () {
4
+ "use strict";
5
+ const $ = (id) => document.getElementById(id);
6
+ const video = $("video"), SMALL_W = 64, SMALL_H = 36, SHARP_W = 192, SHARP_H = 108;
7
+ const small = document.createElement("canvas"), sharpC = document.createElement("canvas");
8
+ small.width = SMALL_W; small.height = SMALL_H; sharpC.width = SHARP_W; sharpC.height = SHARP_H;
9
+ const sctx = small.getContext("2d", { willReadFrequently: true }), hctx = sharpC.getContext("2d", { willReadFrequently: true });
10
+ let fileName = "video", frames = [], stopFlag = false, busy = false, objectUrl = null, bigUrl = null;
11
+
12
+ function status(t, kind = "") { $("status").textContent = t; $("status").className = "status " + kind; }
13
+
14
+ function load(src, name) {
15
+ if (objectUrl) URL.revokeObjectURL(objectUrl);
16
+ objectUrl = src.startsWith("blob:") ? src : null;
17
+ fileName = (name || "video").replace(/\.[^.]+$/, "").replace(/[^\w.-]+/g, "_").slice(0, 60) || "video";
18
+ $("go").disabled = true; $("grab").disabled = true;
19
+ status("Opening the video…");
20
+ // a web address (the sample) must be loaded with CORS, or the canvas would be "tainted" in sandboxed frames
21
+ if (src.startsWith("blob:")) video.removeAttribute("crossorigin"); else video.crossOrigin = "anonymous";
22
+ video.src = src;
23
+ }
24
+ video.addEventListener("loadedmetadata", () => {
25
+ $("info").textContent = `${video.videoWidth}×${video.videoHeight}, ${KF.fmtTime(video.duration)}`;
26
+ $("go").disabled = false; $("grab").disabled = false;
27
+ status("Ready. Choose how to find frames, then press Find keyframes.", "ok");
28
+ });
29
+ video.addEventListener("error", () => status("Your browser can't play this file. Convert it to MP4 (H.264) and try again.", "err"));
30
+
31
+ // Seek, then wait until the new frame is actually ready to draw: "seeked" can fire before it is,
32
+ // so where the browser supports it we also wait for requestVideoFrameCallback (with a short fallback).
33
+ function seek(t) {
34
+ return new Promise((res) => {
35
+ let settled = false;
36
+ const finish = () => { if (!settled) { settled = true; res(); } };
37
+ const onSeeked = () => {
38
+ video.removeEventListener("seeked", onSeeked);
39
+ if (video.requestVideoFrameCallback) { video.requestVideoFrameCallback(() => finish()); setTimeout(finish, 250); }
40
+ else setTimeout(finish, 30);
41
+ };
42
+ video.addEventListener("seeked", onSeeked);
43
+ setTimeout(() => { video.removeEventListener("seeked", onSeeked); finish(); }, 3000); // never hang on a bad seek
44
+ video.currentTime = Math.min(t, Math.max(0, video.duration - 0.001));
45
+ });
46
+ }
47
+
48
+ function measure() {
49
+ sctx.drawImage(video, 0, 0, SMALL_W, SMALL_H);
50
+ hctx.drawImage(video, 0, 0, SHARP_W, SHARP_H);
51
+ const g = KF.gray(sctx.getImageData(0, 0, SMALL_W, SMALL_H).data);
52
+ const h = KF.gray(hctx.getImageData(0, 0, SHARP_W, SHARP_H).data);
53
+ return { g, sharp: KF.sharpness(h, SHARP_W, SHARP_H), bright: KF.brightness(g) };
54
+ }
55
+
56
+ // Full-resolution frame at the current position, kept as a compressed PNG Blob (a 1080p canvas would hold ~8 MB).
57
+ const MAX_FRAMES = 200;
58
+ async function capture(t, how) {
59
+ const c = document.createElement("canvas");
60
+ c.width = video.videoWidth; c.height = video.videoHeight;
61
+ c.getContext("2d").drawImage(video, 0, 0);
62
+ const th = document.createElement("canvas"), tw = 320;
63
+ th.width = tw; th.height = Math.round(tw * c.height / c.width);
64
+ th.getContext("2d").drawImage(c, 0, 0, th.width, th.height);
65
+ const blob = await new Promise((r) => c.toBlob(r, "image/png"));
66
+ c.width = c.height = 0; // let the full-size canvas go
67
+ return { t, how, blob, thumb: th.toDataURL("image/jpeg", 0.85) };
68
+ }
69
+
70
+ async function run() {
71
+ if (busy) return; busy = true; stopFlag = false;
72
+ $("go").disabled = true; $("stop").hidden = false; $("prog").hidden = false; video.pause();
73
+ try {
74
+ const mode = document.querySelector("input[name=mode]:checked").value;
75
+ const found = []; let capped = false, stoppedEarly = false;
76
+ if (mode === "every") {
77
+ const step = Math.max(0.5, +$("every").value || 5), times = KF.sampleTimes(video.duration, step, 2000);
78
+ for (let i = 0; i < times.length && !stopFlag; i++) {
79
+ if (frames.length + found.length >= MAX_FRAMES) { capped = true; break; }
80
+ await seek(times[i]); const m = measure(); found.push(Object.assign(await capture(times[i], `every ${step} s`), { g: m.g }));
81
+ $("prog").value = (i + 1) / times.length; status(`Capturing ${i + 1} of ${times.length}…`);
82
+ }
83
+ } else {
84
+ const times = KF.sampleTimes(video.duration, 0.25, 1500), samples = [];
85
+ let prev = null;
86
+ for (let i = 0; i < times.length && !stopFlag; i++) {
87
+ await seek(times[i]);
88
+ const m = measure();
89
+ samples.push({ t: times[i], diff: prev ? KF.frameDiff(prev, m.g) : 1, sharp: m.sharp, bright: m.bright });
90
+ prev = m.g;
91
+ if (i % 4 === 0) { $("prog").value = (i + 1) / times.length * 0.9; status(`Scanning ${KF.fmtTime(times[i])} of ${KF.fmtTime(video.duration)}…`); }
92
+ }
93
+ window.__kfSamples = samples; // for debugging and tests
94
+ stoppedEarly = stopFlag; stopFlag = false; // Stop ends the scan; the scenes found so far are still captured
95
+ if (stale(samples)) staleHelp();
96
+ const step = times.length > 1 ? times[1] - times[0] : 0.25;
97
+ const picks = KF.pickScenes(samples, { threshold: KF.thresholdFor(+$("sens").value), minGap: Math.max(1, step * 2), window: 3 });
98
+ for (let k = 0; k < picks.length && !stopFlag; k++) {
99
+ if (frames.length + found.length >= MAX_FRAMES) { capped = true; break; }
100
+ const t = samples[picks[k]].t;
101
+ await seek(t); found.push(await capture(t, "scene change"));
102
+ $("prog").value = 0.9 + 0.1 * (k + 1) / picks.length;
103
+ }
104
+ }
105
+ const looksStale = mode === "every" ? found.length > 8 && found.slice(1).every((f, i) => KF.frameDiff(f.g, found[i].g) === 0)
106
+ : stale(window.__kfSamples || []);
107
+ frames = frames.concat(found).sort((a, b) => a.t - b.t);
108
+ render();
109
+ if (looksStale) staleHelp();
110
+ else status((stopFlag || stoppedEarly ? `Stopped early. ${found.length} frames kept.` : `Done: ${found.length} frames. The video was read in this browser and not uploaded.`) +
111
+ (capped ? ` The limit is ${MAX_FRAMES} frames at a time: download or clear some, then continue.` : ""), "ok");
112
+ } catch (e) { status("Something went wrong: " + e.message, "err"); }
113
+ finally { busy = false; $("go").disabled = false; $("stop").hidden = true; $("prog").hidden = true; }
114
+ }
115
+
116
+ // Every sample showed exactly the same picture. Either the video really is one still image, or the browser isn't
117
+ // handing this page new frames (this can happen when it is shown inside another page). Say so, and offer a fix.
118
+ function stale(samples) {
119
+ return samples.length > 8 && video.duration > 3 && samples.slice(1).every((x) => x.diff === 0);
120
+ }
121
+ function staleHelp() {
122
+ const own = location.href.split("?")[0];
123
+ $("info").innerHTML = "";
124
+ status("Every sample showed exactly the same picture. If the video does change, your browser may not be handing this page new frames (this can happen when the tool is shown inside another page): open it in its own tab and try again.", "err");
125
+ const a = document.createElement("a"); a.href = own; a.target = "_blank"; a.rel = "noopener"; a.textContent = "Open video-keyframes in its own tab";
126
+ $("info").appendChild(a);
127
+ }
128
+
129
+ const ENGINES = [["Google Lens", "https://lens.google.com/"], ["Bing", "https://www.bing.com/images"],
130
+ ["Yandex", "https://yandex.com/images/"], ["TinEye", "https://tineye.com/"]];
131
+
132
+ function render() {
133
+ $("out").hidden = frames.length === 0;
134
+ $("count").textContent = `${frames.length} keyframe${frames.length === 1 ? "" : "s"}`;
135
+ $("frames").innerHTML = "";
136
+ frames.forEach((f, i) => {
137
+ const fig = document.createElement("figure");
138
+ fig.innerHTML = `<button class="thumb" type="button" aria-label="View frame at ${KF.fmtTime(f.t)} full size"><img alt="Frame at ${KF.fmtTime(f.t)}" src="${f.thumb}"></button>
139
+ <figcaption><span class="mono">${KF.fmtTime(f.t)}</span> <span class="how">${f.how}</span></figcaption>
140
+ <div class="row small"><button type="button" data-a="png" aria-label="Download the frame at ${KF.fmtTime(f.t)} as PNG">PNG</button><button type="button" data-a="copy" aria-label="Copy the frame at ${KF.fmtTime(f.t)}">Copy</button>
141
+ <button type="button" data-a="seek" title="Show this moment in the video" aria-label="Show ${KF.fmtTime(f.t)} in the video">Show</button><button type="button" data-a="del" aria-label="Remove the frame at ${KF.fmtTime(f.t)}">✕</button></div>
142
+ <div class="engines">Search: ${ENGINES.map(([n, u]) => `<a href="${u}" target="_blank" rel="noopener">${n}</a>`).join(" · ")}</div>`;
143
+ fig.querySelector(".thumb").onclick = () => {
144
+ if (bigUrl) URL.revokeObjectURL(bigUrl); bigUrl = URL.createObjectURL(f.blob);
145
+ $("big").src = bigUrl; $("big").alt = `Frame at ${KF.fmtTime(f.t)}`; $("viewer").showModal(); };
146
+ fig.querySelector("[data-a=png]").onclick = () => save(f.blob, `${fileName}_${KF.fmtTime(f.t).replace(/:/g, "-")}.png`);
147
+ fig.querySelector("[data-a=copy]").onclick = async () => {
148
+ try { await navigator.clipboard.write([new ClipboardItem({ "image/png": f.blob })]); status(`Frame at ${KF.fmtTime(f.t)} copied. Paste it into the search engine.`, "ok"); }
149
+ catch (_) { status("This browser didn't allow copying images. Use PNG to download the frame instead.", "err"); }
150
+ };
151
+ fig.querySelector("[data-a=seek]").onclick = () => { video.currentTime = f.t; video.scrollIntoView({ behavior: "smooth", block: "center" }); };
152
+ fig.querySelector("[data-a=del]").onclick = () => { frames.splice(i, 1); render(); };
153
+ $("frames").appendChild(fig);
154
+ });
155
+ }
156
+
157
+ function save(blob, name) {
158
+ const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = name;
159
+ document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(a.href), 60000);
160
+ }
161
+
162
+ async function zipAll() {
163
+ status("Preparing the ZIP…");
164
+ const files = [], lines = ["file,time,found_by"], used = new Set();
165
+ for (const f of frames) {
166
+ let name = `${fileName}_${KF.fmtTime(f.t).replace(/:/g, "-")}.png`;
167
+ for (let n = 2; used.has(name); n++) name = `${fileName}_${KF.fmtTime(f.t).replace(/:/g, "-")}_${n}.png`;
168
+ used.add(name);
169
+ files.push({ name, data: new Uint8Array(await f.blob.arrayBuffer()) }); lines.push(`${name},${KF.fmtTime(f.t)},${f.how}`);
170
+ }
171
+ files.push({ name: "frames.csv", data: new TextEncoder().encode(lines.join("\n") + "\n") });
172
+ save(new Blob([KF.zip(files)], { type: "application/zip" }), `${fileName}_keyframes.zip`);
173
+ status(`ZIP of ${frames.length} frames saved.`, "ok");
174
+ }
175
+
176
+ $("file").addEventListener("change", (e) => { const f = e.target.files[0]; if (f) load(URL.createObjectURL(f), f.name); });
177
+ const drop = $("drop");
178
+ ["dragenter", "dragover"].forEach((t) => drop.addEventListener(t, (e) => { e.preventDefault(); drop.classList.add("over"); }));
179
+ ["dragleave", "drop"].forEach((t) => drop.addEventListener(t, (e) => { e.preventDefault(); drop.classList.remove("over"); }));
180
+ drop.addEventListener("drop", (e) => { const f = e.dataTransfer.files[0]; if (f) load(URL.createObjectURL(f), f.name); });
181
+ $("sample").onclick = () => load("examples/expo-sample.mp4", "expo-sample.mp4");
182
+ $("sens").oninput = () => { $("sensOut").textContent = $("sens").value; };
183
+ $("go").onclick = run;
184
+ $("stop").onclick = () => { stopFlag = true; };
185
+ $("grab").onclick = async () => {
186
+ if (video.readyState < 2) return;
187
+ if (frames.length >= MAX_FRAMES) { status(`The limit is ${MAX_FRAMES} frames at a time: download or clear some first.`, "err"); return; }
188
+ video.pause(); frames.push(await capture(video.currentTime, "by hand")); frames.sort((a, b) => a.t - b.t); render(); };
189
+ $("zip").onclick = zipAll;
190
+ $("clear").onclick = () => { frames = []; render(); };
191
+
192
+ // ?demo opens the sample and finds its keyframes straight away (a one-click demo link)
193
+ if (new URLSearchParams(location.search).has("demo")) {
194
+ video.addEventListener("loadedmetadata", () => setTimeout(run, 50), { once: true });
195
+ load("examples/expo-sample.mp4", "expo-sample.mp4");
196
+ }
197
+ })();
core.js ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // video-keyframes core: pure functions, no browser APIs. A classic script (window.KF) that Node can also require().
2
+ (function (root) {
3
+ "use strict";
4
+
5
+ // Luminance (Rec. 601) of RGBA pixel data, as a Float32Array of width*height values 0-255.
6
+ function gray(rgba) {
7
+ const n = rgba.length / 4, g = new Float32Array(n);
8
+ for (let i = 0, j = 0; i < n; i++, j += 4) g[i] = 0.299 * rgba[j] + 0.587 * rgba[j + 1] + 0.114 * rgba[j + 2];
9
+ return g;
10
+ }
11
+
12
+ // How different two small grey thumbnails are: mean absolute difference, 0 (same) to 1.
13
+ function frameDiff(a, b) {
14
+ if (!a || !b || a.length !== b.length) return 1;
15
+ let s = 0;
16
+ for (let i = 0; i < a.length; i++) s += Math.abs(a[i] - b[i]);
17
+ return s / a.length / 255;
18
+ }
19
+
20
+ // Sharpness: variance of the Laplacian (a common focus measure). Higher is sharper; blur and motion lower it.
21
+ function sharpness(g, w, h) {
22
+ let n = 0, mean = 0, m2 = 0;
23
+ for (let y = 1; y < h - 1; y++)
24
+ for (let x = 1; x < w - 1; x++) {
25
+ const i = y * w + x;
26
+ const v = 4 * g[i] - g[i - 1] - g[i + 1] - g[i - w] - g[i + w];
27
+ n++; const d = v - mean; mean += d / n; m2 += d * (v - mean);
28
+ }
29
+ return n > 1 ? m2 / (n - 1) : 0;
30
+ }
31
+
32
+ // Mean brightness 0-255: lets us skip black or white transition frames.
33
+ function brightness(g) { let s = 0; for (let i = 0; i < g.length; i++) s += g[i]; return g.length ? s / g.length : 0; }
34
+
35
+ // Sensitivity 1 (only hard cuts) .. 10 (small changes) -> difference threshold.
36
+ function thresholdFor(sensitivity) {
37
+ const s = Math.min(10, Math.max(1, sensitivity));
38
+ return 0.25 * Math.pow(0.03 / 0.25, (s - 1) / 9); // 0.25 at 1, about 0.10 at 5, 0.03 at 10 (log scale)
39
+ }
40
+
41
+ // Pick keyframes from samples [{t, diff, sharp, bright}] taken in time order.
42
+ // A new shot starts where diff (to the previous sample) passes the threshold, at least minGap seconds after the last one.
43
+ // From each shot's first `window` samples, keep the sharpest one that is not almost black or white.
44
+ function pickScenes(samples, opts) {
45
+ const o = Object.assign({ threshold: 0.12, minGap: 1, window: 3 }, opts || {});
46
+ const starts = [];
47
+ samples.forEach((s, i) => {
48
+ if (i === 0 || (s.diff >= o.threshold && s.t - samples[starts[starts.length - 1]].t >= o.minGap)) starts.push(i);
49
+ });
50
+ return starts.map((st, k) => {
51
+ const end = Math.min(k + 1 < starts.length ? starts[k + 1] : samples.length, st + o.window);
52
+ let best = st, bestScore = -1;
53
+ for (let i = st; i < end; i++) {
54
+ const s = samples[i], usable = s.bright > 12 && s.bright < 245;
55
+ const score = (usable ? 1 : 0.001) * s.sharp;
56
+ if (score > bestScore) { bestScore = score; best = i; }
57
+ }
58
+ return best;
59
+ });
60
+ }
61
+
62
+ // Sample times: every `step` seconds from 0 to duration, at most maxSamples (the step grows for long videos).
63
+ function sampleTimes(duration, step, maxSamples) {
64
+ if (!(duration > 0)) return [];
65
+ const st = Math.max(step, duration / maxSamples), out = [];
66
+ for (let t = 0; t < duration - 0.05; t += st) out.push(Math.round(t * 1000) / 1000);
67
+ return out;
68
+ }
69
+
70
+ // 00:01:23.450
71
+ function fmtTime(t) {
72
+ const ms = Math.round(t * 1000), h = Math.floor(ms / 3600000), m = Math.floor(ms / 60000) % 60, s = Math.floor(ms / 1000) % 60;
73
+ const p = (x, n = 2) => String(x).padStart(n, "0");
74
+ return `${p(h)}:${p(m)}:${p(s)}.${p(ms % 1000, 3)}`;
75
+ }
76
+
77
+ // ---- a store-only ZIP writer (no compression; PNG/JPEG are already compressed)
78
+ const CRC = (() => { const t = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xEDB88320 ^ (c >>> 1) : c >>> 1; t[n] = c >>> 0; } return t; })();
79
+ function crc32(u8) { let c = 0xFFFFFFFF; for (let i = 0; i < u8.length; i++) c = CRC[(c ^ u8[i]) & 255] ^ (c >>> 8); return (c ^ 0xFFFFFFFF) >>> 0; }
80
+
81
+ function zip(files) { // files: [{name, data: Uint8Array}] -> Uint8Array
82
+ const enc = new TextEncoder(), parts = [], central = [];
83
+ let offset = 0;
84
+ const u16 = (v) => [v & 255, (v >>> 8) & 255], u32 = (v) => [v & 255, (v >>> 8) & 255, (v >>> 16) & 255, (v >>> 24) & 255];
85
+ for (const f of files) {
86
+ const name = enc.encode(f.name), crc = crc32(f.data), size = f.data.length;
87
+ const local = new Uint8Array([...u32(0x04034b50), ...u16(20), ...u16(0x0800), ...u16(0), ...u16(0), ...u16(0x21),
88
+ ...u32(crc), ...u32(size), ...u32(size), ...u16(name.length), ...u16(0)]);
89
+ parts.push(local, name, f.data);
90
+ central.push(new Uint8Array([...u32(0x02014b50), ...u16(20), ...u16(20), ...u16(0x0800), ...u16(0), ...u16(0), ...u16(0x21),
91
+ ...u32(crc), ...u32(size), ...u32(size), ...u16(name.length), ...u16(0), ...u16(0), ...u16(0), ...u16(0), ...u32(0), ...u32(offset)]), name);
92
+ offset += local.length + name.length + size;
93
+ }
94
+ const cdSize = central.reduce((s, p) => s + p.length, 0);
95
+ const end = new Uint8Array([...u32(0x06054b50), ...u16(0), ...u16(0), ...u16(files.length), ...u16(files.length), ...u32(cdSize), ...u32(offset), ...u16(0)]);
96
+ const all = [...parts, ...central, end], out = new Uint8Array(all.reduce((s, p) => s + p.length, 0));
97
+ let p = 0; for (const a of all) { out.set(a, p); p += a.length; }
98
+ return out;
99
+ }
100
+
101
+ const KF = { gray, frameDiff, sharpness, brightness, thresholdFor, pickScenes, sampleTimes, fmtTime, crc32, zip };
102
+ root.KF = KF;
103
+ if (typeof module !== "undefined" && module.exports) module.exports = KF;
104
+ })(typeof window !== "undefined" ? window : globalThis);
examples/expo-sample.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8af69689efb881387694ea34d4db285ff7efe53ff896dde4c3580a02ab1c9e7
3
+ size 867926
index.html CHANGED
@@ -1,19 +1,92 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
  <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>video-keyframes: sharp frames for reverse image search</title>
7
+ <meta name="description" content="Pull the sharpest frame from each scene of a video, with timestamps, ready for reverse image search. Runs in your browser; the video is not uploaded.">
8
+ <link rel="stylesheet" href="style.css">
9
+ </head>
10
+ <body>
11
+ <main>
12
+ <header>
13
+ <p class="eyebrow">OSINT JOURNO · verification tool</p>
14
+ <h1>video-keyframes</h1>
15
+ <p class="lede">Drop in a video and get the <b>sharpest frame from each scene</b>, with its timestamp, ready for
16
+ reverse image search. Earlier copies of a clip often turn up when you search its key frames, which can show that
17
+ footage is older than claimed or comes from somewhere else.</p>
18
+ <p class="private"><b>Your video stays on your computer.</b> It is read by your browser's own video player in this
19
+ tab and not uploaded anywhere. Only if you choose to search a frame does that frame go to the search engine you
20
+ pick.</p>
21
+ </header>
22
+
23
+ <section class="grid">
24
+ <div class="panel">
25
+ <label class="drop" id="drop">
26
+ <input type="file" id="file" accept="video/*">
27
+ <span class="drop-title">Choose a video</span>
28
+ <span class="drop-sub">or drop it here · any format your browser can play (MP4/H.264 and WebM almost everywhere)</span>
29
+ </label>
30
+ <p class="note">No video to hand? <button type="button" id="sample">Use the sample</button> (a short slideshow of
31
+ OSINT Expo screenshots).</p>
32
+
33
+ <fieldset>
34
+ <legend>Find frames</legend>
35
+ <label><input type="radio" name="mode" value="scenes" checked> At scene changes</label>
36
+ <label class="range">Sensitivity <input type="range" id="sens" min="1" max="10" value="5"> <output id="sensOut">5</output></label>
37
+ <label><input type="radio" name="mode" value="every"> Every <input type="number" id="every" min="0.5" max="600" step="0.5" value="5"> seconds</label>
38
+ </fieldset>
39
+ <div class="row">
40
+ <button class="primary" type="button" id="go" disabled>Find keyframes</button>
41
+ <button type="button" id="stop" hidden>Stop</button>
42
+ </div>
43
+ <progress id="prog" max="1" value="0" hidden></progress>
44
+ <p id="status" class="status" role="status">Choose a video to start.</p>
45
+ <p id="info" class="note"></p>
46
+ </div>
47
+ <div class="panel">
48
+ <video id="video" controls muted playsinline preload="auto"></video>
49
+ <p class="note">Tip: pause on any moment and press <b>Grab this frame</b> to add it by hand.</p>
50
+ <div class="row"><button type="button" id="grab" disabled>Grab this frame</button></div>
51
+ </div>
52
+ </section>
53
+
54
+ <section id="out" hidden>
55
+ <div class="row between">
56
+ <h2 id="count">Keyframes</h2>
57
+ <div class="row">
58
+ <button type="button" id="zip">Download all (ZIP of PNGs)</button>
59
+ <button type="button" id="clear">Clear</button>
60
+ </div>
61
+ </div>
62
+ <p class="note">Click a frame to view it at full size. <b>Copy</b> puts the full-resolution frame on your clipboard,
63
+ to paste into a search engine; the search links open the engine's own upload page, and uploading there sends the
64
+ frame to that company.</p>
65
+ <div id="frames" class="frames"></div>
66
+ </section>
67
+
68
+ <section class="panel about">
69
+ <h2>How it works, and its limits</h2>
70
+ <ul>
71
+ <li>The tool samples the video every fraction of a second at low resolution and measures how much each sample
72
+ differs from the one before. A large jump marks a new scene. From the first few samples of each scene it keeps
73
+ the sharpest (the highest variance of the Laplacian, a standard focus measure), avoiding almost black or white
74
+ frames where possible, then captures that moment at full resolution. Up to 200 frames are kept at a time.</li>
75
+ <li>Timestamps are the time in the file, accurate to the sampling step. Slow fades, camera pans and dark scenes
76
+ can be missed or over-counted: adjust the sensitivity, use "every N seconds", or grab frames by hand.</li>
77
+ <li>The browser can only open formats it can play. If a file won't load, convert it to MP4 (H.264) first.</li>
78
+ <li>A match in a reverse image search is a lead, not proof: check the earliest version and its source. To see
79
+ what a video file says about itself, try <a href="https://huggingface.co/spaces/Ghongha007/aitrace">aitrace</a>.</li>
80
+ </ul>
81
+ </section>
82
+
83
+ <footer>
84
+ Open source: <a href="https://github.com/Ghongha007/video-keyframes">github.com/Ghongha007/video-keyframes</a> (MIT).
85
+ Made by <a href="https://huggingface.co/OSINT-JOURNO">OSINT JOURNO</a>.
86
+ </footer>
87
+ </main>
88
+ <dialog id="viewer"><img id="big" alt=""><form method="dialog"><button>Close</button></form></dialog>
89
+ <script src="core.js"></script>
90
+ <script src="app.js"></script>
91
+ </body>
92
  </html>
style.css CHANGED
@@ -1,28 +1,74 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
  }
5
-
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
- }
10
-
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
- }
17
-
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
- }
25
-
26
- .card p:last-child {
27
- margin-bottom: 0;
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :root {
2
+ --bg: #f6f7f9; --panel: #ffffff; --ink: #1c2024; --muted: #5b6470; --line: #dde1e6; --accent: #0f766e;
3
+ --red: #b4232c; --amber: #a35f00; --green: #1f7a4d; --blue: #2f6f8f; --grey: #5b6470;
4
  }
5
+ @media (prefers-color-scheme: dark) {
6
+ :root { --bg: #0d1117; --panel: #151b23; --ink: #e6edf3; --muted: #9aa5b1; --line: #2a323c; --accent: #2dd4bf;
7
+ --red: #f87171; --amber: #fbbf24; --green: #4ade80; --blue: #7cc4e8; --grey: #9aa5b1; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  }
9
+ * { box-sizing: border-box; }
10
+ body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; }
11
+ main { max-width: 1100px; margin: 0 auto; padding: 28px 16px 40px; }
12
+ h1 { font-size: 2.2rem; margin: 2px 0 10px; letter-spacing: -.01em; }
13
+ h3 { margin: 18px 0 8px; font-size: 1.05rem; }
14
+ a { color: var(--accent); }
15
+ .eyebrow { margin: 0; font: 600 .78rem/1 ui-monospace, "SFMono-Regular", Menlo, monospace; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
16
+ .lede { font-size: 1.05rem; }
17
+ .private { border-left: 4px solid var(--accent); padding: 8px 14px; background: var(--panel); border-radius: 6px; }
18
+ .grid { display: grid; grid-template-columns: 2fr 3fr; gap: 18px; margin-top: 18px; }
19
+ @media (max-width: 760px) { .grid { grid-template-columns: 1fr; } }
20
+ .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
21
+ .drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 150px; padding: 16px;
22
+ border: 2px dashed var(--line); border-radius: 10px; text-align: center; cursor: pointer; }
23
+ .drop:hover, .drop.over { border-color: var(--accent); }
24
+ .drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
25
+ .drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
26
+ .drop-title { font-weight: 600; color: var(--accent); }
27
+ .drop-sub, .note, .meta, .where, .caveat, .always, .placeholder, footer { color: var(--muted); font-size: .92rem; }
28
+ .samples { display: flex; flex-wrap: wrap; gap: 8px; }
29
+ button { font: inherit; font-size: .9rem; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
30
+ button:hover { border-color: var(--accent); }
31
+ .status { font-size: .9rem; margin: 14px 0 0; color: var(--muted); }
32
+ .status.ok { color: var(--green); } .status.err { color: var(--red); }
33
+ .verdict { border-left: 6px solid var(--grey); padding: 10px 16px; border-radius: 6px; background: var(--bg); }
34
+ .verdict p { margin: 6px 0; }
35
+ .v-title { font-size: 1.3rem; font-weight: 700; letter-spacing: .02em; color: var(--grey); }
36
+ .tone-red { border-color: var(--red); } .tone-red .v-title { color: var(--red); }
37
+ .tone-amber { border-color: var(--amber); } .tone-amber .v-title { color: var(--amber); }
38
+ .tone-green { border-color: var(--green); } .tone-green .v-title { color: var(--green); }
39
+ .tone-blue { border-color: var(--blue); } .tone-blue .v-title { color: var(--blue); }
40
+ .findings { list-style: none; padding: 0; margin: 0; } .findings li { margin: 0 0 12px; overflow-wrap: anywhere; }
41
+ .badge { display: inline-block; color: #fff; border-radius: 4px; padding: 0 7px; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; }
42
+ .s-strong { background: #b4232c; } .s-moderate { background: #a35f00; } .s-weak { background: #2f6f8f; } .s-info { background: #5b6470; }
43
+ .always { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 14px; }
44
+ details { margin-top: 14px; } summary { cursor: pointer; color: var(--muted); }
45
+ pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .82rem; background: var(--bg); padding: 10px; border-radius: 6px; max-height: 360px; overflow: auto; }
46
+ footer { margin-top: 26px; }
47
+ .tone-grey { border-color: var(--muted); } .tone-grey .v-title { color: var(--muted); }
48
+ /* video-keyframes */
49
+ main > section { margin-top: 18px; }
50
+ fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 14px 0; padding: 8px 12px 12px; }
51
+ legend { font-weight: 600; padding: 0 4px; }
52
+ fieldset label { display: block; margin: 6px 0; }
53
+ .range { padding-left: 26px; color: var(--muted); font-size: .92rem; }
54
+ #every { width: 70px; font: inherit; padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
55
+ .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
56
+ .row.between { justify-content: space-between; }
57
+ .primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; padding: 8px 18px; }
58
+ @media (prefers-color-scheme: dark) { .primary { color: #0d1117; } }
59
+ button:disabled { opacity: .5; cursor: not-allowed; }
60
+ progress { width: 100%; margin-top: 12px; accent-color: var(--accent); }
61
+ video { width: 100%; max-height: 360px; background: #000; border-radius: 8px; }
62
+ h2 { font-size: 1.2rem; margin: 0; }
63
+ .frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-top: 12px; }
64
+ .frames figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
65
+ .thumb { display: block; padding: 0; border: 0; background: none; width: 100%; cursor: zoom-in; }
66
+ .thumb img { display: block; width: 100%; border-radius: 6px; }
67
+ figcaption { margin: 6px 0 4px; font-size: .9rem; } .how { color: var(--muted); font-size: .8rem; }
68
+ .mono { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }
69
+ .row.small button { font-size: .8rem; padding: 3px 8px; }
70
+ .engines { margin-top: 6px; font-size: .8rem; color: var(--muted); }
71
+ dialog { max-width: 96vw; max-height: 94vh; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
72
+ dialog img { display: block; max-width: 92vw; max-height: 82vh; } dialog form { text-align: right; margin-top: 6px; }
73
+ dialog::backdrop { background: rgba(0,0,0,.7); }
74
+ .about h2 { font-size: 1.05rem; margin: 0 0 8px; } .about ul { padding-left: 18px; font-size: .92rem; } .about li { margin: 0 0 6px; }