全ページのビデオストリーミングプレーヤー用のnginxとビルドの端子EasyPlayerライブおよびオンデマンドのビデオサーバをプラグインは、RTMP

使用のnginxとRTMPモジュールは、簡単にビデオ放送およびオンデマンドのサーバアウトを構築することができます。ここでは、特定の実装手順を見てみましょう。

インストールし、nginxのモジュールRTMP 1

コンパイルし、関連nginxのインストールは比較的簡単ですが、参考文献を参照してください、ここでは説明しません。ここでは、以下の点を示唆します:

(1)ここでは、nginxの設定ファイルをインストール:

/usr/local/nginx/conf/nginx.conf
(2)[スタート] nginxのコマンドを実行します。

$ sudo /usr/local/nginx/sbin/nginx -s stop
$ sudo /usr/local/nginx/sbin/nginx

2. [設定nginxのライブおよびオンデマンドビデオサービス

ビデオオンデマンドやライブに関連した完全な構成nginxの設定ファイルを見てみましょう。

rtmp {
	server {
		listen 1935;
		chunk_size 4096;
		application live {
			live on;
			record off;
		}
		application live2 {
			live on;
			record off;
		}
		# video on demand
		application vod {
			play /var/flvs;
		}
		application vod_http {
			play http://192.168.31.185/vod;
		}
		application hls {
			live on;
			hls on;
			hls_path /tmp/hls;
		}
	}
}
# HTTP can be used for accessing RTMP stats
http {
    server {
	listen      8080;
	# This URL provides RTMP statistics in XML
	location /stat {
	    rtmp_stat all;
	    # Use this stylesheet to view XML as web page
	    # in browser
	    rtmp_stat_stylesheet stat.xsl;
	}
	location /stat.xsl {
	    # XML stylesheet to view RTMP stats.
	    # Copy stat.xsl wherever you want
	    # and put the full directory path here
	    root /path/to/stat.xsl/;
	}
	location /hls {
	    # Serve HLS fragments
	    types {
		application/vnd.apple.mpegurl m3u8;
		video/mp2t ts;
	    }
	    root /tmp;
	    add_header Cache-Control no-cache;
	}
	location /dash {
	    # Serve DASH fragments
	    root /tmp;
	    add_header Cache-Control no-cache;
	}
    }
}

さて、コード内部の各行の意味を説明します。必要性は、複数の入力ストリームをサポートする場合は、ライブビデオサービスの場合、それはより多くのnginxの設定ファイル内のいくつかのアプリケーションでのみとなり、このような非常に簡単です、と。

application live {
	live on;
	record off;
}
application live2 {
	live on;
	record off;
}

これは、次のアドレスライブストリームを介してプッシュすることができ、観客のもう一方の端は、アドレスをフォローしているライブストリームによってアクセスすることができます。

RTMP://192.168.31.185/live/test
RTMP://192.168.31.185/live2/testは
、テストのキーワードに続いては、簡単に限り、あなたはその上に同じアドレスへのストリームの流れとアクセスを押すと、交換することができます。

RTMPモジュールはまた、直接オンデマンドサービスこのVODビデオをサポートすることができ、あなただけの設定ファイルに以下を追加する必要があります。

# video on demand
application vod {
    play /var/flvs;
}

application vod_http {
    play http://myserver.com/vod;
}

そして、それは次のURLからアクセスできます/var/flvs/dir/file.flvビデオファイルのFLVの下MP4やFLVファイルは/ var /ディレクトリに投げ込ま:

http://myserver.com/vod//dir/file.flv

だから、ウェブ経由でブラウザ内で直接ビデオを見ることができます。MP4ファイルの場合、あなたはまた、VODサービスを実現することができますが、それはH.264やmp4ファイルをエンコードされたAACフォーマットの使用である必要があります。

構成3. HLSライブストリーム

あなたは、設定ファイルとして直接、HLSライブ映像を使用する必要がある場合は、次の段落を記述します。

application hls {
        live on;
        hls on;
        hls_path /tmp/hls;
}

書き込みアクセスHTTPとの関係でリア中:

# HTTP can be used for accessing RTMP stats
http {
	server {
		listen	  8080;
		# This URL provides RTMP statistics in XML
		location /stat {
			rtmp_stat all;
			# Use this stylesheet to view XML as web page
			# in browser
			rtmp_stat_stylesheet stat.xsl;
		}
		location /stat.xsl {
			# XML stylesheet to view RTMP stats.
			# Copy stat.xsl wherever you want
			# and put the full directory path here
			root /path/to/stat.xsl/;
		}
		location /hls {
			# Serve HLS fragments
			types {
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
			}
			root /tmp;
			add_header Cache-Control no-cache;
		}
		location /dash {
			# Serve DASH fragments
			root /tmp;
			add_header Cache-Control no-cache;
		}
	}
}

良い未来では、プラグフローは、次のアドレスを使用することができます。

RTMP://192.168.31.185/hls/movie
作品のキーワードは任意の交換することができます。聴衆の終わりのために、それはいくつかの方法で再生することができます。

(1)RTMP:

RTMP://192.168.31.185/hls/movie
HLSと(2)のプレイ:

http://192.168.31.185:8080/hls/movie.m3u8
あなたはストリームへの導入のアンカー終わりを見ることができるようにします。あなたが道HTTPを使用する場合、それは設定ファイルに書かれているポート8080、リッスンしていることに注意してください。

4.プレイヤーはウェブを果たしています

第二段階では、ほかにビデオを見るために、ブラウザで直接URLを開くために、あなたはまた、のようなYoukuのようなビデオ・オン・デマンドサービスのためのページを書くことができます。サードパーティ製のプレーヤーを使用することにより、プレイヤーは、このようなEasyPlayerプレーヤーを使用するなど、これを達成するために、ページ上に移植。

彼は198元の記事を発表 ウォンの賞賛8 ビュー20000 +

おすすめ

転載: blog.csdn.net/TsingSee/article/details/104689437