项目作者: chxj1992

项目描述 :
浏览器RTMP推流SDK (A javascript rtmp streamer library)
高级语言: ActionScript
项目地址: git://github.com/chxj1992/rtmp-streamer.git
创建时间: 2016-05-24T03:24:52Z
项目社区:https://github.com/chxj1992/rtmp-streamer

开源协议:Do What The F*ck You Want To Public License

下载


rtmp-streamer npm version

WTFPL

NPM

浏览器中通过内嵌swf推rtmp流的javascript库

Demo

可在任何http容器中加载项目目录来运行demo

http-server:

  1. $ http-server -p 8888

PHP build-in web server:

  1. $ php -S 0.0.0.0:8888

访问 http://localhost:8888/demo

screenshot

Install

  1. $ npm install rtmp-streamer

OR

  1. $ bower install rtmp-streamer

Tutorial

rtmp-streamer 遵循AMD规范,可通过require.js等方式加载, 另外, 请确保在页面中引入了RtmpStreamer.swf, 否则rtmp-streamer将无法正确载入。

  1. <object>
  2. <embed id="rtmp-streamer" src="../RtmpStreamer.swf" bgcolor="#999999" quality="high"
  3. width="320" height="240" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>
  4. </object>
  1. require(["rtmp-streamer"], function (RtmpStreamer) {
  2. var streamer = new RtmpStreamer(document.getElementById('rtmp-streamer'));
  3. streamer.publish(url, name);
  4. });

Document

  1. /**
  2. * Push video to RTMP stream from local camera.
  3. *
  4. * @param url - The RTMP stream URL
  5. * @param name - The RTMP stream name
  6. */
  7. function publish(url, name);
  8. /**
  9. * Pull video from RTMP stream.
  10. *
  11. * @param url - The RTMP stream URL
  12. * @param name - The RTMP stream name
  13. */
  14. function play(url, name);
  15. /**
  16. * Disconnect from RTMP stream
  17. */
  18. function disconnect();
  19. /**
  20. * Set the screen width and height.
  21. *
  22. * @param width - The screen width (pixels). The default value is 320.
  23. * @param height - The screen height (pixels). The default value is 240.
  24. */
  25. function setScreenSize(width, height);
  26. /**
  27. * Set the screen position.
  28. *
  29. * @param x - The screen horizontal position (pixels). The default value is 0.
  30. * @param y - The screen vertical position (pixels). The default value is 0.
  31. */
  32. function setScreenPosition(x, y);
  33. /**
  34. * Set the camera mode.
  35. *
  36. * @param width - The requested capture width (pixels). The default value is 640.
  37. * @param height - The requested capture height (pixels). The default value is 480.
  38. * @param fps - The requested capture frame rate, in frames per second. The default value is 15.
  39. */
  40. function setCamMode(width, height, fps);
  41. /**
  42. * Set the camera frame interval.
  43. *
  44. * @param frameInterval - The number of video frames transmitted in full (called keyframes) instead of being interpolated by the video compression algorithm.
  45. * The allowed values are 1 through 300.
  46. * The default value is 15, which means that every 15th frame is a keyframe. A value of 1 means that every frame is a keyframe.
  47. */
  48. function setCamFrameInterval(frameInterval);
  49. /**
  50. * Set the camera quality.
  51. *
  52. * @param bandwidth - Specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second (bps).
  53. * To specify that the video can use as much bandwidth as needed to maintain the value of quality, pass 0 for bandwidth.
  54. * The default value is 200000.
  55. * @param quality - An integer that specifies the required level of picture quality, as determined by the amount of compression
  56. * being applied to each video frame. Acceptable values range from 1 (lowest quality, maximum compression) to 100
  57. * (highest quality, no compression). To specify that picture quality can vary as needed to avoid exceeding bandwidth, pass 0 for quality.
  58. * The default value is 90.
  59. */
  60. function setCamQuality(bandwidth, quality);
  61. /**
  62. * Set the microphone quality.
  63. *
  64. * @param quality - The encoded speech quality when using the Speex codec. Possible values are from 0 to 10.
  65. * Higher numbers represent higher quality but require more bandwidth, as shown in the following table.
  66. * The bit rate values that are listed represent net bit rates and do not include packetization overhead.
  67. * ------------------------------------------
  68. * Quality value | Required bit rate (kbps)
  69. *-------------------------------------------
  70. * 0 | 3.95
  71. * 1 | 5.75
  72. * 2 | 7.75
  73. * 3 | 9.80
  74. * 4 | 12.8
  75. * 5 | 16.8
  76. * 6 | 20.6
  77. * 7 | 23.8
  78. * 8 | 27.8
  79. * 9 | 34.2
  80. * 10 | 42.2
  81. *-------------------------------------------
  82. * The default value is 9.
  83. */
  84. function setMicQuality(quality);
  85. /**
  86. * Set the microphone rate.
  87. *
  88. * @param rate - The rate at which the microphone is capturing sound, in kHz. Acceptable values are 5, 8, 11, 22, and 44.
  89. * The default value is 44.
  90. */
  91. function setMicRate(rate);

快速搭建一个RTMP服务器?试试Wowza(https://www.wowza.com/free-trial)

Install & Configuration

wowza

采用直播云服务

七牛云为例:

设置参数的方式和用OBS等工具推流时的方式类似, 地址为直播云的空间名, 数据流名称为直播流的名称加鉴权参数:

在七牛的直播云管理后台中预览推流视频: