stream.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. import childProcess = require('child_process');
  3. import os = require('os');
  4. import path = require('path');
  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,
  10. fileExt: string, mode: string, done: (err: Error) => void)
  11. {
  12. if (mode === 'RTMP')
  13. {
  14. childProcess.exec(command('rtmpdump') + ' ' +
  15. '-r "' + rtmpUrl + '" ' +
  16. '-y "' + rtmpInputPath + '" ' +
  17. '-W "' + swfUrl + '" ' +
  18. '-o "' + filePath + fileExt + '"', {
  19. maxBuffer: Infinity,
  20. }, done);
  21. }
  22. else if (mode === 'HLS')
  23. {
  24. const cmd = command('ffmpeg') + ' ' +
  25. '-i "' + rtmpInputPath + '" ' +
  26. '-c copy -bsf:a aac_adtstoasc ' +
  27. '"' + filePath + '.mp4"';
  28. childProcess.exec(cmd,
  29. {
  30. maxBuffer: Infinity,
  31. }, done);
  32. }
  33. else
  34. {
  35. log.error('No such mode: ' + mode);
  36. }
  37. }
  38. /**
  39. * Determines the command for the operating system.
  40. */
  41. function command(exe: string): string
  42. {
  43. if (os.platform() !== 'win32')
  44. {
  45. return exe;
  46. }
  47. return '"' + path.join(__dirname, '../../bin/' + exe + '.exe') + '"';
  48. }