<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bernie Yu &#187; 直播</title>
	<atom:link href="http://bernieyu.com/tag/%e7%9b%b4%e6%92%ad/feed/" rel="self" type="application/rss+xml" />
	<link>http://bernieyu.com</link>
	<description>复刻生活</description>
	<lastBuildDate>Tue, 17 May 2016 09:03:15 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>在Windows下搭建基于nginx的视频直播和点播系统</title>
		<link>http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/</link>
		<comments>http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/#comments</comments>
		<pubDate>Fri, 19 Jun 2015 09:00:27 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[ffplay]]></category>
		<category><![CDATA[hls]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rtmp]]></category>
		<category><![CDATA[yamdi]]></category>
		<category><![CDATA[录制]]></category>
		<category><![CDATA[直播]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=234</guid>
		<description><![CDATA[一、软件准备 由于nginx原生是为linux服务的，因此官方并没有编译好的windows版本可以下载，要在w ... <a class="more-link" href="http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<h2>一、软件准备</h2>
<p style="padding-left: 30px;">由于nginx原生是为linux服务的，因此官方并没有编译好的windows版本可以下载，要在windows上使用nginx，要么下载源码进行编译，要么使用其他人已经编译好的文件。</p>
<p style="padding-left: 30px;">而要让nginx支持视频直播和点播，还需要第三方的nginx模块：nginx-rtmp-module</p>
<p style="padding-left: 30px;">所幸，已经有大神做好了nginx的编译，而且集成了很多nginx模块，其中就已经包括了<a href="https://github.com/arut/nginx-rtmp-module">nginx-rtmp-module</a>。</p>
<p style="padding-left: 30px;">下载地址：<a href="http://nginx-win.ecsds.eu">http://nginx-win.ecsds.eu</a>/，详细说明可参见：<a href="http://nginx-win.ecsds.eu/download/Readme%20nginx-win%20version.txt">Readme nginx-win version.txt</a></p>
<p style="padding-left: 30px;">我下载的是<a href="http://nginx-win.ecsds.eu/download/nginx%201.7.11.3%20Gryphon.zip">nginx 1.7.11.3 Gryphon</a>这个版本。</p>
<p style="padding-left: 30px;">这个网站同时也提供了vcredist的下载（<a href="http://nginx-win.ecsds.eu/download/vcredist_x86.exe">x86</a>，<a href="http://nginx-win.ecsds.eu/download/vcredist_x64.exe">x64</a>），以避免运行nginx时出现缺少库的错误。</p>
<p style="padding-left: 30px;">另外还要下载<a href="https://github.com/arut/nginx-rtmp-module/blob/master/stat.xsl"> stat.xsl</a> 用于显示当前ngix-rtmp服务状态</p>
<p style="padding-left: 30px;">另外还需要下载ffmpeg、ffplay、yamdi：</p>
<p style="padding-left: 30px;">总结如下：</p>
<p style="padding-left: 30px;">1. <a href="http://nginx-win.ecsds.eu/download/nginx%201.7.11.3%20Gryphon.zip">nginx 1.7.11.3 Gryphon</a></p>
<p style="padding-left: 30px;">2. <a href="https://github.com/arut/nginx-rtmp-module/blob/master/stat.xsl">stat.xsl</a></p>
<p style="padding-left: 30px;">3. <a href="http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20150619-git-bb3703a-win32-static.7z">ffmpeg、ffplay</a></p>
<p style="padding-left: 30px;">4. <a href="http://sourceforge.net/projects/yamdi/files/latest/download?source=files">yamdi</a></p>
<h2>二、Nginx 配置</h2>
<p style="padding-left: 30px;"> 1. nginx配置</p>
<pre>worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;

        application hls {
             live on;  #启用rtmp直播
                       #地址为rtmp://[server]:[rtmp_port]/[app]/[stream]
             hls on;   #启用hls直播
                       #地址为http://[server]:[http_port]/[app]/[stream].m3u8
                       #需要配合下面http段设置使用
             hls_path nginx-rtmp-module/tmp/app/;
             hls_fragment 5s;
             recorder rec {  #启用录制
               record all manual;  #手动控制录制启停
               record_suffix _rec.flv;
               record_path nginx-rtmp-module/tmp/rec/;  #录制保存地址
               record_unique on;
           }
       }
       application vod2{  #rtmp点播
       		play nginx-rtmp-module/tmp/rec/;    
       }
    }
}

http {
    server {
        listen      18080;

        location /stat {  #服务器状态
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root nginx-rtmp-module/;
        }

        location /control { #控制器
            rtmp_control all;
        }
        
	location /hls/ {  #hls直播地址
           #server hls fragments
           types{
             application/vnd.apple.mpegurl m3u8;
             video/mp2t ts;
           }
           alias nginx-rtmp-module/tmp/app/;
           expires -1;
        }

        location /vod/{  #hls点播地址
            alias nginx-rtmp-module/tmp/rec/;
        }

        location / {
            root nginx-rtmp-module/test/www/;
        }
    }
}
</pre>
<h2>三、测试</h2>
<p style="padding-left: 30px;">1. 启动nginx</p>
<pre>start nginx_1.7.11.3_Gryphon\nginx</pre>
<p style="padding-left: 30px;">2. 推送rtmp流到nginx-rtmp</p>
<pre>start ffmpeg\ffmpeg -re -i rtmp://live.hkstv.hk.lxdns.com/live/hks -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec copy -f flv rtmp://localhost:1935/hls/mystream -loglevel quiet</pre>
<p style="padding-left: 30px;">3. rtmp直播</p>
<pre>ffmpeg\ffplay "rtmp://127.0.0.1:1935/hls/mystream"
</pre>
<p style="padding-left: 30px;">4. hls 直播</p>
<pre>ffmpeg\ffplay "http://127.0.0.1:18080/hls/mystream.m3u8"</pre>
<p style="padding-left: 30px;">5. 开始录制</p>
<pre>http://127.0.0.1:18080/control/record/start?app=hls&amp;name=mystream&amp;rec=rec</pre>
<p style="padding-left: 30px;">6. 停止录制</p>
<pre>http://127.0.0.1:18080/control/record/stop?app=hls&amp;name=mystream&amp;rec=rec</pre>
<p style="padding-left: 30px;">7. 为rtmp点播文件添加索引，否则文件在播放时进度条不能拖动，假定刚才录制的文件名为mystream-1428384476_rec.flv</p>
<pre>yamdi\yamdi -i nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -o nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec_idx.flv</pre>
<p style="padding-left: 30px;">8. rtmp点播</p>
<pre>ffmpeg\ffplay "rtmp://127.0.0.1:1935/vod2/mystream-1428384476_rec_idx.flv"</pre>
<p style="padding-left: 30px;">9. 制作hls点播分片文件</p>
<pre>ffmpeg\ffmpeg -i E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -acodec copy -bsf:a h264_mp4toannexb -g 105 -vcodec libx264 -vprofile baseline -bf 0 -bufsize 850k -bsf:v dump_extra -map 0 -f segment -segment_format mpegts -segment_list "E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec.m3u8" -segment_time 10 E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec-%d.ts</pre>
<p style="padding-left: 30px;">10. hls 点播</p>
<pre>ffplay "http://127.0.0.1:8080/vod/mystream-1428384476_rec/mystream-1428384476_rec.m3u8"</pre>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
