Help us understand the problem. What is going on with this article?

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

簡単に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

_syado_
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした