forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
342 lines (316 loc) · 11.6 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Media Recorder and Playback Tool | Record and Test Your Audio and Video</title>
<meta name="description" content="Use our Media Recorder and Playback Tool to easily record video and audio snippets without ads, sign-ins, or payments. Perfect for testing audio loudness and synchronization.">
<meta name="keywords" content="media recorder, video recording, audio recording, test audio, test video, audio loudness, audio synchronization, no ads, no sign-in, no payment">
<meta name="author" content="VDO.Ninja">
<link rel="canonical" href="https://vdo.ninja/recorder">
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon" />
<link id="favicon1" rel="icon" type="image/png" sizes="32x32" href="../media/favicon-32x32.png" />
<link id="favicon2" rel="icon" type="image/png" sizes="16x16" href="../media/favicon-16x16.png" />
<link id="favicon3" rel="icon" href="../media/favicon.ico" />
<link id="thumbnailUrl" itemprop="thumbnailUrl" href="../media/vdoNinja_logo_full.png" />
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #2b2b2b;
font-family: 'Helvetica Neue', Arial, sans-serif;
color: #e0e0e0;
}
#container {
text-align: center;
width: 90%;
max-width: 800px;
padding: 20px;
background: #3a3a3a;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}
h1 {
font-size: 24px;
margin-bottom: 15px;
color: #ffffff;
}
#video {
display: block;
margin: 10px auto;
max-width: 100%;
max-height: 50vh;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}
#audio-meter {
width: 100%;
height: 20px;
background: #444;
margin-top: 10px;
border-radius: 10px;
overflow: hidden;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}
#meter-fill {
width: 0%;
height: 100%;
background: linear-gradient(90deg, #4caf50, #76ff0322);
border-radius: 10px;
}
#controls {
margin-top: 15px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
select, button {
margin: 5px;
padding: 8px 15px;
font-size: 14px;
border: none;
border-radius: 5px;
cursor: pointer;
background-color: #007bff;
color: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
transition: background-color 0.2s;
}
button:hover {
background-color: #0056b3;
}
select {
background-color: #555;
color: #e0e0e0;
padding: 8px;
border: 1px solid #666;
}
.recording-indicator {
color: red;
animation: pulse 1s infinite;
margin-top: 10px;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.hidden {
display: none;
}
@media (max-width: 600px) {
#container {
padding: 10px;
}
h1 {
font-size: 20px;
}
select, button {
padding: 6px 12px;
font-size: 12px;
}
}
@media (max-height: 500px) {
#container {
height: auto;
overflow-y: auto;
}
#video {
max-height: 40vh;
}
}
</style>
</head>
<body>
<div id="container">
<h1>Media Recorder and Playback Tool</h1>
<select id="videoSource"></select>
<select id="audioSource"></select>
<video id="video" autoplay muted></video>
<div id="audio-meter">
<div id="meter-fill"></div>
</div>
<div id="controls">
<button id="record" disabled>Record</button>
<button id="play" class="hidden">Play</button>
<button id="download" class="hidden">Download</button>
<div id="recording-indicator" class="hidden recording-indicator">Recording...</div>
</div>
</div>
<script>
const videoElement = document.getElementById('video');
const recordButton = document.getElementById('record');
const playButton = document.getElementById('play');
const downloadButton = document.getElementById('download');
const meterFill = document.getElementById('meter-fill');
const videoSelect = document.getElementById('videoSource');
const audioSelect = document.getElementById('audioSource');
const recordingIndicator = document.getElementById('recording-indicator');
let mediaStream = null;
let mediaRecorder = null;
let recordedChunks = [];
let audioContext = null;
let meter = null;
let sourceNode = null;
let recordedBlob = null;
(function (w) {
w.URLSearchParams =
w.URLSearchParams ||
function (searchString) {
var self = this;
self.searchString = searchString;
self.get = function (name) {
var results = new RegExp("[\?&]" + name + "=([^&#]*)").exec(self.searchString);
if (results == null) {
return null;
} else {
return decodeURI(results[1]) || 0;
}
};
};
})(window);
var urlParams = new URLSearchParams(window.location.search);
var denoise = false;
if (urlParams.has("denoise")){
denoise = true;
console.log("De-noising enabled");
}
var autogain = true;
if (urlParams.has("noautogain")){
autogain = false;
console.log("Auto-gain disabled");
}
async function init() {
try {
await getDevices();
await startMedia();
} catch (error) {
console.error('Error initializing media:', error);
}
}
async function getDevices() {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
const videoDevices = devices.filter(device => device.kind === 'videoinput');
const audioDevices = devices.filter(device => device.kind === 'audioinput');
videoSelect.innerHTML = videoDevices.map(device => `<option value="${device.deviceId}">${device.label}</option>`).join('');
audioSelect.innerHTML = audioDevices.map(device => `<option value="${device.deviceId}">${device.label}</option>`).join('');
} catch (error) {
console.error('Error getting devices:', error);
}
}
async function startMedia() {
try {
if (mediaStream) {
mediaStream.getTracks().forEach(track => track.stop());
}
const videoSource = videoSelect.value;
const audioSource = audioSelect.value;
mediaStream = await navigator.mediaDevices.getUserMedia({
video: { deviceId: videoSource ? { exact: videoSource } : undefined },
audio: {
deviceId: audioSource ? { exact: audioSource } : undefined,
echoCancellation: false,
noiseSuppression: denoise,
autoGainControl: autogain
}
});
videoElement.srcObject = mediaStream;
if (audioContext) {
audioContext.close();
}
audioContext = new (window.AudioContext || window.webkitAudioContext)();
await audioContext.audioWorklet.addModule('testrecord-processor.js');
const audioTracks = mediaStream.getAudioTracks();
if (audioTracks.length > 0) {
sourceNode = audioContext.createMediaStreamSource(mediaStream);
meter = new AudioWorkletNode(audioContext, 'meter');
meter.port.onmessage = (event) => {
const volume = event.data;
meterFill.style.width = `${Math.min(volume * 100, 100)}%`;
};
sourceNode.connect(meter).connect(audioContext.destination);
}
recordButton.removeAttribute("disabled");
} catch (error) {
console.error('Error starting media:', error);
}
}
recordButton.addEventListener('click', async () => {
try {
await audioContext.resume();
if (mediaRecorder && mediaRecorder.state === 'recording') {
mediaRecorder.stop();
recordButton.textContent = 'Record';
recordingIndicator.classList.add('hidden');
videoSelect.removeAttribute("disabled");
audioSelect.removeAttribute("disabled");
} else {
// Show live camera feed again
videoElement.srcObject = mediaStream;
videoElement.controls = false;
videoElement.muted = true;
playButton.classList.add('hidden');
downloadButton.classList.add('hidden');
recordedChunks = [];
mediaRecorder = new MediaRecorder(mediaStream);
mediaRecorder.ondataavailable = event => {
if (event.data.size > 0) {
recordedChunks.push(event.data);
}
};
mediaRecorder.onstop = () => {
recordedBlob = new Blob(recordedChunks, { type: 'video/webm' });
videoElement.srcObject = null;
videoElement.src = URL.createObjectURL(recordedBlob);
videoElement.controls = true;
videoElement.loop = true;
videoElement.muted = false; // Unmute during playback
playButton.classList.remove('hidden');
downloadButton.classList.remove('hidden');
playButton.textContent = 'Play';
videoElement.pause(); // Ensure the video does not autoplay
};
mediaRecorder.start();
recordButton.textContent = 'Stop';
recordingIndicator.classList.remove('hidden');
videoSelect.setAttribute("disabled", "true");
audioSelect.setAttribute("disabled", "true");
}
} catch (error) {
console.error('Error during recording:', error);
}
});
function updatePlayButtonText() {
playButton.textContent = videoElement.paused ? 'Play' : 'Stop';
}
videoElement.addEventListener('play', updatePlayButtonText);
videoElement.addEventListener('pause', updatePlayButtonText);
playButton.addEventListener('click', () => {
if (videoElement.paused) {
videoElement.play();
} else {
videoElement.pause();
}
updatePlayButtonText();
});
downloadButton.addEventListener('click', () => {
const url = URL.createObjectURL(recordedBlob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'recording.webm';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
videoSelect.onchange = startMedia;
audioSelect.onchange = startMedia;
init();
</script>
</body>
</html>