-
Notifications
You must be signed in to change notification settings - Fork 143
/
wav-to-ogg.html
330 lines (272 loc) · 14.6 KB
/
wav-to-ogg.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
<!--
> Muaz Khan - www.MuazKhan.com
> MIT License - www.WebRTC-Experiment.com/licence
> Documentation - github.com/muaz-khan/Ffmpeg.js
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>RecordRTC WAV to Ogg using ffmpeg-asm.js</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="author" type="text/html" href="https://plus.google.com/+MuazKhan">
<meta name="author" content="Muaz Khan">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="https://cdn.webrtc-experiment.com/style.css">
<style>
audio { vertical-align: middle; }
input {
border: 1px solid #d9d9d9;
border-radius: 1px;
font-size: 2em;
margin: .2em;
width: 30%;
}
p, .inner { padding: 1em; }
li {
border-bottom: 1px solid rgb(189, 189, 189);
border-left: 1px solid rgb(189, 189, 189);
padding: .5em;
}
label {
display: inline-block;
width: 8em;
}
</style>
<script>
document.createElement('article');
document.createElement('footer');
</script>
<!-- script used for audio/video/gif recording -->
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js"> </script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
</head>
<body>
<article>
<header style="text-align: center;">
<h1>
<a href="https://www.webrtc-experiment.com/RecordRTC/">RecordRTC</a> WAV to Ogg using <a href="http://bgrins.github.io/videoconverter.js/">ffmpeg-asm.js</a>!
</h1>
<p>
<a href="https://www.webrtc-experiment.com/ffmpeg/">HOME</a>
<span> © </span>
<a href="http://www.MuazKhan.com/" target="_blank">Muaz Khan</a>
.
<a href="http://twitter.com/WebRTCWeb" target="_blank" title="Twitter profile for WebRTC Experiments">@WebRTCWeb</a>
.
<a href="https://github.com/muaz-khan?tab=repositories" target="_blank" title="Github Profile">Github</a>
.
<a href="https://github.com/muaz-khan/Ffmpeg.js/issues?state=open" target="_blank">Latest issues</a>
.
<a href="https://github.com/muaz-khan/Ffmpeg.js/commits/master" target="_blank">What's New?</a>
</p>
</header>
<div class="github-stargazers"></div>
<section class="experiment">
<h2 class="header">Logs</h2>
<ol id="logs-preview">
<li>
<a href="https://www.webrtc-experiment.com/RecordRTC/">RecordRTC</a> experiment converting WAV to Ogg inside the browser!
</li>
</ol>
</section>
<section class="experiment">
<h2 class="header">Record Audio and convert into "Ogg" using <a href="https://archive.org/download/ffmpeg_asm/ffmpeg_asm.js" download="ffmpeg-asm.js">ffmpeg-asm.js</a>!</h2>
<div class="inner">
<audio id="audio-preview" controls muted></audio>
<br>
<button id="record-audio">Record</button>
<button id="stop-recording-audio" disabled>Stop</button>
<br>
</div>
</section>
<script>
var recordAudio;
var audioPreview = document.getElementById('audio-preview');
var inner = document.querySelector('.inner');
document.querySelector('#record-audio').onclick = function() {
this.disabled = true;
navigator.getUserMedia({
audio: true
}, function(stream) {
audioPreview.srcObject = stream;
audioPreview.play();
recordAudio = RecordRTC(stream, {
bufferSize: 16384,
recorderType: StereoAudioRecorder
});
recordAudio.startRecording();
}, function(error) { throw error;});
document.querySelector('#stop-recording-audio').disabled = false;
};
document.querySelector('#stop-recording-audio').onclick = function() {
this.disabled = true;
recordAudio.stopRecording(function(url) {
if(!!navigator.mozGetUserMedia) { // remove this if-block if you still want to use ffmpeg-asm.js in Firefox.
log('We do not need to use ffmpeg-asm.js in Firefox.');
log('If you are still interested to use ffmpeg-asm.js in Firefox then set <a href="https://github.com/muaz-khan/RecordRTC#recordertype">this recorderType</a> parameter.');
log('E.g. <code>recordAudio = RecordRTC(stream, { recordertype: StereoAudioRecorder });</code>');
var blob = new File([recordAudio.blob], 'test.ogg', {
type:' audio/ogg'
});
audioPreview.src = URL.createObjectURL(blob);
audioPreview.download = 'Orignal.ogg';
PostBlob(blob);
return;
}
audioPreview.src = url;
audioPreview.download = 'Orignal.wav';
log('<a href="'+ workerPath +'" download="ffmpeg-asm.js">ffmpeg-asm.js</a> file download started. It is about 18MB in size; please be patient!');
convertStreams(recordAudio.getBlob());
});
};
var workerPath = 'https://archive.org/download/ffmpeg_asm/ffmpeg_asm.js';
if(document.domain == 'localhost') {
workerPath = location.href.replace(location.href.split('/').pop(), '') + 'ffmpeg_asm.js';
}
function processInWebWorker() {
var blob = URL.createObjectURL(new Blob(['importScripts("' + workerPath + '");var now = Date.now;function print(text) {postMessage({"type" : "stdout","data" : text});};onmessage = function(event) {var message = event.data;if (message.type === "command") {var Module = {print: print,printErr: print,files: message.files || [],arguments: message.arguments || [],TOTAL_MEMORY: message.TOTAL_MEMORY || false};postMessage({"type" : "start","data" : Module.arguments.join(" ")});postMessage({"type" : "stdout","data" : "Received command: " +Module.arguments.join(" ") +((Module.TOTAL_MEMORY) ? ". Processing with " + Module.TOTAL_MEMORY + " bits." : "")});var time = now();var result = ffmpeg_run(Module);var totalTime = now() - time;postMessage({"type" : "stdout","data" : "Finished processing (took " + totalTime + "ms)"});postMessage({"type" : "done","data" : result,"time" : totalTime});}};postMessage({"type" : "ready"});'], {
type: 'application/javascript'
}));
var worker = new Worker(blob);
URL.revokeObjectURL(blob);
return worker;
}
var worker;
function convertStreams(audioBlob) {
var aab;
var buffersReady;
var workerReady;
var posted;
var fileReader = new FileReader();
fileReader.onload = function() {
aab = this.result;
postMessage();
};
fileReader.readAsArrayBuffer(audioBlob);
if (!worker) {
worker = processInWebWorker();
}
worker.onmessage = function(event) {
var message = event.data;
if (message.type == "ready") {
log('<a href="'+ workerPath +'" download="ffmpeg-asm.js">ffmpeg-asm.js</a> file has been loaded.');
workerReady = true;
if (buffersReady)
postMessage();
} else if (message.type == "stdout") {
log(message.data);
} else if (message.type == "start") {
log('<a href="'+ workerPath +'" download="ffmpeg-asm.js">ffmpeg-asm.js</a> file received ffmpeg command.');
} else if (message.type == "done") {
log(JSON.stringify(message));
var result = message.data[0];
log(JSON.stringify(result));
var blob = new File([result.data], 'test.ogg', {
type: 'audio/ogg'
});
log(JSON.stringify(blob));
PostBlob(blob);
}
};
var postMessage = function() {
posted = true;
worker.postMessage({
type: 'command',
arguments: '-i audio.wav -c:a vorbis -b:a 4800k -strict experimental output.ogg'.split(' '),
files: [
{
data: new Uint8Array(aab),
name: "audio.wav"
}
]
});
};
}
function PostBlob(blob) {
var audio = document.createElement('audio');
audio.controls = true;
var source = document.createElement('source');
source.src = URL.createObjectURL(blob);
source.type = 'audio/ogg; codecs=vorbis';
audio.appendChild(source);
audio.download = 'Converted Audio.ogg';
inner.appendChild(document.createElement('hr'));
var h2 = document.createElement('h2');
h2.innerHTML = '<a href="' + source.src + '" target="_blank" download="Converted Audio.ogg" style="font-size:200%;color:red;">Download Converted Ogg:</a>';
inner.appendChild(h2);
h2.style.display = 'block';
inner.appendChild(audio);
audio.tabIndex = 0;
audio.focus();
audio.play();
document.querySelector('#record-audio').disabled = false;
}
var logsPreview = document.getElementById('logs-preview');
function log(message) {
var li = document.createElement('li');
li.innerHTML = message;
logsPreview.appendChild(li);
li.tabIndex = 0;
li.focus();
}
window.onbeforeunload = function() {
document.querySelector('#record-audio').disabled = false;
};
</script>
<section class="experiment own-widgets">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/Ffmpeg.js/issues" target="_blank">Ffmpeg.js Issues</a>
</h2>
<div id="github-issues"></div>
</section>
<section class="experiment">
<h2 class="header" id="feedback">Feedback</h2>
<div>
<textarea id="message" style="border: 1px solid rgb(189, 189, 189); height: 8em; margin: .2em; outline: none; resize: vertical; width: 98%;" placeholder="Have any message? Suggestions or something went wrong?"></textarea>
</div>
<button id="send-message" style="font-size: 1em;">Send Message</button><small style="margin-left: 1em;">Enter your email too; if you want "direct" reply!</small>
</section>
<section class="experiment">
<h2 class="header">Using ffmpeg-asm.js...</h2>
<ol>
<li>
WebM can be converted in mp4.
</li>
<li>
WAV can be converted in ogg or mp3 (AAC/Vorbis).
</li>
<li>
WAV can be merged in mp4.
</li>
</ol>
<p style="margin-top: 0;">
If WAV or WebM is 5MB in size; ogg, mp3 or mp4 will be 700kb!
</p>
</section>
<section class="experiment">
<p style="margin-top: 0;">
Ffmpeg.js is MIT licensed on Github! <a href="https://github.com/muaz-khan/Ffmpeg.js" target="_blank">Documentation</a>
</p>
</section>
<section class="experiment own-widgets latest-commits">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/Ffmpeg.js/commits/master" target="_blank">Latest Updates</a></h2>
<div id="github-commits"></div>
</section>
</article>
<a href="https://github.com/muaz-khan/Ffmpeg.js" class="fork-right"></a>
<a href="https://github.com/muaz-khan/RecordRTC" class="fork-left"></a>
<footer>
<p>
<a href="https://www.webrtc-experiment.com/">WebRTC Experiments</a>
© <a href="https://plus.google.com/+MuazKhan" rel="author" target="_blank">Muaz Khan</a>
<a href="mailto:muazkh@gmail.com" target="_blank">muazkh@gmail.com</a>
</p>
</footer>
<!-- commits.js is useless for you! -->
<script>
window.useThisGithubPath = 'muaz-khan/Ffmpeg.js';
</script>
<script src="https://cdn.webrtc-experiment.com/commits.js" async> </script>
</body>
</html>