Skip to content

Instantly share code, notes, and snippets.

@jlank
Created June 21, 2012 02:40
Show Gist options
  • Save jlank/2963507 to your computer and use it in GitHub Desktop.
Save jlank/2963507 to your computer and use it in GitHub Desktop.
Video.prototype.slowDown = function (options, input, cb) {
var self = this,
audio = fs.createWriteStream('/tmp/' + uuid() + '.wav'),
video = fs.createWriteStream('/tmp/' + uuid() + '.mov'),
streamed = {},
run_proc = null;
input.on('data', function (data) {
audio.write(data);
video.write(data);
});
input.on('end', function () {
fs.close(audio.fd, function (err, res) {
self.isolateSound(fs.createReadStream(audio.path), function (err, res) {
self.slowDownAudio(options, res, function (err, res) {
if (err) {
return cb(err, null);
}
else {
streamed['audio'] = res;
if (streamed.video !== undefined && streamed.audio !== undefined) {
console.log(streamed);
console.log('+++++');
self.mergeStreams(streamed.audio, streamed.video, cb);
}
}
});
});
});
fs.close(video.fd, function (err, res) {
self.slowDownVideo(options, fs.createReadStream(video.path), function (err, res) {
if (err) {
return cb(err, null);
}
else {
streamed['video'] = res;
if (streamed.video !== undefined && streamed.audio !== undefined) {
console.log(streamed);
console.log('-----');
self.mergeStreams(streamed.audio, streamed.video, cb);
}
}
});
});
});
};
// will output
node test/video.js
{ video:
{ path: '/tmp/5A7D5DE9-6534-4BAD-A314-C99B03B4621D.mov',
fd: 6,
readable: false,
paused: false,
flags: 'r',
mode: 438,
bufferSize: 65536,
reading: false },
audio:
{ path: '/tmp/993F0136-1D70-4BCB-852F-FCD30B672CD9.wav',
fd: null,
readable: true,
paused: false,
flags: 'r',
mode: 438,
bufferSize: 65536 } }
+++++
(this is logged from within mergeStreams)
{ path: '/tmp/5A7D5DE9-6534-4BAD-A314-C99B03B4621D.mov',
fd: 6,
readable: false,
paused: false,
flags: 'r',
mode: 438,
bufferSize: 65536,
reading: false }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment