stream.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. import childProcess = require('child_process');
  3. import path = require('path');
  4. import os = require('os');
  5. import log = require('../log');
  6. /**
  7. * Streams the video to disk.
  8. */
  9. export default function(rtmpUrl: string, rtmpInputPath: string, swfUrl: string, filePath: string, fileExt: string, mode: string, done: (err: Error) => void) {
  10. if (mode == "RTMP")
  11. {
  12. childProcess.exec(command("rtmpdump") + ' ' +
  13. '-r "' + rtmpUrl + '" ' +
  14. '-y "' + rtmpInputPath + '" ' +
  15. '-W "' + swfUrl + '" ' +
  16. '-o "' + filePath + fileExt + '"', {
  17. maxBuffer: Infinity
  18. }, done);
  19. }
  20. else if (mode == "HLS")
  21. {
  22. //log.debug("Experimental FFMPEG, MAY FAIL!!!");
  23. var cmd=command("ffmpeg") + ' ' +
  24. '-i "' + rtmpInputPath + '" ' +
  25. '-c copy -bsf:a aac_adtstoasc ' +
  26. '"' + filePath + '.mp4"';
  27. childProcess.exec(cmd, {
  28. maxBuffer: Infinity
  29. }, done);
  30. }
  31. else
  32. {
  33. log.error("No such mode: " + mode);
  34. }
  35. }
  36. /**
  37. * Determines the command for the operating system.
  38. */
  39. function command(exe: string): string {
  40. if (os.platform() !== 'win32') return exe;
  41. return '"' + path.join(__dirname, '../../bin/' + exe + '.exe') + '"';
  42. }