-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv3.1-Preview.html
176 lines (147 loc) · 6.65 KB
/
v3.1-Preview.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Screenshot v2d</title>
</head>
<body>
<input type="file" id="videoInput" accept="video/*">
<label for="frequency">Screenshot Frequency (seconds):</label>
<input type="number" id="frequency" min="1" step="1" value="1">
<label for="format">Output Format:</label>
<select id="format">
<option value="png">PNG</option>
<option value="jpeg">JPEG</option>
</select>
<label for="playAudio">Play Audio:</label>
<input type="checkbox" id="playAudio" checked>
<label for="previewCheckbox">Show Preview:</label>
<input type="checkbox" id="previewCheckbox" checked>
<button onclick="startScreenshot()">Start Screenshot</button>
<div id="screenshotContainer"></div>
<div id="previewContainer"></div>
<div id="progressBar">
<div id="progress" style="width: 0%;"></div>
<div id="progressText">0%</div>
<div id="etaText">ETA: --</div>
</div>
<script>
let screenshots = [];
let packNumber = 1;
let interval;
let startTime;
function startScreenshot() {
clearInterval(interval);
screenshots = [];
packNumber = 1;
startTime = new Date();
const videoInput = document.getElementById('videoInput');
const frequency = parseInt(document.getElementById('frequency').value);
const format = document.getElementById('format').value;
const playAudio = document.getElementById('playAudio').checked;
const previewEnabled = document.getElementById('previewCheckbox').checked;
if (!videoInput.files || !videoInput.files[0]) {
alert('Please select a video file.');
return;
}
const videoFile = videoInput.files[0];
const videoURL = URL.createObjectURL(videoFile);
const video = document.createElement('video');
video.src = videoURL;
video.crossOrigin = 'anonymous';
video.muted = !playAudio;
video.addEventListener('loadedmetadata', () => {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const videoWidth = video.videoWidth;
const videoHeight = video.videoHeight;
canvas.width = videoWidth / 2; // Reduce canvas size for performance
canvas.height = videoHeight / 2;
const duration = video.duration;
let currentTime = 0;
interval = setInterval(() => {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
const image = canvas.toDataURL(`image/${format}`);
screenshots.push(image);
if (previewEnabled) {
showLatestScreenshotPreview(image);
}
const progress = (currentTime / duration) * 100;
updateProgress(progress);
if (currentTime >= duration) {
clearInterval(interval);
updatePackCounter();
} else {
currentTime += frequency;
video.currentTime = currentTime;
}
}, frequency * 1000); // Convert seconds to milliseconds
});
video.load();
video.play();
}
function updateProgress(progress) {
const progressBar = document.getElementById('progress');
const progressText = document.getElementById('progressText');
const etaText = document.getElementById('etaText');
progressBar.style.width = `${progress}%`;
progressText.textContent = `${Math.round(progress)}%`;
if (progress === 0) {
etaText.textContent = 'ETA: --';
} else {
const elapsedTime = (new Date() - startTime) / 1000; // in seconds
const remainingTime = (elapsedTime / progress) * (100 - progress);
etaText.textContent = `ETA: ${formatTime(remainingTime)}`;
}
}
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
return `${minutes}m ${remainingSeconds}s`;
}
function updatePackCounter() {
const packCounter = document.getElementById('packCounter');
packCounter.textContent = `${(packNumber - 1) * 10}/${screenshots.length}`;
}
function downloadImages(start, end) {
const zip = new JSZip();
for (let i = start; i < end; i++) {
const imgData = screenshots[i].split(';base64,')[1];
zip.file(`screenshot_${i + 1}.png`, imgData, {base64: true});
}
zip.generateAsync({type:"blob"})
.then(function(content) {
saveAs(content, `screenshot_${start + 1}-${end}.zip`);
});
}
function createDownloadButtons() {
const container = document.getElementById('screenshotContainer');
container.innerHTML = '';
let start = 0;
let end = 10;
while (start < screenshots.length) {
const button = document.createElement('button');
button.textContent = `Download images ${start + 1}-${end}`;
button.onclick = function() {
downloadImages(start, end);
};
container.appendChild(button);
start = end;
end = Math.min(end + 10, screenshots.length);
}
}
function showLatestScreenshotPreview(image) {
const previewContainer = document.getElementById('previewContainer');
previewContainer.innerHTML = '';
const img = document.createElement('img');
img.src = image;
img.style.maxWidth = '200px';
img.style.maxHeight = '200px';
previewContainer.appendChild(img);
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.0/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
</body>
</html>