stream.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. maxBuffer: Infinity,
  30. }, done);
  31. }
  32. else
  33. {
  34. log.error('No such mode: ' + mode);
  35. }
  36. }
  37. /**
  38. * Determines the command for the operating system.
  39. */
  40. function command(exe: string): string
  41. {
  42. if (os.platform() !== 'win32')
  43. {
  44. return exe;
  45. }
  46. return '"' + path.join(__dirname, '../../bin/' + exe + '.exe') + '"';
  47. }