merge.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var childProcess = require('child_process');
  3. var fs = require('fs');
  4. var path = require('path');
  5. var os = require('os');
  6. /**
  7. * Merges the subtitle and video files into a Matroska Multimedia Container.
  8. * @param {Object} config
  9. * @param {string} rtmpInputPath
  10. * @param {string} filePath
  11. * @param {function(Error)} done
  12. */
  13. module.exports = function(config, rtmpInputPath, filePath, done) {
  14. var subtitlePath = filePath + '.' + config.format;
  15. var videoPath = filePath + path.extname(rtmpInputPath);
  16. childProcess.exec(_command() + ' ' +
  17. '-o "' + filePath + '.mkv" ' +
  18. '"' + videoPath + '" ' +
  19. '"' + subtitlePath + '"', {
  20. maxBuffer: Infinity
  21. }, function(err) {
  22. if (err) return done(err);
  23. fs.unlink(videoPath, function(err) {
  24. if (err) return done(err);
  25. fs.unlink(subtitlePath, done);
  26. });
  27. });
  28. };
  29. /**
  30. * Determines the command for the operating system.
  31. * @private
  32. * @returns {string}
  33. */
  34. function _command() {
  35. if (os.platform() !== 'win32') return 'mkvmerge';
  36. return path.join(__dirname, '../../bin/mkvmerge.exe');
  37. }