Skip to content

Commit

Permalink
ability to specify bitrate setting in lamejs plugin (#214)
Browse files Browse the repository at this point in the history
* add ability to specify bitrate setting in lamejs plugin
* allow overriding sampleRate in lamejs plugin
* allow to specify samplerate in libvorbis plugin
  • Loading branch information
thijstriemstra authored Feb 25, 2018
1 parent b2c1d5d commit 51ac357
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ videojs-record changelog

- Bump required version for videojs-wavesurfer to 2.2.1 for compatibility
with video.js 6.7.x (#208)
- Ability to specify bitrate setting in lamejs plugin (#213)


2.1.1 - 2018/02/19
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ The available options for this plugin are:
| `audioMimeType` | string | `'auto'` | The mime type for the audio recorder. Defaults to `auto` which will pick the best option available in the browser (e.g. either `audio/wav`, `audio/ogg` or `audio/webm`). A full list of supported mime-types in the Chrome browser is listed [here](https://cs.chromium.org/chromium/src/third_party/WebKit/LayoutTests/fast/mediarecorder/MediaRecorder-isTypeSupported.html).|
| `audioBufferSize` | float | `4096` | The size of the audio buffer (in sample-frames per second). Legal values: 0, 256, 512, 1024, 2048, 4096, 8192 and 16384. |
| `audioSampleRate` | float | `44100` | The audio sample rate (in sample-frames per second) at which the `AudioContext` handles audio. Legal values are in the range of 22050 to 96000. |
| `audioBitRate` | float | `128` | The audio bitrate in kbps (only used in the lamejs plugin). |
| `audioChannels` | float | `2` | Number of audio channels. Using a single channel results in a smaller filesize. |
| `audioWorkerURL` | string | `''` | URL for the audio worker, for example: `/opus-recorder/build/encoderWorker.min.js`. Currently only used for opus-recorder and lamejs plugins. |
| `animationFrameRate` | float | `200` | Frame rate for animated GIF (in frames per second). |
Expand Down
4 changes: 3 additions & 1 deletion examples/plugins/audio-only-mp3.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
maxLength: 20,
debug: true,
audioEngine: "lamejs",
audioWorkerURL: "../../node_modules/lamejs/worker-example/worker-realtime.js"
audioWorkerURL: "../../node_modules/lamejs/worker-example/worker-realtime.js",
audioSampleRate: 44100,
audioBitRate: 128
}
}
}, function() {
Expand Down
3 changes: 2 additions & 1 deletion examples/plugins/audio-only-ogg.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
video: false,
maxLength: 20,
debug: true,
audioEngine: "libvorbis.js"
audioEngine: "libvorbis.js",
audioSampleRate: 32000
}
}
}, function() {
Expand Down
2 changes: 2 additions & 0 deletions src/js/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const pluginDefaultOptions = {
// An implementation must support sample-rates in at least
// the range 22050 to 96000.
audioSampleRate: 44100,
// The audio bitrate in kbps (only used in lamejs plugin).
audioBitRate: 128,
// Allows you to record single-channel audio, which can reduce the
// filesize.
audioChannels: 2,
Expand Down
7 changes: 4 additions & 3 deletions src/js/plugins/lamejs-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ class LamejsEngine extends RecordEngine {
this.inputStream = stream;
this.mediaType = mediaType;
this.debug = debug;
this.audioType = 'audio/mp3';

let config = {
debug: this.debug,
sampleRate: this.sampleRate
sampleRate: this.sampleRate,
bitRate: this.bitRate
};

this.audioContext = new AudioContext();
this.audioSourceNode = this.audioContext.createMediaStreamSource(
this.inputStream);
this.processor = this.audioContext.createScriptProcessor(
16384, 1, 1);
config.sampleRate = this.audioContext.sampleRate;

this.engine = new Worker(this.audioWorkerURL);
this.engine.onmessage = this.onWorkerMessage.bind(this);
Expand Down Expand Up @@ -67,7 +68,7 @@ class LamejsEngine extends RecordEngine {
switch (ev.data.cmd) {
case 'end':
this.onStopRecording(new Blob(ev.data.buf,
{type: 'audio/mp3'}));
{type: this.audioType}));
break;

case 'error':
Expand Down
2 changes: 1 addition & 1 deletion src/js/plugins/libvorbis-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LibVorbisEngine extends RecordEngine {

// setup libvorbis.js
this.options = {
audioBitsPerSecond: 32000
audioBitsPerSecond: this.sampleRate
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/js/videojs.record.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class Record extends Plugin {
this.audioWorkerURL = recordOptions.audioWorkerURL;
this.audioBufferSize = recordOptions.audioBufferSize;
this.audioSampleRate = recordOptions.audioSampleRate;
this.audioBitRate = recordOptions.audioBitRate;
this.audioChannels = recordOptions.audioChannels;
this.audioMimeType = recordOptions.audioMimeType;

Expand Down Expand Up @@ -444,6 +445,7 @@ class Record extends Plugin {
// audio settings
this.engine.bufferSize = this.audioBufferSize;
this.engine.sampleRate = this.audioSampleRate;
this.engine.bitRate = this.audioBitRate;
this.engine.audioChannels = this.audioChannels;
this.engine.audioWorkerURL = this.audioWorkerURL;

Expand Down

0 comments on commit 51ac357

Please sign in to comment.