Skip to content

Commit

Permalink
index.html demo updated to support mp4-recording.
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Feb 3, 2017
1 parent 02d524b commit 0b25a2f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
@@ -1,4 +1,6 @@
# [RecordRTC](https://github.com/muaz-khan/RecordRTC): [WebRTC](https://www.webrtc-experiment.com/) audio/video recording
# RecordRTC: WebRTC JavaScript Library for Audio+Video+Screen Recording

# Demo: https://www.webrtc-experiment.com/RecordRTC/

[RecordRTC Documentation](http://RecordRTC.org/) / [RecordRTC Wiki Pages](https://github.com/muaz-khan/RecordRTC/wiki) / [RecordRTC Demo](https://www.webrtc-experiment.com/RecordRTC/) / [WebRTC Experiments](https://www.webrtc-experiment.com/)

Expand Down
14 changes: 12 additions & 2 deletions RecordRTC.js
@@ -1,4 +1,4 @@
// Last time updated: 2017-01-05 10:11:56 AM UTC
// Last time updated: 2017-02-03 12:20:23 PM UTC

// ________________
// RecordRTC v5.4.0
Expand Down Expand Up @@ -1703,6 +1703,16 @@ function MediaStreamRecorder(mediaStream, config) {
recorderHints = 'video/vp8';
}

if (typeof MediaRecorder.isTypeSupported === 'function' && recorderHints.mimeType) {
if (!MediaRecorder.isTypeSupported(recorderHints.mimeType)) {
if (!config.disableLogs) {
console.warn('MediaRecorder API seems unable to record mimeType:', recorderHints.mimeType);
}

recorderHints.mimeType = config.type === 'audio' ? 'audio/webm' : 'video/webm';
}
}

// http://dxr.mozilla.org/mozilla-central/source/content/media/MediaRecorder.cpp
// https://wiki.mozilla.org/Gecko:MediaRecorder
// https://dvcs.w3.org/hg/dap/raw-file/default/media-stream-capture/MediaRecorder.html
Expand All @@ -1715,7 +1725,7 @@ function MediaStreamRecorder(mediaStream, config) {
mediaRecorder = new MediaRecorder(mediaStream);
}

if ('canRecordMimeType' in mediaRecorder && mediaRecorder.canRecordMimeType(config.mimeType) === false) {
if (!MediaRecorder.isTypeSupported && 'canRecordMimeType' in mediaRecorder && mediaRecorder.canRecordMimeType(config.mimeType) === false) {
if (!config.disableLogs) {
console.warn('MediaRecorder API seems unable to record mimeType:', config.mimeType);
}
Expand Down
6 changes: 3 additions & 3 deletions RecordRTC.min.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion dev/MediaStreamRecorder.js
Expand Up @@ -100,6 +100,16 @@ function MediaStreamRecorder(mediaStream, config) {
recorderHints = 'video/vp8';
}

if (typeof MediaRecorder.isTypeSupported === 'function' && recorderHints.mimeType) {
if (!MediaRecorder.isTypeSupported(recorderHints.mimeType)) {
if (!config.disableLogs) {
console.warn('MediaRecorder API seems unable to record mimeType:', recorderHints.mimeType);
}

recorderHints.mimeType = config.type === 'audio' ? 'audio/webm' : 'video/webm';
}
}

// http://dxr.mozilla.org/mozilla-central/source/content/media/MediaRecorder.cpp
// https://wiki.mozilla.org/Gecko:MediaRecorder
// https://dvcs.w3.org/hg/dap/raw-file/default/media-stream-capture/MediaRecorder.html
Expand All @@ -112,7 +122,7 @@ function MediaStreamRecorder(mediaStream, config) {
mediaRecorder = new MediaRecorder(mediaStream);
}

if ('canRecordMimeType' in mediaRecorder && mediaRecorder.canRecordMimeType(config.mimeType) === false) {
if (!MediaRecorder.isTypeSupported && 'canRecordMimeType' in mediaRecorder && mediaRecorder.canRecordMimeType(config.mimeType) === false) {
if (!config.disableLogs) {
console.warn('MediaRecorder API seems unable to record mimeType:', config.mimeType);
}
Expand Down
25 changes: 17 additions & 8 deletions index.html
Expand Up @@ -240,6 +240,7 @@ <h2 class="header">
var recordingMedia = recordingDIV.querySelector('.recording-media');
var recordingPlayer = recordingDIV.querySelector('video');
var mediaContainerFormat = recordingDIV.querySelector('.media-container-format');
var mimeType = 'video/webm';

window.onbeforeunload = function() {
recordingDIV.querySelector('button').disabled = false;
Expand Down Expand Up @@ -329,9 +330,17 @@ <h2 class="header">
}
};

var mimeType = 'video/webm';
if(mediaContainerFormat.value === 'Mp4') {
mimeType = 'video/mp4; codecs=h264';
mimeType = 'video/webm\;codecs=h264';

if(typeof MediaRecorder.isTypeSupported === 'function') {
if(MediaRecorder.isTypeSupported('video/mpeg')) {
mimeType = 'video/mpeg';
}
else {
mimeType = 'video/webm\;codecs=h264';
}
}
}

if(recordingMedia.value === 'record-audio') {
Expand Down Expand Up @@ -864,8 +873,8 @@ <h2 class="header">
recordingDIV.querySelector('#save-to-disk').onclick = function() {
if(!recordRTC) return alert('No recording found.');

var file = new File([recordRTC.getBlob()], 'RecordRTC-' + (new Date).toISOString().replace(/:|\./g, '-') + '.webm', {
type: 'video/webm'
var file = new File([recordRTC.getBlob()], 'RecordRTC-' + (new Date).toISOString().replace(/:|\./g, '-') + '.' + (mimeType.indexOf('h264') != -1 ? 'mp4' : 'webm'), {
type: mimeType
});

invokeSaveAsDialog(file, file.name);
Expand All @@ -874,15 +883,15 @@ <h2 class="header">
recordingDIV.querySelector('#open-new-tab').onclick = function() {
if(!recordRTC) return alert('No recording found.');

var file = new File([recordRTC.getBlob()], 'RecordRTC-' + (new Date).toISOString().replace(/:|\./g, '-') + '.webm', {
type: 'video/webm'
var file = new File([recordRTC.getBlob()], 'RecordRTC-' + (new Date).toISOString().replace(/:|\./g, '-') + '.' + (mimeType.indexOf('h264') != -1 ? 'mp4' : 'webm'), {
type: mimeType
});

window.open(URL.createObjectURL(file));
};

var file = new File([recordRTC.getBlob()], 'RecordRTC-' + (new Date).toISOString().replace(/:|\./g, '-') + '.webm', {
type: 'video/webm'
var file = new File([recordRTC.getBlob()], 'RecordRTC-' + (new Date).toISOString().replace(/:|\./g, '-') + '.' + (mimeType.indexOf('h264') != -1 ? 'mp4' : 'webm'), {
type: mimeType
});

window.open(URL.createObjectURL(file));
Expand Down

0 comments on commit 0b25a2f

Please sign in to comment.