LoginSignup
26
36

More than 3 years have passed since last update.

Nginxで簡単にライブストリーミングサーバ構築(ubuntu)

Last updated at Posted at 2018-07-06

簡単にRTMPでライブストリーミング配信できるサーバを構築する方法を説明します。

環境

OS: Ubuntu 16.04.4 LTS

必要な物をインストール

$ sudo apt-get update
$ sudo apt-get upgrade -y
$ sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev -y

スクリプトをダウンロード

簡単に構築するために、こちらのスクリプトを使います。

$ git clone https://github.com/notaweelos/rtmp-streaming-server-build-script.git

スクリプトを実行

$ cd rtmp-streaming-server-build-script
$ sudo bash ./build.sh

ディレクトリを移動し、実行します。

1. Nginx-with-rtmp
2. Tengine-with-rtmp
3. Openresty-with-rtmp
First: you must install PCRE library and wget
---------------------------------------------------------------------------------
CentOS: yum -y pcre-devel
Ubuntu: apt-get install libpcre3 libpcre3-dev
---------------------------------------------------------------------------------
Author: losywee@gmail.com
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
Please Select build type ( 1 2 3 ) >

するとこのような画面になるので、1を選択。
構築が始まり、しばらく待ちます。

confファイル設定

nginx.confファイルの最後に下記を追加

/opt/local/nginx/conf/nginx.conf
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            hls on;
            hls_path /opt/local/nginx/html;
            hls_fragment 5s;
            hls_type live;
        }
    }
}

追加後、confファイルが正常かテスト

$ sudo /opt/local/nginx/sbin/nginx -t

下記のように返ってきたら問題なし。

nginx: the configuration file /opt/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/local/nginx/conf/nginx.conf test is successful

Nginxを実行

$ sudo /opt/local/nginx/sbin/nginx

配信設定

OBSなどの配信ソフトで下記のように設定

URL: rtmp://{ipアドレス}/live
ストリーミングキー: 自由
※以降ストリーミングキーは{key}、ipアドレスは{ipアドレス}と記述

WEBページ作成

index.htmlファイルを編集

/opt/local/nginx/html/index.html
<!DOCTYPE html>
<html lang="en" class="">
<head>
  <link href="http://vjs.zencdn.net/4.2.0/video-js.css" rel="stylesheet">
  <script src="http://vjs.zencdn.net/4.2.0/video.js"></script>
</head>
<style type="text/css">
  #live {
    position: absolute;
    left: 0;
    top: 0;
    min-width: 100%;
    min-height: 100%;
    width: 100%;
    height: 100%;
    z-index: 1;
}
</style>
<body>
  <video id="live" class="video-js vjs-default-skin" controls autoplay fullc
   preload="auto" data-setup='{}'>
    <source src="{key}.m3u8" type='application/x-mpegURL'>
    <source src="rtmp://{ipアドレス}:1935/live/{key}" type='rtmp/mp4'>
    <p class="vjs-no-js">サポートしておりません</p>
  </video>
</body>
</html>

Webページで鑑賞

http://{ipアドレス}にアクセスすると、HLSまたはRTMPで自動再生されます。

VLCで鑑賞

Ctrl+VでURLを打ち込む画面になるので、下記を入力し再生

rtmp://{ipアドレス}:1935/live/{Key}

参照元

http://www.hiroyuki.com/posts/615307/
https://qiita.com/nuxaxtu/items/250ca4fb4e102fa425d7
https://qiita.com/drasky1132/items/93ab71742175914e61cb
https://github.com/losywee/rtmp-streaming-server-build-script

26
36
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
36