2
0

srs_publisher_flash.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>SRS</title>
  5. <meta charset="utf-8">
  6. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
  7. <style>
  8. body{
  9. padding-top: 55px;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <img src='https://ossrs.net/gif/v1/sls.gif?site=ossrs.net&path=/player/srspublisher'/>
  15. <div class="navbar navbar-fixed-top">
  16. <div class="navbar-inner">
  17. <div class="container">
  18. <a id="srs_index" class="brand" href="#">SRS</a>
  19. <div class="nav-collapse collapse">
  20. <ul class="nav">
  21. <li><a id="nav_srs_player" href="srs_player.html">SRS播放器</a></li>
  22. </ul>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="container">
  28. <div name="detect_flash">
  29. <div id="main_flash_alert" class="alert alert-danger fade in hide">
  30. <button type="button" class="close" data-dismiss="alert">×</button>
  31. <strong><p>Usage:</p></strong>
  32. <p>
  33. 请点击下面的图标,启用Flash
  34. </p>
  35. <p>
  36. 若没有见到这个图标,Chrome浏览器请打开
  37. <span class="text-info">chrome://settings/content/flash</span> 并修改为"Ask first"。
  38. </p>
  39. </div>
  40. <div id="main_flash_hdr" class="hide">
  41. </div>
  42. </div>
  43. <div id="main_content" class="hide">
  44. <div class="alert alert-danger fade in">
  45. <button type="button" class="close" data-dismiss="alert">×</button>
  46. <strong><span>Remark:</span></strong>
  47. <span>Flash推流只支持H.264+Speex,音频不支持AAC,所以无法输出HLS</span>
  48. </div>
  49. <div class="alert alert-info fade in" id="txt_log">
  50. <button type="button" class="close" data-dismiss="alert">×</button>
  51. <strong><span id="txt_log_title">Usage:</span></strong>
  52. <span id="txt_log_msg">设置编码参数,点“发布视频”,允许Flash访问摄像头即可推流</span>
  53. </div>
  54. <div class="control-group">
  55. <div class="form-inline">
  56. <button class="btn" id="btn_video_settings">视频编码配置</button>
  57. <button class="btn" id="btn_audio_settings">音频编码配置</button>
  58. </div>
  59. </div>
  60. <div class="control-group">
  61. <div class="form-inline">
  62. 发布地址:
  63. <input type="text" id="txt_url" class="input-xxlarge" value=""></input>
  64. <button class="btn btn-primary" id="btn_publish">发布视频</button>
  65. <label class="checkbox">
  66. <input type="checkbox" id="cb_preview" checked>预览
  67. </label>
  68. <a id="txt_play_realtime" class="input-xxlarge" href="#">RTMP播放地址(请发布视频)</a>
  69. </div>
  70. </div>
  71. <div id="video_modal" class="modal hide fade">
  72. <div class="modal-header">
  73. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  74. <h3>视频编码</h3>
  75. </div>
  76. <div class="modal-body">
  77. <div class="form-horizontal">
  78. <div class="control-group">
  79. <label class="control-label" for="sl_cameras">
  80. 摄像头
  81. <a id="sl_cameras_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  82. <img src="img/tooltip.png"/>
  83. </a>
  84. </label>
  85. <div class="controls">
  86. <select class="span4" id="sl_cameras"></select>
  87. </div>
  88. </div>
  89. <div class="control-group">
  90. <label class="control-label" for="sl_vcodec">
  91. Codec
  92. <a id="sl_cameras_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  93. <img src="img/tooltip.png"/>
  94. </a>
  95. </label>
  96. <div class="controls">
  97. <select class="span2" id="sl_vcodec"></select>
  98. </div>
  99. </div>
  100. <div class="control-group">
  101. <label class="control-label" for="sl_profile">
  102. Profile
  103. <a id="sl_profile_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  104. <img src="img/tooltip.png"/>
  105. </a>
  106. </label>
  107. <div class="controls">
  108. <select class="span2" id="sl_profile"></select>
  109. </div>
  110. </div>
  111. <div class="control-group">
  112. <label class="control-label" for="sl_level">
  113. Level
  114. <a id="sl_level_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  115. <img src="img/tooltip.png"/>
  116. </a>
  117. </label>
  118. <div class="controls">
  119. <select class="span2" id="sl_level"></select>
  120. </div>
  121. </div>
  122. <div class="control-group">
  123. <label class="control-label" for="sl_gop">
  124. GOP
  125. <a id="sl_gop_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  126. <img src="img/tooltip.png"/>
  127. </a>
  128. </label>
  129. <div class="controls">
  130. <select class="span2" id="sl_gop"></select>
  131. </div>
  132. </div>
  133. <div class="control-group">
  134. <label class="control-label" for="sl_size">
  135. 尺寸
  136. <a id="sl_size_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  137. <img src="img/tooltip.png"/>
  138. </a>
  139. </label>
  140. <div class="controls">
  141. <select class="span2" id="sl_size"></select>
  142. </div>
  143. </div>
  144. <div class="control-group">
  145. <label class="control-label" for="sl_fps">
  146. 帧率
  147. <a id="sl_fps_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  148. <img src="img/tooltip.png"/>
  149. </a>
  150. </label>
  151. <div class="controls">
  152. <select class="span2" id="sl_fps"></select>
  153. </div>
  154. </div>
  155. <div class="control-group">
  156. <label class="control-label" for="sl_bitrate">
  157. 码率
  158. <a id="sl_bitrate_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  159. <img src="img/tooltip.png"/>
  160. </a>
  161. </label>
  162. <div class="controls">
  163. <select class="span2" id="sl_bitrate"></select>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. <div class="modal-footer">
  169. <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">设置</button>
  170. </div>
  171. </div>
  172. <div id="audio_modal" class="modal hide fade">
  173. <div class="modal-header">
  174. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  175. <h3>音频编码</h3>
  176. </div>
  177. <div class="modal-body">
  178. <div class="form-horizontal">
  179. <div class="control-group">
  180. <label class="control-label" for="sl_microphones">
  181. 麦克风
  182. <a id="worker_id_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  183. <img src="img/tooltip.png"/>
  184. </a>
  185. </label>
  186. <div class="controls">
  187. <select class="span4" id="sl_microphones"></select>
  188. </div>
  189. </div>
  190. <div class="control-group">
  191. <label class="control-label" for="sl_acodec">
  192. 编码
  193. <a id="sl_acodec_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
  194. <img src="img/tooltip.png"/>
  195. </a>
  196. </label>
  197. <div class="controls">
  198. <select class="span2" id="sl_acodec"></select>
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. <div class="modal-footer">
  204. <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">设置</button>
  205. </div>
  206. </div>
  207. <div class="container">
  208. <div class="row-fluid">
  209. <div class="span6">
  210. <div class="accordion-group">
  211. <div class="accordion-heading">
  212. <span class="accordion-toggle">
  213. <strong>本地摄像头</strong>
  214. </span>
  215. </div>
  216. <div class="accordion-body collapse in">
  217. <div class="accordion-inner">
  218. <div id="local_publisher"></div>
  219. </div>
  220. </div>
  221. </div>
  222. </div>
  223. <div class="span6">
  224. <div class="accordion-group">
  225. <div class="accordion-heading">
  226. <span class="accordion-toggle">
  227. <strong>远程服务器</strong>
  228. <a id="low_latecy_tips" href="#" data-toggle="tooltip" data-placement="top" title="">
  229. 低延时<img src="img/tooltip.png"/>
  230. </a>
  231. <a id="realtime_player_url" href="#" data-toggle="tooltip" data-placement="top" title="">
  232. 播放地址<img src="img/tooltip.png"/>
  233. </a>
  234. </span>
  235. </div>
  236. <div class="accordion-body collapse in">
  237. <div class="accordion-inner">
  238. <div id="realtime_player"></div>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. </div>
  246. <footer>
  247. <p></p>
  248. <p><a href="https://github.com/ossrs/srs">SRS Team &copy; 2013</a></p>
  249. </footer>
  250. </div>
  251. </body>
  252. <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
  253. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  254. <script type="text/javascript" src="js/swfobject.js"></script>
  255. <script type="text/javascript" src="js/json2.js"></script>
  256. <script type="text/javascript" src="js/srs.page.js"></script>
  257. <script type="text/javascript" src="js/srs.log.js"></script>
  258. <script type="text/javascript" src="js/srs.player.js"></script>
  259. <script type="text/javascript" src="js/srs.publisher.js"></script>
  260. <script type="text/javascript" src="js/srs.utility.js"></script>
  261. <script type="text/javascript" src="js/winlin.utility.js"></script>
  262. <script type="text/javascript">
  263. var __on_flash_ready = null;
  264. $(function(){
  265. // 探测Flash是否正常启用。
  266. $('#main_flash_hdr').html(
  267. '\
  268. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="100%"> \
  269. <param name="movie" value="srs_player/release/srs_player.swf"> \
  270. <param name="quality" value="autohigh"> \
  271. <param name="swliveconnect" value="true"> \
  272. <param name="allowScriptAccess" value="always"> \
  273. <param name="bgcolor" value="#0"> \
  274. <param name="allowFullScreen" value="true"> \
  275. <param name="wmode" value="opaque"> \
  276. <param name="FlashVars" value="log=1"> \
  277. <param name="flashvars" value="id=1&on_player_ready=__on_flash_ready"> \
  278. <embed src="srs_player/release/srs_player.swf" width="100%" height="100%" \
  279. quality="autohigh" bgcolor="#0" align="middle" allowfullscreen="true" allowscriptaccess="always" \
  280. type="application/x-shockwave-flash" swliveconnect="true" wmode="opaque" \
  281. flashvars="id=1&on_player_ready=__on_flash_ready" \
  282. pluginspage="http://www.macromedia.com/go/getflashplayer"> \
  283. </object> \
  284. '
  285. );
  286. $('#main_flash_hdr').show();
  287. var showFlashHdr = setTimeout(function(){
  288. $('#main_flash_alert').show();
  289. }, 300);
  290. __on_flash_ready = function (id) {
  291. clearTimeout(showFlashHdr);
  292. $('#main_flash_alert').hide();
  293. $('#main_flash_hdr').hide();
  294. $('#main_content').show();
  295. autoLoadPage();
  296. };
  297. });
  298. </script>
  299. <script type="text/javascript">
  300. var srs_publisher = null;
  301. var realtime_player = null;
  302. var query = parse_query_string();
  303. var autoLoadPage = function() {
  304. // get the vhost and port to set the default url.
  305. // url set to: http://localhost:8080/live/livestream.flv
  306. srs_init_flv("#txt_url", null);
  307. if (query.agent == "true") {
  308. document.write(navigator.userAgent);
  309. return;
  310. }
  311. $("#btn_video_settings").click(function(){
  312. $("#video_modal").modal({show:true});
  313. });
  314. $("#btn_audio_settings").click(function(){
  315. $("#audio_modal").modal({show:true});
  316. });
  317. $("#low_latecy_tips").tooltip({
  318. title: "服务器不转码直接转发FLASH编码器的流,所以延迟比支持HLS的流要低很多"
  319. });
  320. $("#realtime_player_url").tooltip({
  321. title: "右键复制RTMP地址"
  322. });
  323. $("#btn_publish").click(on_user_publish);
  324. // for publish, we use randome stream name.
  325. $("#txt_url").val($("#txt_url").val() + "." + new Date().getTime());
  326. // start the publisher.
  327. srs_publisher = new SrsPublisher("local_publisher", 430, 185);
  328. srs_publisher.on_publisher_ready = function(cameras, microphones) {
  329. srs_publisher_initialize_page(
  330. cameras, microphones,
  331. "#sl_cameras", "#sl_microphones",
  332. "#sl_vcodec", "#sl_profile", "#sl_level", "#sl_gop", "#sl_size",
  333. "#sl_fps", "#sl_bitrate",
  334. "#sl_acodec"
  335. );
  336. };
  337. srs_publisher.on_publisher_error = function(code, desc) {
  338. if (!on_publish_stop()) {
  339. return;
  340. }
  341. error(code, desc + "请重试。");
  342. };
  343. srs_publisher.on_publisher_warn = function(code, desc) {
  344. warn(code, desc);
  345. };
  346. srs_publisher.start();
  347. // if no play specified, donot show the player, for debug the publisher.
  348. if (query.no_play != "true") {
  349. // start the realtime player.
  350. realtime_player = new SrsPlayer("realtime_player", 430, 185);
  351. realtime_player.on_player_ready = function() {
  352. this.set_bt(0.8);
  353. };
  354. realtime_player.on_player_metadata = function(metadata) {
  355. this.set_dar(0, 0);
  356. this.set_fs("screen", 100);
  357. }
  358. realtime_player.start();
  359. }
  360. };
  361. function on_publish_stop() {
  362. if (!srs_can_republish()) {
  363. $("#btn_join").attr("disabled", true);
  364. error(0, "您使用的浏览器很弱,请关闭页面后重新打开页面(刷新也不管用)。<br/>推荐使用Chrome浏览器,支持重试");
  365. srs_log_disabled = true;
  366. return false;
  367. }
  368. return true;
  369. }
  370. function update_play_url() {
  371. var url = $("#txt_url").val();
  372. var ret = srs_parse_rtmp_url(url);
  373. var remote_url = "rtmp://" + ret.server + ":" + ret.port + "/" + ret.app + "/" + ret.stream + '?vhost=' + ret.vhost;
  374. $("#realtime_player_url").attr("href", url).attr("target", "_blank");
  375. var srs_player_rt_url = "http://" + query.host + query.dir + "/srs_player.html?";
  376. srs_player_rt_url += "vhost=" + ret.vhost + "&port=" + ret.port + "&app=" + ret.app + "&stream=" + ret.stream;
  377. srs_player_rt_url += "&autostart=true";
  378. $("#txt_play_realtime").text("RTMP播放地址").attr("href", srs_player_rt_url).attr("target", "_blank");
  379. }
  380. function on_user_publish() {
  381. if ($("#btn_publish").text() == "停止发布") {
  382. srs_publisher.stop();
  383. $("#btn_publish").text("发布视频");
  384. if (!on_publish_stop()) {
  385. return;
  386. }
  387. return;
  388. }
  389. $("#btn_publish").text("停止发布");
  390. update_play_url();
  391. var url = $("#txt_url").val();
  392. var vcodec = {};
  393. var acodec = {};
  394. srs_publiser_get_codec(
  395. vcodec, acodec,
  396. "#sl_cameras", "#sl_microphones",
  397. "#sl_vcodec", "#sl_profile", "#sl_level", "#sl_gop", "#sl_size",
  398. "#sl_fps", "#sl_bitrate",
  399. "#sl_acodec"
  400. );
  401. info("开始推流到服务器");
  402. srs_publisher.publish(url, vcodec, acodec);
  403. if (!$("#cb_preview").is(":checked")) {
  404. return;
  405. }
  406. if (realtime_player) {
  407. // directly play the url for the realtime player.
  408. realtime_player.stop();
  409. realtime_player.play(url);
  410. }
  411. }
  412. </script>
  413. </html>