-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
787 lines (686 loc) · 27.3 KB
/
index.html
File metadata and controls
787 lines (686 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Frame Capture Studio</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg-primary: #0a0a0b;
--bg-secondary: #111113;
--bg-tertiary: #1a1a1d;
--fg-primary: #f5f5f7;
--fg-secondary: #8b8b8e;
--fg-muted: #5a5a5d;
--accent: #00d4aa;
--accent-dim: #00d4aa33;
--border: #2a2a2d;
--danger: #ff4757;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg-primary);
color: var(--fg-primary);
min-height: 100vh;
}
.mono {
font-family: 'JetBrains Mono', monospace;
}
.bg-noise {
background-image:
radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-dim) 0%, transparent 60%),
url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
}
.glass-card {
background: linear-gradient(135deg, rgba(26,26,29,0.9) 0%, rgba(17,17,19,0.95) 100%);
border: 1px solid var(--border);
backdrop-filter: blur(20px);
}
.glow-line {
height: 1px;
background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
/* Custom range slider */
input[type="range"] {
-webkit-appearance: none;
appearance: none;
background: transparent;
cursor: pointer;
width: 100%;
}
input[type="range"]::-webkit-slider-track {
height: 6px;
background: var(--bg-tertiary);
border-radius: 3px;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 18px;
height: 18px;
background: var(--accent);
border-radius: 50%;
margin-top: -6px;
box-shadow: 0 0 20px var(--accent), 0 0 6px var(--accent);
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
transform: scale(1.2);
box-shadow: 0 0 30px var(--accent), 0 0 10px var(--accent);
}
input[type="range"]::-moz-range-track {
height: 6px;
background: var(--bg-tertiary);
border-radius: 3px;
}
input[type="range"]::-moz-range-thumb {
width: 18px;
height: 18px;
background: var(--accent);
border-radius: 50%;
border: none;
box-shadow: 0 0 20px var(--accent);
}
/* Timeline track fill */
.timeline-container {
position: relative;
}
.timeline-fill {
position: absolute;
top: 50%;
left: 0;
height: 6px;
background: linear-gradient(90deg, var(--accent), var(--accent-dim));
border-radius: 3px;
transform: translateY(-50%);
pointer-events: none;
z-index: 0;
}
/* Drop zone */
.drop-zone {
border: 2px dashed var(--border);
transition: all 0.3s ease;
}
.drop-zone.dragover {
border-color: var(--accent);
background: var(--accent-dim);
}
/* Button styles */
.btn-primary {
background: linear-gradient(135deg, var(--accent) 0%, #00b894 100%);
color: var(--bg-primary);
font-weight: 600;
transition: all 0.2s ease;
position: relative;
overflow: hidden;
}
.btn-primary::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
opacity: 0;
transition: opacity 0.2s ease;
}
.btn-primary:hover::before {
opacity: 1;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 8px 30px var(--accent-dim);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-secondary {
background: var(--bg-tertiary);
border: 1px solid var(--border);
color: var(--fg-primary);
transition: all 0.2s ease;
}
.btn-secondary:hover {
border-color: var(--accent);
background: var(--bg-secondary);
}
/* Input styles */
.input-field {
background: var(--bg-tertiary);
border: 1px solid var(--border);
color: var(--fg-primary);
transition: all 0.2s ease;
}
.input-field:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-dim);
}
/* Video container */
.video-container {
position: relative;
background: var(--bg-secondary);
border: 1px solid var(--border);
}
.video-container video {
display: block;
max-width: 100%;
max-height: 60vh;
margin: 0 auto;
}
/* Animations */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.animate-fade-in {
animation: fadeInUp 0.5s ease forwards;
}
.animate-delay-1 { animation-delay: 0.1s; }
.animate-delay-2 { animation-delay: 0.2s; }
.animate-delay-3 { animation-delay: 0.3s; }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
/* Capture flash effect */
.capture-flash {
position: absolute;
inset: 0;
background: white;
opacity: 0;
pointer-events: none;
z-index: 10;
}
.capture-flash.active {
animation: flash 0.3s ease-out;
}
@keyframes flash {
0% { opacity: 0.8; }
100% { opacity: 0; }
}
/* Frame counter */
.frame-marker {
width: 8px;
height: 8px;
background: var(--accent);
border-radius: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
opacity: 0.6;
cursor: pointer;
transition: all 0.15s ease;
}
.frame-marker:hover {
opacity: 1;
transform: translate(-50%, -50%) scale(1.5);
}
/* Status indicator */
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--fg-muted);
}
.status-dot.ready {
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
</style>
</head>
<body class="bg-noise">
<div class="min-h-screen p-4 md:p-8">
<!-- Header -->
<header class="max-w-5xl mx-auto mb-8 animate-fade-in" style="opacity: 0;">
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-lg bg-gradient-to-br from-[var(--accent)] to-emerald-600 flex items-center justify-center">
<svg class="w-5 h-5 text-black" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
</div>
<div>
<h1 class="text-xl font-bold tracking-tight">Frame Capture Studio</h1>
<p class="text-xs text-[var(--fg-secondary)]">Extract frames at native resolution</p>
</div>
</div>
<div class="flex items-center gap-2">
<div class="status-dot" id="statusDot"></div>
<span class="text-xs text-[var(--fg-secondary)] mono" id="statusText">No video loaded</span>
</div>
</div>
</header>
<main class="max-w-5xl mx-auto space-y-6">
<!-- Upload Section -->
<section id="uploadSection" class="animate-fade-in animate-delay-1" style="opacity: 0;">
<div class="drop-zone glass-card rounded-2xl p-12 text-center cursor-pointer transition-all hover:border-[var(--fg-muted)]" id="dropZone">
<input type="file" id="fileInput" accept="video/*" class="hidden">
<div class="flex flex-col items-center gap-4">
<div class="w-16 h-16 rounded-full bg-[var(--bg-tertiary)] flex items-center justify-center">
<svg class="w-8 h-8 text-[var(--fg-muted)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
</svg>
</div>
<div>
<p class="text-lg font-medium mb-1">Drop your video here</p>
<p class="text-sm text-[var(--fg-secondary)]">or click to browse files</p>
</div>
<p class="text-xs text-[var(--fg-muted)] mono">MP4, WebM, MOV supported</p>
</div>
</div>
</section>
<!-- Video Player Section -->
<section id="playerSection" class="hidden space-y-4">
<!-- Video Display -->
<div class="glass-card rounded-2xl overflow-hidden animate-fade-in" style="opacity: 0;">
<div class="video-container relative" id="videoContainer">
<div class="capture-flash" id="captureFlash"></div>
<video id="videoPlayer" class="w-full"></video>
<!-- Video overlay info -->
<div class="absolute top-4 left-4 flex items-center gap-2">
<span class="mono text-xs bg-black/60 backdrop-blur-sm px-2 py-1 rounded" id="resolutionBadge">--</span>
</div>
<div class="absolute top-4 right-4">
<span class="mono text-xs bg-black/60 backdrop-blur-sm px-2 py-1 rounded" id="currentTimeDisplay">00:00.000</span>
</div>
</div>
</div>
<!-- Timeline Scrubber -->
<div class="glass-card rounded-2xl p-6 animate-fade-in animate-delay-1" style="opacity: 0;">
<div class="space-y-4">
<!-- Timeline bar -->
<div class="timeline-container">
<div class="timeline-fill" id="timelineFill"></div>
<input type="range" id="timelineSlider" min="0" max="100" step="0.001" value="0" class="relative z-10 w-full">
</div>
<!-- Time displays -->
<div class="flex justify-between items-center text-sm">
<span class="mono text-[var(--fg-secondary)]" id="startTime">00:00</span>
<div class="flex items-center gap-4">
<!-- Frame navigation -->
<button class="btn-secondary px-3 py-1.5 rounded-lg text-sm flex items-center gap-1" id="prevFrame">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg>
Frame
</button>
<button class="btn-secondary px-3 py-1.5 rounded-lg text-sm flex items-center gap-1" id="nextFrame">
Frame
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</button>
</div>
<span class="mono text-[var(--fg-secondary)]" id="endTime">00:00</span>
</div>
<div class="glow-line"></div>
<!-- Timestamp input -->
<div class="flex flex-col sm:flex-row gap-4 items-start sm:items-end">
<div class="flex-1 w-full sm:w-auto">
<label class="block text-xs text-[var(--fg-secondary)] mb-2 uppercase tracking-wider">Jump to timestamp</label>
<div class="flex gap-2">
<input type="text" id="timestampInput" placeholder="00:00.000"
class="input-field mono text-sm px-4 py-2.5 rounded-lg flex-1 min-w-0"
pattern="[0-9]{2}:[0-9]{2}\.[0-9]{3}">
<button class="btn-secondary px-4 py-2.5 rounded-lg text-sm" id="jumpBtn">Go</button>
</div>
</div>
<!-- Capture button -->
<button class="btn-primary px-6 py-3 rounded-xl text-sm flex items-center gap-2 w-full sm:w-auto justify-center" id="captureBtn">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 13a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
Capture Frame
</button>
</div>
</div>
</div>
<!-- Video Info -->
<div class="glass-card rounded-2xl p-4 animate-fade-in animate-delay-2" style="opacity: 0;">
<div class="flex flex-wrap gap-4 text-sm">
<div class="flex items-center gap-2">
<span class="text-[var(--fg-secondary)]">File:</span>
<span class="mono truncate max-w-[200px]" id="fileName">--</span>
</div>
<div class="flex items-center gap-2">
<span class="text-[var(--fg-secondary)]">Duration:</span>
<span class="mono" id="duration">--</span>
</div>
<div class="flex items-center gap-2">
<span class="text-[var(--fg-secondary)]">Resolution:</span>
<span class="mono" id="resolution">--</span>
</div>
<div class="flex items-center gap-2 ml-auto">
<button class="text-[var(--fg-secondary)] hover:text-[var(--accent)] transition-colors text-sm flex items-center gap-1" id="loadNewBtn">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Load new video
</button>
</div>
</div>
</div>
</section>
<!-- Captured Frames Section -->
<section id="capturesSection" class="hidden animate-fade-in" style="opacity: 0;">
<div class="glass-card rounded-2xl p-6">
<div class="flex items-center justify-between mb-4">
<h2 class="font-semibold">Captured Frames</h2>
<button class="text-sm text-[var(--fg-secondary)] hover:text-[var(--danger)] transition-colors" id="clearAllBtn">Clear all</button>
</div>
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4" id="capturesGrid"></div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="max-w-5xl mx-auto mt-12 text-center">
<p class="text-xs text-[var(--fg-muted)]">Frames are captured at original video resolution</p>
</footer>
</div>
<!-- Hidden canvas for capture -->
<canvas id="captureCanvas" class="hidden"></canvas>
<script>
// DOM Elements - Initialize all at the start
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const uploadSection = document.getElementById('uploadSection');
const playerSection = document.getElementById('playerSection');
const capturesSection = document.getElementById('capturesSection');
const videoPlayer = document.getElementById('videoPlayer');
const videoContainer = document.getElementById('videoContainer');
const captureFlash = document.getElementById('captureFlash');
const timelineSlider = document.getElementById('timelineSlider');
const timelineFill = document.getElementById('timelineFill');
const timestampInput = document.getElementById('timestampInput');
const captureBtn = document.getElementById('captureBtn');
const jumpBtn = document.getElementById('jumpBtn');
const captureCanvas = document.getElementById('captureCanvas');
const capturesGrid = document.getElementById('capturesGrid');
const statusDot = document.getElementById('statusDot');
const statusText = document.getElementById('statusText');
const resolutionBadge = document.getElementById('resolutionBadge');
const currentTimeDisplay = document.getElementById('currentTimeDisplay');
const startTimeEl = document.getElementById('startTime');
const endTimeEl = document.getElementById('endTime');
const fileNameEl = document.getElementById('fileName');
const durationEl = document.getElementById('duration');
const resolutionEl = document.getElementById('resolution');
const prevFrameBtn = document.getElementById('prevFrame');
const nextFrameBtn = document.getElementById('nextFrame');
const loadNewBtn = document.getElementById('loadNewBtn');
const clearAllBtn = document.getElementById('clearAllBtn');
// State
let currentVideoFile = null;
let capturedFrames = [];
let frameTime = 1 / 30; // Default assumption, will be refined
// Utility functions
function formatTime(seconds) {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
const ms = Math.floor((seconds % 1) * 1000);
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}.${ms.toString().padStart(3, '0')}`;
}
function formatShortTime(seconds) {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
}
function parseTimestamp(timestamp) {
const match = timestamp.match(/^(\d{1,2}):(\d{2})(?:\.(\d{1,3}))?$/);
if (!match) return null;
const mins = parseInt(match[1], 10);
const secs = parseInt(match[2], 10);
const ms = match[3] ? parseInt(match[3].padEnd(3, '0'), 10) : 0;
return mins * 60 + secs + ms / 1000;
}
function updateStatus(text, ready = false) {
statusText.textContent = text;
if (ready) {
statusDot.classList.add('ready');
} else {
statusDot.classList.remove('ready');
}
}
// File handling
function handleFile(file) {
if (!file || !file.type.startsWith('video/')) {
alert('Please select a valid video file.');
return;
}
currentVideoFile = file;
const url = URL.createObjectURL(file);
videoPlayer.src = url;
videoPlayer.onloadedmetadata = () => {
// Show player section
uploadSection.classList.add('hidden');
playerSection.classList.remove('hidden');
// Trigger animations
playerSection.querySelectorAll('.animate-fade-in').forEach((el, i) => {
setTimeout(() => {
el.style.opacity = '1';
}, i * 100);
});
// Update UI
fileNameEl.textContent = file.name;
durationEl.textContent = formatShortTime(videoPlayer.duration);
resolutionEl.textContent = `${videoPlayer.videoWidth} × ${videoPlayer.videoHeight}`;
resolutionBadge.textContent = `${videoPlayer.videoWidth}×${videoPlayer.videoHeight}`;
endTimeEl.textContent = formatShortTime(videoPlayer.duration);
// Estimate frame time (assume 30fps, can be refined)
frameTime = 1 / 30;
updateStatus('Ready', true);
// Seek to start
videoPlayer.currentTime = 0;
};
}
// Event Listeners - File input
dropZone.addEventListener('click', () => fileInput.click());
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('dragover');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('dragover');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
const file = e.dataTransfer.files[0];
handleFile(file);
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
handleFile(file);
});
// Timeline controls
timelineSlider.addEventListener('input', (e) => {
const percent = parseFloat(e.target.value);
const time = (percent / 100) * videoPlayer.duration;
videoPlayer.currentTime = time;
updateTimelineFill(percent);
});
function updateTimelineFill(percent) {
timelineFill.style.width = `${percent}%`;
}
videoPlayer.addEventListener('timeupdate', () => {
const percent = (videoPlayer.currentTime / videoPlayer.duration) * 100;
timelineSlider.value = percent;
currentTimeDisplay.textContent = formatTime(videoPlayer.currentTime);
updateTimelineFill(percent);
});
// Timestamp input
timestampInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
jumpToTimestamp();
}
});
jumpBtn.addEventListener('click', jumpToTimestamp);
function jumpToTimestamp() {
const timestamp = timestampInput.value.trim();
const time = parseTimestamp(timestamp);
if (time === null) {
timestampInput.style.borderColor = 'var(--danger)';
setTimeout(() => {
timestampInput.style.borderColor = '';
}, 1000);
return;
}
if (time >= 0 && time <= videoPlayer.duration) {
videoPlayer.currentTime = time;
timestampInput.style.borderColor = 'var(--accent)';
setTimeout(() => {
timestampInput.style.borderColor = '';
}, 1000);
}
}
// Frame navigation
prevFrameBtn.addEventListener('click', () => {
const newTime = Math.max(0, videoPlayer.currentTime - frameTime);
videoPlayer.currentTime = newTime;
});
nextFrameBtn.addEventListener('click', () => {
const newTime = Math.min(videoPlayer.duration, videoPlayer.currentTime + frameTime);
videoPlayer.currentTime = newTime;
});
// Capture function
captureBtn.addEventListener('click', captureFrame);
function captureFrame() {
const width = videoPlayer.videoWidth;
const height = videoPlayer.videoHeight;
if (width === 0 || height === 0) {
alert('Video not ready. Please wait for the video to load.');
return;
}
// Set canvas to native resolution
captureCanvas.width = width;
captureCanvas.height = height;
const ctx = captureCanvas.getContext('2d');
ctx.drawImage(videoPlayer, 0, 0, width, height);
// Flash effect
captureFlash.classList.add('active');
setTimeout(() => captureFlash.classList.remove('active'), 300);
// Create image data
const imageData = captureCanvas.toDataURL('image/png');
const timestamp = formatTime(videoPlayer.currentTime);
// Add to captures
capturedFrames.push({
data: imageData,
timestamp: timestamp,
width: width,
height: height
});
updateCapturesGrid();
// Show captures section
if (capturedFrames.length === 1) {
capturesSection.classList.remove('hidden');
capturesSection.style.opacity = '1';
}
}
function updateCapturesGrid() {
capturesGrid.innerHTML = capturedFrames.map((frame, index) => `
<div class="group relative rounded-lg overflow-hidden bg-[var(--bg-tertiary)] border border-[var(--border)]">
<img src="${frame.data}" alt="Frame at ${frame.timestamp}" class="w-full aspect-video object-cover">
<div class="absolute inset-0 bg-gradient-to-t from-black/80 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity">
<div class="absolute bottom-0 left-0 right-0 p-2">
<p class="mono text-xs text-[var(--fg-secondary)] mb-2">${frame.timestamp} · ${frame.width}×${frame.height}</p>
<div class="flex gap-2">
<button onclick="downloadFrame(${index})" class="flex-1 bg-[var(--accent)] text-black text-xs py-1.5 rounded font-medium hover:opacity-90 transition-opacity">
Download
</button>
<button onclick="removeFrame(${index})" class="bg-[var(--bg-secondary)] text-[var(--fg-secondary)] text-xs px-3 py-1.5 rounded hover:text-[var(--danger)] transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
</div>
</div>
</div>
</div>
`).join('');
}
// Global functions for inline handlers
window.downloadFrame = function(index) {
const frame = capturedFrames[index];
const link = document.createElement('a');
link.download = `frame_${frame.timestamp.replace(/:/g, '-')}.png`;
link.href = frame.data;
link.click();
};
window.removeFrame = function(index) {
capturedFrames.splice(index, 1);
updateCapturesGrid();
if (capturedFrames.length === 0) {
capturesSection.classList.add('hidden');
}
};
// Clear all captures
clearAllBtn.addEventListener('click', () => {
if (confirm('Remove all captured frames?')) {
capturedFrames = [];
updateCapturesGrid();
capturesSection.classList.add('hidden');
}
});
// Load new video
loadNewBtn.addEventListener('click', () => {
// Reset
videoPlayer.pause();
videoPlayer.src = '';
playerSection.classList.add('hidden');
uploadSection.classList.remove('hidden');
updateStatus('No video loaded', false);
fileInput.value = '';
});
// Keyboard shortcuts
document.addEventListener('keydown', (e) => {
if (playerSection.classList.contains('hidden')) return;
if (e.target.tagName === 'INPUT') return;
switch(e.key) {
case ' ':
e.preventDefault();
if (videoPlayer.paused) {
videoPlayer.play();
} else {
videoPlayer.pause();
}
break;
case 'ArrowLeft':
videoPlayer.currentTime = Math.max(0, videoPlayer.currentTime - (e.shiftKey ? 5 : frameTime));
break;
case 'ArrowRight':
videoPlayer.currentTime = Math.min(videoPlayer.duration, videoPlayer.currentTime + (e.shiftKey ? 5 : frameTime));
break;
case 'c':
case 'C':
captureFrame();
break;
}
});
// Initial animations
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.animate-fade-in').forEach((el, i) => {
setTimeout(() => {
el.style.opacity = '1';
}, i * 100);
});
});
</script>
</body>
</html>