stream.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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, verbose: boolean, done: (err: Error) => void)
  11. {
  12. let cp;
  13. let cmd;
  14. if (mode === 'RTMP')
  15. {
  16. cmd = command('rtmpdump') + ' ' +
  17. '-r "' + rtmpUrl + '" ' +
  18. '-y "' + rtmpInputPath + '" ' +
  19. '-W "' + swfUrl + '" ' +
  20. '-o "' + filePath + fileExt + '"';
  21. }
  22. else if (mode === 'HLS')
  23. {
  24. cmd = command('ffmpeg') + ' ' +
  25. '-y -xerror ' +
  26. '-i "' + rtmpInputPath + '" ' +
  27. '-c copy -bsf:a aac_adtstoasc ' +
  28. '"' + filePath + '.mp4"';
  29. }
  30. else
  31. {
  32. log.error('No such mode: ' + mode);
  33. }
  34. cp = childProcess.exec(cmd,
  35. {
  36. maxBuffer: Infinity,
  37. }, done);
  38. if (verbose === true)
  39. {
  40. cp.stdin.pipe(process.stdin);
  41. cp.stdout.pipe(process.stdout);
  42. cp.stderr.pipe(process.stderr);
  43. }
  44. }
  45. /**
  46. * Determines the command for the operating system.
  47. */
  48. function command(exe: string): string
  49. {
  50. if (os.platform() !== 'win32')
  51. {
  52. return exe;
  53. }
  54. return '"' + path.join(__dirname, '../../bin/' + exe + '.exe') + '"';
  55. }