stream.ts 1.1 KB

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