{"id":7902,"date":"2020-02-28T16:47:11","date_gmt":"2020-02-28T08:47:11","guid":{"rendered":"https:\/\/sdeno.com\/?p=7902"},"modified":"2020-02-28T16:52:37","modified_gmt":"2020-02-28T08:52:37","slug":"hls%e5%8d%8f%e8%ae%ae%e5%9c%a8nginx%e7%9a%84%e9%85%8d%e7%bd%ae%e8%af%a6%e7%bb%86%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=7902","title":{"rendered":"HLS\u534f\u8bae\u5728nginx\u7684\u914d\u7f6e\u8be6\u7ec6\u8bf4\u660e"},"content":{"rendered":"<h6 id=\"h1_1\">\u4e00\u3001HLS\u7b80\u4ecb<\/h6>\n<p>HLS\uff08HTTP Live Streaming\uff09 \u662fAppale\u516c\u53f8\u57282009\u5e74\u53d1\u5e03\u7684\uff0c\u53ef\u4ee5\u901a\u8fc7\u666e\u901a\u7684web\u670d\u52a1\u5668\u8fdb\u884c\u5206\u53d1\u7684\u65b0\u578b\u6d41\u5a92\u4f53\u534f\u8bae\u3002<\/p>\n<p>HLS\u534f\u8bae\u6587\u4ef6\uff1ahttp:\/\/tools.ietf.org\/html\/draft-pantos-http-live-streaming-07<\/p>\n<p>HLS\u63d0\u4f9b\u4e00\u4e2am3u8\u5217\u8868\uff0c\u64ad\u653e\u5730\u5740\u50cf\u8fd9\u6837\uff1ahttp:\/\/IP[port]\/[app]\/live.m3u8\uff0c\u5176\u5b9em3u8\u662f\u4e00\u4e2ats\u7684list\uff0c\u4f46\u662f\u5728\u8fd9\u4e2alist\u4e2d\u8981\u9700\u8981\u5b9a\u4e49\u4e00\u4e9b\u5173\u952e\u7684\u53c2\u6570\uff0c\u8fd9\u4e9b\u53c2\u6570\u90fd\u6709\u91cd\u8981\u7684\u610f\u4e49\u3002<\/p>\n<p>\u4e00\u822cHLS\u4e2dts\u5207\u7247\u7684\u89c6\u9891\u7f16\u7801\u4f7f\u7528H264\uff0c\u97f3\u9891\u7f16\u7801\u4f7f\u7528AAC\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h6 id=\"h1_2\">\u4e8c\u3001HLS m3u8\u4ecb\u7ecd<\/h6>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2am3u8\u5217\u8868\u4e2d\u7684\u5185\u5bb9<\/p>\n<p>#EXTM3U<\/p>\n<p>#EXT-X-VERSION:3<\/p>\n<p>#EXT-X-MEDIA-SEQUENCE:64<\/p>\n<p>#EXT-X-TARGETDURATION:12<\/p>\n<p>#EXTINF:11.550<\/p>\n<p>livestream-64.ts<\/p>\n<p>#EXTINF:5.250<\/p>\n<p>livestream-65.ts<\/p>\n<p>#EXTINF:7.700<\/p>\n<p>livestream-66.ts<\/p>\n<p>#EXTINF:6.850<\/p>\n<p>livestream-67.ts<\/p>\n<p>\u6709\u51e0\u4e2a\u5173\u952e\u7684\u53c2\u6570\uff0c\u8fd9\u4e9b\u53c2\u6570\u5728SRS\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u90fd\u6709\u914d\u7f6e\u9879\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>EXT-X-TARGETDURATION\uff1a\u6240\u6709\u5207\u7247\u7684\u6700\u5927\u65f6\u957f\u3002\u6709\u4e9bApple\u8bbe\u5907\u8fd9\u4e2a\u53c2\u6570\u4e0d\u6b63\u786e\u4f1a\u65e0\u6cd5\u64ad\u653e\u3002SRS\u4f1a\u81ea\u52a8\u8ba1\u7b97\u51fats\u6587\u4ef6\u7684\u6700\u5927\u65f6\u957f\uff0c\u7136\u540e\u66f4\u65b0m3u8\u65f6\u4f1a\u81ea\u52a8\u66f4\u65b0\u8fd9\u4e2a\u503c\u3002\u7528\u6237\u4e0d\u5fc5\u81ea\u5df1\u914d\u7f6e\u3002<\/li>\n<li>EXTINF\uff1ats\u5207\u7247\u7684\u5b9e\u9645\u65f6\u957f\uff0cSRS\u63d0\u4f9b\u914d\u7f6e\u9879hls_fragment\uff0c\u4f46\u5b9e\u9645\u4e0a\u7684ts\u65f6\u957f\u8fd8\u53d7gop\u5f71\u54cd\uff0c\u8be6\u89c1\u4e0b\u9762\u914d\u7f6eHLS\u7684\u8bf4\u660e\u3002<\/li>\n<li>ts\u6587\u4ef6\u7684\u6570\u76ee\uff1aSRS\u53ef\u914d\u7f6ehls_window\uff0c\u6307\u5b9am3u8\u4e2d\u4fdd\u5b58\u591a\u5c11\u4e2a\u5207\u7247\uff0cSRS\u4f1a\u81ea\u52a8\u6e05\u7406\u65e7\u7684\u5207\u7247\u3002<\/li>\n<li>livestream-67.ts\uff1aSRS\u4f1a\u81ea\u52a8\u7ef4\u62a4ts\u5207\u7247\u7684\u6587\u4ef6\u540d\uff0c\u5728\u7f16\u7801\u5668\u91cd\u63a8\u4e4b\u540e\uff0c\u8fd9\u4e2a\u7f16\u53f7\u4f1a\u7ee7\u7eed\u589e\u957f\uff0c\u4fdd\u8bc1\u6d41\u7684\u8fde\u7eed\u6027\u3002\u76f4\u5230SRS\u91cd\u542f\uff0c\u8fd9\u4e2a\u7f16\u53f7\u624d\u91cd\u7f6e\u4e3a0\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8b6c\u5982\uff0c\u6bcf\u4e2ats\u5207\u7247\u4e3a10\u79d2\uff0c\u7a97\u53e3\u4e3a60\u79d2\uff0c\u90a3\u4e48m3u8\u4e2d\u4f1a\u4fdd\u5b586\u4e2ats\u5207\u7247\u3002<\/p>\n<p>&nbsp;<\/p>\n<h6 id=\"h1_3\">\u4e09\u3001SRS\u7684HLS\u5de5\u4f5c\u6d41<\/h6>\n<p>RTMP\u7f16\u7801\u5668\u63a8\u6d41\u5230SRS\uff0c\u89c6\u97f3\u9891\u7f16\u7801\u4e3a\uff0c\u89c6\u9891\uff1aH.264 \u97f3\u9891\uff1aAAC\uff0c\u5176\u4ed6\u7f16\u7801\u7684\uff0c\u53ef\u4ee5\u901a\u8fc7SRS\u8fdb\u884c\u76f4\u64ad\u8f6c\u7801\u540e\uff0c\u8f93\u51fa\u5230SRS\u7684\u5176\u4ed6Vhost\u4e2d\uff0c\u7136\u540e\u751f\u6210HLS<\/p>\n<p>\u5982\u679c\u4e0d\u662fH264\/AAC\uff0c\u5219\u505c\u6b62\u8f93\u51faHLS\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h6 id=\"h1_4\">\u56db\u3001SRS\u914d\u7f6e\u751f\u6210HLS<\/h6>\n<p>\u5176\u4ed6\u914d\u7f6e\u67e5\u770bconf\u76ee\u5f55\u4e0b\u7684full.conf<\/p>\n<p>vhost with-hls.srs.com {<\/p>\n<p>hls {<\/p>\n<p><span style=\"color: #800000;\"><em>#\u662f\u5426\u5f00\u542fHLS\uff0con\uff1a\u5f00\u542f off\uff1a\u5173\u95ed\uff0c\u9ed8\u8ba4\u662foff\u00a0<\/em><\/span><\/p>\n<p>enabled \u00a0 \u00a0 \u00a0 \u00a0 on;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u5355\u4f4d\u79d2\uff0c\u6307\u5b9ats\u5207\u7247\u7684\u6700\u5c0f\u957f\u5ea6\u3002\u9ed8\u8ba4\u4e3a10<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#ts\u6587\u4ef6\u957f\u5ea6 =\u00a0max(hls_fragment, gop_size)<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u5982\u679cffmpeg\u4e2d\u6307\u5b9afps\uff08\u5e27\u901f\u7387\uff09\u4e3a20\u5e27\/\u79d2\uff0cgop\u4e3a200\u5e27\uff0c\u90a3\u4e48gop_size=gop\/fps=10\u79d2<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u90a3\u4e48\u5b9e\u9645ts\u7684\u957f\u5ea6\u4e3amax(5,10) =10\u79d2\u3002\u8fd9\u6837\u5b9e\u9645ts\u5207\u7247\u7684\u957f\u5ea6\u5c31\u4e0e\u8bbe\u5b9a\u7684\u4e0d\u540c\u4e86\u3002<\/em><\/span><\/p>\n<p>hls_fragment \u00a0 \u00a05;<\/p>\n<p><em>\u00a0<span style=\"color: #800000;\">#\u500d\u6570\uff0c\u63a7\u5236m3u8\u7684EXT-X-TARGETDURATION\u503c\uff0cEXT-X-TARGETDURATION\uff08\u6574\u6570\uff09\u503c\u6807\u660e\u4e86\u5207\u7247\u7684\u6700\u5927\u65f6\u957f\u3002<\/span><\/em><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#m3u8\u5217\u8868\u6587\u4ef6\u4e2dEXTINF\u7684\u503c\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8eEXT-X-TARGETDURATION\u7684\u503c\u3002<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#EXT-X-TARGETDURATION\u5728m3u8\u5217\u8868\u6587\u4ef6\u4e2d\u5fc5\u987b\u51fa\u73b0\u4e00\u6b21\u3002<\/em><\/span><\/p>\n<p>hls_td_ratio \u00a0 \u00a01.5;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u500d\u6570\u3002\u7eaf\u97f3\u9891\u65f6\uff0c\u5f53ts\u65f6\u957f\u8d85\u8fc7\u914d\u7f6e\u7684ls_fragment\u4e58\u4ee5\u8fd9\u4e2a\u7cfb\u6570\u65f6\u5c31\u5207\u5272\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5f53ls_fragment\u662f10\u79d2\uff0chls_aof_ratio\u662f2.0\u65f6\uff0c\u5bf9\u4e8e\u7eaf\u97f3\u9891\uff0c10s*2.0=20\u79d2\u65f6\u5c31\u5207\u5272ts\u6587\u4ef6\u3002<\/em><\/span><\/p>\n<p>hls_aof_ratio \u00a0 2.0;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u5355\u4f4d\uff1a\u79d2\uff0c\u6307\u5b9aHLS\u7a97\u53e3\u5927\u5c0f\uff0c\u5373m3u8\u4e2dts\u6587\u4ef6\u7684\u65f6\u957f\u4e4b\u548c\uff0c\u8d85\u8fc7\u603b\u65f6\u957f\u540e\uff0c\u4e22\u5f03\u7b2c\u4e00\u4e2am3u8\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5207\u7247\uff0c\u76f4\u5230ts\u7684\u603b\u65f6\u957f\u5728\u8fd9\u4e2a\u914d\u7f6e\u9879\u8303\u56f4\u4e4b\u5185\u3002\u5373SRS\u4fdd\u8bc1\uff1a<\/em><em>hls_window\u7684\u503c\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8em3u8\u5217\u8868\u6587\u4ef6\u4e2d\u6240\u6709ts\u5207\u7247\u65f6\u957f\u7684\u603b\u548c\u3002<\/em><\/span><\/p>\n<p>hls_window \u00a0 \u00a0 \u00a060;<\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #800000;\">\u00a0\u00a0#hls\u9519\u8bef\u7b56\u7565<\/span><br \/>\n<\/em><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0ignore\uff1a\u5f53\u9519\u8bef\u53d1\u751f\u65f6\uff0c\u5ffd\u7565\u9519\u8bef\u5e76\u505c\u6b62\u8f93\u51fahls\uff08\u9ed8\u8ba4\uff09<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0disconnect\uff1a\u5f53\u53d1\u751f\u9519\u8bef\u65f6\uff0c\u65ad\u5f00\u63a8\u6d41\u8fde\u63a5<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0continue\uff1a\u5f53\u53d1\u751f\u9519\u8bef\u65f6\uff0c\u5ffd\u7565\u9519\u8bef\u5e76\u7ee7\u7eed\u8f93\u51fahls<\/em><\/span><\/p>\n<p>hls_on_error \u00a0 \u00a0ignore;<\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #800000;\">#hls\u5b58\u50a8\u65b9\u5f0f<\/span><br \/>\n<\/em><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0disk\uff1a\u628am3u8\/ts\u5199\u5230\u78c1\u76d8\uff08\u9ed8\u8ba4\uff09<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0ram\uff1a\u53d1\u9001m3u8\/ts\u5230\u5185\u5b58\uff0c\u4f46\u662f\u5fc5\u987b\u4f7f\u7528srs\u81ea\u5e26\u7684http server\u8fdb\u884c\u5206\u53d1\u3002<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0both\uff0c disk and ram\u3002<\/em><\/span><\/p>\n<p>hls_storage \u00a0 \u00a0 disk;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u5f53hls\u5199\u5230\u78c1\u76d8\u65f6\uff0c\u6307\u5b9a\u5199\u5165\u7684\u76ee\u5f55\u3002<\/em><em>\u00a0\u00a0<\/em><\/span><\/p>\n<p>hls_path \u00a0 \u00a0 \u00a0 \u00a0.\/objs\/nginx\/html;<\/p>\n<p><em>\u00a0<span style=\"color: #800000;\">#\u751f\u6210hls\u7684m3u8\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff0c\u6709\u4e00\u4e9b\u53d8\u91cf\u53ef\u7528\u4e8e\u751f\u6210m3u8\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff1a<\/span><br \/>\n<\/em><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0[vhost]\uff0c\u539f\u59cb\u6d41\u6765\u7684vhost\uff0c\u6bd4\u5982rtmp:\/\/v.flyfn.com:1935\/live\/livestream,\u5bf9\u5e94\u5230srs\u4e2d\uff0cvhost\u5e94\u662fv.flyfn.com<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0[app], \u6e90rtmp\u6d41\u4e2d\u7684app\uff0c\u5bf9\u5e94\u4e0a\u9762\u7684\u64ad\u653e\u5730\u5740\u4e2d\uff0c\u4e3alive<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a0[stream]\uff0c\u6e90rtmp\u6d41\u4e2d\u7684\u6d41\u540d\u79f0\uff0c\u5bf9\u5e94\u4e0a\u9762\u64ad\u653e\u5730\u5740\u4e2d\uff0c\u4e3alivestream<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#m3u8\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\u4e3a[SRS_Path]\/objs\/nginx\/html\/[app]\/[stream].m3u8<\/em><\/span><\/p>\n<p>hls_m3u8_file \u00a0 [app]\/[stream].m3u8;<\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #800000;\">\u00a0#\u751f\u6210\u7684ts\u6587\u4ef6\u7684\u540d\u79f0\uff0c\u6709\u8bb8\u591a\u7684\u53d8\u91cf\u53ef\u7528\u4e8e\u751f\u6210ts\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff1a<\/span><\/em><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[vhost], the vhost of stream.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[app], the app of stream.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[stream], the stream name of stream.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[2006], replace this const to current year.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[01], replace this const to current month.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[02], replace this const to current date.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[15], replace this const to current hour.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[04], repleace this const to current minute.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[05], repleace this const to current second.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[999], repleace this const to current millisecond.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[timestamp],replace this const to current UNIX timestamp in ms.<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[seq], the sequence number of ts\uff0c\u987a\u5e8f\u53f7\uff0c0,1,2&#8230;n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u751f\u6210\u7684ts\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\uff1a[SRS_Path]\/objs\/nginx\/html\/[app]\/[stream]-[seq].ts<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u4f8b\u5982\uff1a[app]\/[stream]\/[2006][01]\/[02]\/[timestamp].ts\u751f\u6210\u7684ts\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\u662f\uff1a<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#[SRS_Path]\/objs\/nginx\/html\/[app]\/[stream]\/201505\/15\/1431619258.ts<\/em><\/span><\/p>\n<p>hls_ts_file \u00a0 \u00a0 [app]\/[stream]-[seq].ts;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u662f\u5426\u4f7f\u7528floor\u7684\u65b9\u5f0f\u751f\u6210hls ts\u6587\u4ef6\u7684\u8def\u5f84\u3002\u5982\u5b9ehls_ts_floor on; \u4f7f\u7528timestamp\/hls_fragment\u4f5c\u4e3a[timestamp]\u53d8\u91cf\uff0c\u5373[timestamp]=timestamp\/hls_fragment\uff0c\u5e76\u4e14\u4f7f\u7528enahanced\u7b97\u6cd5\u751f\u6210\u4e0b\u4e00\u4e2a\u5207\u7247\u7684\u5dee\u503c\u3002<\/em><\/span><\/p>\n<p>hls_ts_floor \u00a0 \u00a0off;<\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #800000;\">#hls_entry_prefix: TS\u7684base url\u3002\u53ef\u9009\u9ed8\u8ba4\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff1b\u975e\u7a7a\u65f6\u52a0\u5728ts\u524d\u9762\u4f5c\u4e3abase url\u3002<\/span><\/em><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u5bf9\u4e8ets\u5207\u7247\uff1alive\/livestream-0.ts<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u82e5\u914d\u7f6e\u4e3a\uff1ahls_entry_prefix http:\/\/your-server;<\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u5219\u6700\u540e\u7684TS\u7684URL\u662f\uff1ahttp:\/\/your-server\/live\/livestream-0.ts<\/em><\/span><\/p>\n<p>hls_entry_prefix\u00a0<a href=\"http:\/\/your-server%3B\/\" rel=\"nofollow\">http:\/\/your-server;<\/a><\/p>\n<p><span style=\"color: #800000;\"><em>#\u5185\u5b58hls\u7684m3u8\/ts\u6302\u8f7d\u70b9\u3002\u64ad\u653e\u7684\u65f6\u5019\u5230\u8fd9\u4e2a\u8def\u5f84\u4e0b\u627em3u8\u548cts\u6587\u4ef6\u3002\u64ad\u653e\u8def\u5f84\u4e3a\uff1a<a style=\"color: #800000;\" href=\"http:\/\/your-server\/[vhost]\/[app]\/[stream].m3u8\" rel=\"nofollow\">http:\/\/your-server\/[vhost]\/[app]\/[stream].m3u8<\/a><\/em><\/span><\/p>\n<p><span style=\"color: #800000;\"><em>#\u82e5\u8981\u652f\u6301\u5185\u5b58\u5206\u53d1HLS\uff0c\u5373ts\u4e0d\u5199\u78c1\u76d8\u30021\u3001\u9700\u8981\u5f00\u542fSRS\u7684http_server\u30022\u3001\u4fee\u6539 hls_storage ram;<\/em><\/span><\/p>\n<p>hls_mount \u00a0 \u00a0 \u00a0 [vhost]\/[app]\/[stream].m3u8;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u9ed8\u8ba4\u7684\u97f3\u9891\u7f16\u7801\u3002\u5f53\u6d41\u7684\u7f16\u7801\u6539\u53d8\u65f6\uff0c\u4f1a\u66f4\u65b0PMT\/PAT\u4fe1\u606f\uff1b\u9ed8\u8ba4\u662faac\uff0c\u56e0\u6b64\u9ed8\u8ba4\u7684PMT\/PAT\u4fe1\u606f\u662faac\uff1b\u5982\u679c\u6d41\u662fmp3\uff0c\u90a3\u4e48\u53ef\u4ee5\u914d\u7f6e\u8fd9\u4e2a\u53c2\u6570\u4e3amp3\uff0c\u907f\u514dPMT\/PAT\u6539\u53d8\u3002<\/em><\/span><\/p>\n<p>hls_acodec \u00a0 \u00a0 \u00a0aac;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u9ed8\u8ba4\u7684\u89c6\u9891\u7f16\u7801\u3002\u5f53\u6d41\u7684\u7f16\u7801\u6539\u53d8\u65f6\uff0c\u4f1a\u66f4\u65b0PMT\/PAT\u4fe1\u606f\uff1b\u9ed8\u8ba4\u662fh264\u3002\u5982\u679c\u662f\u7eaf\u97f3\u9891HLS\uff0c\u53ef\u4ee5\u914d\u7f6e\u4e3avn\uff0c\u53ef\u4ee5\u51cf\u5c11SRS\u68c0\u6d4b\u7eaf\u97f3\u9891\u7684\u65f6\u95f4\uff0c\u76f4\u63a5\u8fdb\u5165\u7eaf\u97f3\u9891\u6a21\u5f0f\u3002<\/em><\/span><\/p>\n<p>hls_vcodec \u00a0 \u00a0 \u00a0h264;<\/p>\n<p><em>\u00a0<span style=\"color: #800000;\">#\u662f\u5426\u5220\u9664\u8fc7\u671f\u7684ts\u5207\u7247\uff0c\u4e0d\u5728m3u8\u4e2d\u5c31\u662f\u8fc7\u671f\u3002\u53ef\u4ee5\u5173\u95ed\u6e05\u9664ts\u5207\u7247\uff0c\u5b9e\u73b0\u65f6\u79fb\u548c\u5b58\u50a8\uff0c\u4f7f\u7528\u81ea\u5df1\u7684\u5207\u7247\u7ba1\u7406\u7cfb\u7edf\u3002<\/span><\/em><\/p>\n<p>hls_cleanup \u00a0 \u00a0 on;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u4ecenotify\u670d\u52a1\u5668\u8bfb\u53d6\u6570\u636e\u7684\u957f\u5ea6<\/em><\/span><\/p>\n<p>hls_nb_notify \u00a0 64;<\/p>\n<p><span style=\"color: #800000;\"><em>#\u662f\u5426\u6309gop\u5207\u7247\uff0c\u5373\u7b49\u5f85\u5230\u5173\u952e\u5e27\u540e\u5f00\u59cb\u5207\u7247\u3002\u6d4b\u8bd5\u53d1\u73b0OS X\u548candroid\u4e0a\u53ef\u4ee5\u4e0d\u7528\u6309go\u5207\u7247\u3002<\/em><\/span><\/p>\n<p>hls_wait_keyframe \u00a0 \u00a0 \u00a0 on;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h6 id=\"h1_5\">\u4e94\u3001SRS\u4e2d\u5173\u4e8eHLS\u7684Callback<\/h6>\n<p>vhost v.flyfn.com {<\/p>\n<p>http_hooks {<\/p>\n<p><span style=\"color: #993300;\"><em>#\u5f53\u5207\u7247\u751f\u6210\u65f6\uff0c\u56de\u8c03\u8fd9\u513furl\uff0c\u4f7f\u7528POST\u56de\u8c03\u3002<br \/>\n<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u5df2json\u7f16\u7801\u683c\u5f0fPOST\u3002<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# {<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;action&#8221;: &#8220;on_hls&#8221;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;client_id&#8221;: 1985,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;ip&#8221;: &#8220;192.168.1.10&#8221;, &#8220;vhost&#8221;: &#8220;video.test.com&#8221;, &#8220;app&#8221;: &#8220;live&#8221;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;stream&#8221;: &#8220;livestream&#8221;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;duration&#8221;: 9.36, \/\/ in seconds<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;cwd&#8221;: &#8220;\/usr\/local\/srs&#8221;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;file&#8221;: &#8220;.\/objs\/nginx\/html\/live\/livestream\/2015-04-23\/01\/476584165.ts&#8221;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;url&#8221;: &#8220;live\/livestream\/2015-04-23\/01\/476584165.ts&#8221;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;m3u8&#8221;: &#8220;.\/objs\/nginx\/<span style=\"color: #800000;\">html<\/span>\/live\/livestream\/live.m3u8&#8243;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;m3u8_url&#8221;: &#8220;live\/livestream\/live.m3u8&#8221;,<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# \u00a0 \u00a0 &#8220;seq_no&#8221;: 100<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# }<\/em><\/span><\/p>\n<p><em><span style=\"color: #993300;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u4e0b\u9762\u662f\u56de\u8c03\u591a\u4e2a\u5730\u5740<\/span><br \/>\n<\/em><\/p>\n<p>on_hls \u00a0 \u00a0 \u00a0 \u00a0 \u00a0http:\/\/127.0.0.1:8085\/api\/v1\/hls\u00a0<a href=\"http:\/\/localhost:8085\/api\/v1\/hls;\" rel=\"nofollow\">http:\/\/localhost:8085\/api\/v1\/hls;<\/a><\/p>\n<p><span style=\"color: #800000;\"><em>#HLS\u901a\u77e5\uff0c\u5b9e\u73b0CDN\u9884\u5206\u53d1<\/em>\u3002<\/span><\/p>\n<p>on_hls_notify \u00a0\u00a0<a href=\"http:\/\/127.0.0.1:8085\/api\/v1\/hls\/[app]\/[stream][ts_url];\" rel=\"nofollow\">http:\/\/127.0.0.1:8085\/api\/v1\/hls\/[app]\/[stream][ts_url];<\/a><\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><audio style=\"display: none;\" controls=\"controls\"><\/audio><\/p>\n<p><audio style=\"display: none;\" controls=\"controls\"><\/audio><\/p>\n<p><audio style=\"display: none;\" controls=\"controls\"><\/audio><\/p>\n<p><audio style=\"display: none;\" controls=\"controls\"><\/audio><\/p>\n<p><audio style=\"display: none;\" controls=\"controls\"><\/audio><\/p>\n<p><audio style=\"display: none;\" controls=\"controls\"><\/audio><\/p>\n<p><audio style=\"display: none;\" controls=\"controls\"><\/audio><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001HLS\u7b80\u4ecb HLS\uff08HTTP Live Streaming\uff09 \u662fAppale\u516c\u53f8\u57282009\u5e74\u53d1\u5e03\u7684\uff0c\u53ef\u4ee5\u901a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,9],"tags":[],"class_list":["post-7902","post","type-post","status-publish","format-standard","hentry","category-php","category-9"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/7902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7902"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/7902\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}