Added MKV muxing support

This commit is contained in:
Roel van Uden
2015-01-23 20:38:23 +01:00
parent ed8f7c90f5
commit 256f9cd887
7 changed files with 115 additions and 30 deletions

View File

@@ -1,3 +1,4 @@
module.exports = {
merge: require('./merge'),
stream: require('./stream')
};

39
src/video/merge.js Normal file
View File

@@ -0,0 +1,39 @@
'use strict';
var childProcess = require('child_process');
var fs = require('fs');
var path = require('path');
var os = require('os');
/**
* Merges the subtitle and video files into a Matroska Multimedia Container.
* @param {Object} config
* @param {string} rtmpInputPath
* @param {string} filePath
* @param {function(Error)} done
*/
module.exports = function(config, rtmpInputPath, filePath, done) {
var subtitlePath = filePath + '.' + config.format;
var videoPath = filePath + path.extname(rtmpInputPath);
childProcess.exec(_command() + ' ' +
'-o "' + filePath + '.mkv" ' +
'"' + videoPath + '" ' +
'"' + subtitlePath + '"', {
maxBuffer: Infinity
}, function(err) {
if (err) return done(err);
fs.unlink(videoPath, function(err) {
if (err) return done(err);
fs.unlink(subtitlePath, done);
});
});
};
/**
* Determines the command for the operating system.
* @private
* @returns {string}
*/
function _command() {
if (os.platform() !== 'win32') return 'mkvmerge';
return path.join(__dirname, '../../bin/mkvmerge.exe');
}

View File

@@ -23,6 +23,7 @@ module.exports = function(rtmpUrl, rtmpInputPath, swfUrl, filePath, done) {
/**
* Determines the command for the operating system.
* @private
* @returns {string}
*/
function _command() {