來來來,作個直播DEMO

目前直播很火,可是直播是怎麼作的呢?不少地方都有相關的教程,在這裏作一個我作的簡單的DEMO,從零開始。如下所說的服務器環境所有在Linux上。html

  • nginx的編譯安裝

    • 在服務器上下載如下源碼,截至目前這些包都是最新的。nginx

      • 下載nginx的源碼 連接git

      • 下載pcre的源碼 連接github

      • 下載zlib的源碼 連接服務器

      • 下載openssl的源碼 連接網絡

      • 下載nginx-rtmp-module的源碼 連接app

    • 編譯安裝ide

      • 下載完了以後你的目錄結構應該是這樣的,順序的羅列在某個文件夾下。code

        • nginxserver

        • pcre

        • openssl

        • zlib

        • nginx-rtmp-module

      • 編譯

        • 進入pcre的目錄執行命令 ./configure && make && make install

        • 進入nginx的目錄執行命令

          ./configure --add-module=../nginx-rtmp-module --with-http_ssl_module  --with-openssl=../openssl --with-zlib=../zlib 
                  make 
                  make install`。
      • 運行

        • 安裝好的nginx都在 /usr/local/nginx 中。

        • 修改 /usr/local/nginx/conf/nginx.conf 文件內容:

          worker_processes  1;
                  events {
                      worker_connections  1024;
                  }
          
                  rtmp {
                      server {
                          listen 1935;
                          chunk_size 4096;
                          application live {
                              live on;
                              record off;
                          }
          
                          application hls {
                                  live on;
                                  hls on;
                                  hls_path hls_temp;
                                  hls_fragment 8s;
                          }
                      }
                  }
                  http {
                      include       mime.types;
                      default_type  application/octet-stream;
                      sendfile        on;
                      keepalive_timeout  65;
                      server {
                          listen       80;
                          server_name  localhost;
                          location / {
                              root   html/Love/;
                              index  index.html index.htm;
                          }
                          error_page   500 502 503 504  /50x.html;
                          location = /50x.html {
                          root   html;
                      }
                  }
  • 推流與觀看

    • 推流

      • 向服務端推送直播的內容,能夠用比較流行的OBS,固然在網上搜一下一些ffmpeg的命令也是能夠的。

      • 設置廣播設定爲rtmp://ServerIP:1935/live

      • 設置播放路徑串流碼爲 test

      • 選擇一個場景開始串流

    • 觀看

      • 就用大名鼎鼎的 vlc

      • 設置 打開媒體 -> 打開網絡 rtmp://ServerIP/live/test

      • vlc也是有手機版的,是一樣。

相關文章
相關標籤/搜索