New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

recordrtc

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recordrtc - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

static/README.md

0

config.js

@@ -0,0 +0,0 @@ // Muaz Khan - www.MuazKhan.com

22

handlers.js

@@ -25,3 +25,3 @@ // Muaz Khan - www.MuazKhan.com

if (files.isFirefox) {
if (files.uploadOnlyAudio) {
response.statusCode = 200;

@@ -32,3 +32,3 @@ response.writeHead(200, { 'Content-Type': 'application/json' });

if (!files.isFirefox) {
if (!files.uploadOnlyAudio) {
// writing video file to disk

@@ -81,2 +81,5 @@ _upload(response, files.video);

'webm': 'video/webm',
'mp4': 'video/mp4',
'wav': 'audio/wav',
'ogg': 'audio/ogg',
'gif': 'image/gif'

@@ -88,3 +91,3 @@ };

});
if (extensionTypes[extension] == 'video/webm')
if (hasMediaType(extensionTypes[extension]))
response.end(fs.readFileSync('.' + pathname));

@@ -95,2 +98,11 @@ else

function hasMediaType(type) {
var isHasMediaType = false;
['audio/wav', 'audio/ogg', 'video/webm', 'video/mp4'].forEach(function(t) {
if(t== type) isHasMediaType = true;
});
return isHasMediaType;
}
function ifWin(response, files) {

@@ -130,7 +142,7 @@ // following command tries to merge wav/webm files using ffmpeg

var mergedFile = __dirname + '/uploads/' + files.audio.name.split('.')[0] + '-merged.webm';
var util = require('util'),
exec = require('child_process').exec;
//child_process = require('child_process');
var command = "ffmpeg -i " + audioFile + " -itsoffset -00:00:01 -i " + videoFile + " -map 0:0 -map 1:0 " + mergedFile;
var command = "ffmpeg -i " + audioFile + " -i " + videoFile + " -map 0:0 -map 1:0 " + mergedFile;

@@ -137,0 +149,0 @@ exec(command, function (error, stdout, stderr) {

@@ -0,0 +0,0 @@ // Muaz Khan - www.MuazKhan.com

{
"name": "recordrtc",
"preferGlobal": true,
"version": "3.0.0",
"version": "3.0.1",
"author": {

@@ -48,4 +48,4 @@ "name": "Muaz Khan",

"homepage": "https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-to-Nodejs",
"_id": "recordrtc@3.0.0",
"_id": "recordrtc@3.0.1",
"_from": "recordrtc@"
}

@@ -0,1 +1,5 @@

Note: You MUST always manually create a directory and name it "uploads".
=
#### [RecordRTC to Node.js](https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-to-Nodejs)

@@ -46,3 +50,3 @@

@echo off
"C:\ffmpeg\bin\ffmpeg.exe" -i %1 -itsoffset -00:00:01 -i %2 %3
ffmpeg -i audio-file.wav -i video-file.webm 0:0 -map 1:0 output-file-name.webm
```

@@ -59,3 +63,3 @@

```
ffmpeg -i audio-file.wav -itsoffset -00:00:01 -i video-file.webm -map 0:0 -map 1:0 output-file-name.webm
ffmpeg -i audio-file.wav -i video-file.webm -map 0:0 -map 1:0 output-file-name.webm
```

@@ -67,379 +71,117 @@

##### How to install ffmpeg on windows?
##### Ubuntu, Debian, or Linux Mint?
1. Download ffmpeg and extract ZIP file
2. Rename extracted directory to "ffmpeg"
3. Right click over "My Computer" icon and select "Properties" context-menu option
4. Select "Advance system settings" from top-left section
5. Click "Environment Variables..." button from "Advanced" tab
6. Click "New..." button and in the "Variable name" box, enter "Path".
7. In the "Variable value" box, enter extracted directory full URI e.g. "C:\ffmpeg"
8. Click "OK" and done!
You're suggested to install ffmpeg and libvpx from following URL:
http://www.wikihow.com/Install-FFmpeg-on-Windows
* https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide
=
Another useful resource is:
##### How to install ffmpeg on Mac OSX?
* http://wiki.razuna.com/display/ecp/FFmpeg+Installation+for+Ubuntu
Make sure you have **homebrew** installed. Then run following command:
Read following comments:
> Actually it is very easy to install FFmpeg under Ubuntu with the apt-get command.
> Unfortunately, the default FFmpeg installation doesn't let you include the latest codecs
> which are needed to merge WAV/WebM into vp8 encoded video i.e. WebM!
> Thus you have to compile FFmpeg yourself!
For example, you can check libvpx installation using following command:
```
brew install ffmpeg --with-libvpx --with-theora --whit-libogg --with-libvorbis
dpkg -s libvpx | grep Status
```
##### How to test?
This doesn't mean that you enabled libvpx for ffmpeg; you need to verify vp8 encoders in ffmpeg using following commands:
In the node.js command prompt window; type `node index`; then open `http://localhost:8000/`.
```
ffmpeg -codecs # to check list of all decoders
ffmpeg -encoders # to check list of all encoders
```
=
Usually latest ffmpeg can decode WebM i.e. vp8 codecs; however it can't encode back into vp8 until you manually install libvpx.
##### `index.html`
There is another useful resource!
```html
<!--
// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
// Experiments - github.com/muaz-khan/WebRTC-Experiment
-->
* http://juliensimon.blogspot.com/2013/08/howto-compiling-ffmpeg-x264-mp3-aac.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>RecordRTC over Node.js</title>
<script>
if (location.href.indexOf('file:') == 0) {
document.write('<h1 style="color:red;">Please load this HTML file on HTTP or HTTPS.</h1>');
}
</script>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="author" type="text/html" href="https://plus.google.com/+MuazKhan">
<meta name="author" content="Muaz Khan">
<script src="https://www.webrtc-experiment.com/RecordRTC.js"> </script>
<style>
html { background-color: #f7f7f7; }
This provides a good command to check list of encoders in ffmpeg:
body {
background-color: white;
border: 1px solid rgb(15, 158, 238);
margin: 1% 35%;
text-align: center;
}
```
ffmpeg -encoders|grep -E "mp3|xvid|aac|gsm|amr|x264|theora|vorbis"
```
hr {
border: 0;
border-top: 1px solid rgb(15, 158, 238);
}
Sometimes you mistakenly install multiple ffmpeg instances. Find-out ffmpeg instance that has included libvpx; then include that instance's full path in the ffmpeg-command. E.g.
a {
color: #2844FA;
text-decoration: none;
}
```
ffmpeg -itsoffset -00:00:00 -i audioFile -itsoffset -00:00:00 -i videoFile -map 0:0 -map 1:0 outputFile
```
a:hover, a:focus { color: #1B29A4; }
=
a:active { color: #000; }
</style>
</head>
<body>
<p>
<video id="camera-preview" controls style="border: 1px solid rgb(15, 158, 238); width: 94%;"></video>
</p><hr />
##### How to install ffmpeg on windows?
<div>
<button id="start-recording">Start Recording</button>
<button id="stop-recording" disabled="">Stop Recording</button>
</div>
<script>
var startRecording = document.getElementById('start-recording');
var stopRecording = document.getElementById('stop-recording');
var cameraPreview = document.getElementById('camera-preview');
1. Download ffmpeg and extract ZIP file
2. Rename extracted directory to "ffmpeg"
3. Right click over "My Computer" icon and select "Properties" context-menu option
4. Select "Advance system settings" from top-left section
5. Click "Environment Variables..." button from "Advanced" tab
6. Click "New..." button and in the "Variable name" box, enter "Path".
7. In the "Variable value" box, enter extracted directory full URI e.g. "C:\ffmpeg"
8. Click "OK" and done!
var audio = document.querySelector('audio');
http://www.wikihow.com/Install-FFmpeg-on-Windows
var isFirefox = !!navigator.mozGetUserMedia;
=
var recordAudio, recordVideo;
startRecording.onclick = function() {
startRecording.disabled = true;
navigator.getUserMedia({
audio: true,
video: true
}, function(stream) {
cameraPreview.src = window.URL.createObjectURL(stream);
cameraPreview.play();
##### How to install ffmpeg on Mac OSX?
recordAudio = RecordRTC(stream, {
bufferSize: 16384
});
Make sure you have **homebrew** installed. Then run following command:
if (!isFirefox) {
recordVideo = RecordRTC(stream, {
type: 'video'
});
}
```
brew install ffmpeg --with-libvpx --with-theora --with-libogg --with-libvorbis
```
recordAudio.startRecording();
More info here:
if (!isFirefox) {
recordVideo.startRecording();
}
* https://github.com/muaz-khan/WebRTC-Experiment/issues/198
stopRecording.disabled = false;
}, function(error) {
alert(JSON.stringify(error));
});
};
##### How to test?
In the node.js command prompt window; type `node index`; then open `http://localhost:8000/`.
stopRecording.onclick = function() {
startRecording.disabled = false;
stopRecording.disabled = true;
recordAudio.stopRecording(function() {
if (isFirefox) onStopRecording();
});
if (!isFirefox) {
recordVideo.stopRecording();
onStopRecording();
}
function onStopRecording() {
recordAudio.getDataURL(function(audioDataURL) {
if (!isFirefox) {
recordVideo.getDataURL(function(videoDataURL) {
postFiles(audioDataURL, videoDataURL);
});
} else postFiles(audioDataURL);
});
}
};
var fileName;
function postFiles(audioDataURL, videoDataURL) {
fileName = getRandomString();
var files = { };
files.audio = {
name: fileName + (isFirefox ? '.webm' : '.wav'),
type: isFirefox ? 'video/webm' : 'audio/wav',
contents: audioDataURL
};
if (!isFirefox) {
files.video = {
name: fileName + '.webm',
type: 'video/webm',
contents: videoDataURL
};
}
files.isFirefox = isFirefox;
cameraPreview.src = '';
cameraPreview.poster = '/ajax-loader.gif';
xhr('/upload', JSON.stringify(files), function(_fileName) {
var href = location.href.substr(0, location.href.lastIndexOf('/') + 1);
cameraPreview.src = href + 'uploads/' + _fileName;
cameraPreview.play();
var h2 = document.createElement('h2');
h2.innerHTML = '<a href="' + cameraPreview.src + '">' + cameraPreview.src + '</a>';
document.body.appendChild(h2);
});
}
function xhr(url, data, callback) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
callback(request.responseText);
}
};
request.open('POST', url);
request.send(data);
}
window.onbeforeunload = function() {
startRecording.disabled = false;
};
function getRandomString() {
if (window.crypto) {
var a = window.crypto.getRandomValues(new Uint32Array(3)),
token = '';
for (var i = 0, l = a.length; i < l; i++) token += a[i].toString(36);
return token;
} else {
return (Math.random() * new Date().getTime()).toString(36).replace( /\./g , '');
}
}
</script>
</body>
</html>
```
=
##### `handlers.js`
#### How to fix audio/video sync issues on chrome?
```javascript
var config = require('./config'),
fs = require('fs'),
sys = require('sys'),
exec = require('child_process').exec;
recordAudio = RecordRTC( stream, {
onAudioProcessStarted: function( ) {
recordVideo.startRecording();
}
});
function home(response) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
response.end(fs.readFileSync('./static/index.html'));
}
recordVideo = RecordRTC(stream, {
type: 'video'
});
// this function uploads files
recordAudio.startRecording();
```
function upload(response, postData) {
var files = JSON.parse(postData);
`onAudioProcessStarted` fixes shared/exclusive audio gap (a little bit). Because shared audio sometimes causes 100ms delay...
sometime about 400-to-500 ms delay.
Delay depends upon number of applications concurrently requesting same audio devices and CPU/Memory available.
Shared mode is the only mode currently available on 90% of windows systems especially on windows 7.
// writing audio file to disk
_upload(response, files.audio);
=
if (files.isFirefox) {
response.statusCode = 200;
response.writeHead(200, { 'Content-Type': 'application/json' });
response.end(files.audio.name);
}
#### Want to recording only audio?
if (!files.isFirefox) {
// writing video file to disk
_upload(response, files.video);
```
// line 91:
merge(response, files);
}
}
// this function merges wav/webm files
function merge(response, files) {
// detect the current operating system
var isWin = !!process.platform.match( /^win/ );
if (isWin) {
ifWin(response, files);
} else {
ifMac(response, files);
}
}
function _upload(response, file) {
var fileRootName = file.name.split('.').shift(),
fileExtension = file.name.split('.').pop(),
filePathBase = config.upload_dir + '/',
fileRootNameWithBase = filePathBase + fileRootName,
filePath = fileRootNameWithBase + '.' + fileExtension,
fileID = 2,
fileBuffer;
while (fs.existsSync(filePath)) {
filePath = fileRootNameWithBase + '(' + fileID + ').' + fileExtension;
fileID += 1;
}
file.contents = file.contents.split(',').pop();
fileBuffer = new Buffer(file.contents, "base64");
fs.writeFileSync(filePath, fileBuffer);
}
function serveStatic(response, pathname) {
var extension = pathname.split('.').pop(),
extensionTypes = {
'js': 'application/javascript',
'webm': 'video/webm',
'gif': 'image/gif'
};
response.writeHead(200, {
'Content-Type': extensionTypes[extension]
});
if (extensionTypes[extension] == 'video/webm')
response.end(fs.readFileSync('.' + pathname));
else
response.end(fs.readFileSync('./static' + pathname));
}
function ifWin(response, files) {
// following command tries to merge wav/webm files using ffmpeg
var merger = __dirname + '\\merger.bat';
var audioFile = __dirname + '\\uploads\\' + files.audio.name;
var videoFile = __dirname + '\\uploads\\' + files.video.name;
var mergedFile = __dirname + '\\uploads\\' + files.audio.name.split('.')[0] + '-merged.webm';
// if a "directory" has space in its name; below command will fail
// e.g. "c:\\dir name\\uploads" will fail.
// it must be like this: "c:\\dir-name\\uploads"
var command = merger + ', ' + audioFile + " " + videoFile + " " + mergedFile + '';
exec(command, function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: ' + error.code);
console.log('Signal received: ' + error.signal);
} else {
response.statusCode = 200;
response.writeHead(200, {
'Content-Type': 'application/json'
});
response.end(files.audio.name.split('.')[0] + '-merged.webm');
fs.unlink(audioFile);
fs.unlink(videoFile);
}
});
}
function ifMac(response, files) {
// its probably *nix, assume ffmpeg is available
var audioFile = __dirname + '/uploads/' + files.audio.name;
var videoFile = __dirname + '/uploads/' + files.video.name;
var mergedFile = __dirname + '/uploads/' + files.audio.name.split('.')[0] + '-merged.webm';
var util = require('util'),
exec = require('child_process').exec;
//child_process = require('child_process');
var command = "ffmpeg -i " + audioFile + " -itsoffset -00:00:01 -i " + videoFile + " -map 0:0 -map 1:0 " + mergedFile;
exec(command, function (error, stdout, stderr) {
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
if (error) {
console.log('exec error: ' + error);
response.statusCode = 404;
response.end();
} else {
response.statusCode = 200;
response.writeHead(200, {
'Content-Type': 'application/json'
});
response.end(files.audio.name.split('.')[0] + '-merged.webm');
// removing audio/video files
fs.unlink(audioFile);
fs.unlink(videoFile);
}
});
}
exports.home = home;
exports.upload = upload;
exports.serveStatic = serveStatic;
// Firefox can record both audio/video in single webm container
// Don't need to create multiple instances of the RecordRTC for Firefox
// You can even use below property to force recording only audio blob on chrome
var isRecordOnlyAudio = true;
```

@@ -446,0 +188,0 @@

@@ -18,3 +18,6 @@ // Muaz Khan - www.MuazKhan.com

css: 'css',
webm: 'webm'
webm: 'webm',
mp4: 'mp4',
wav: 'wav',
ogg: 'ogg'
};

@@ -21,0 +24,0 @@

@@ -0,0 +0,0 @@ // Muaz Khan - www.MuazKhan.com

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc