使用 nginx_rtmp_module 搭建個人學習流媒體服務器


nginx 共享服務器中的視頻

如果服務器處於內網或者沒有公網ip,可以使用 相關軟件進行打洞或轉發 如: frpc https://github.com/fatedier/frpholer https://github.com/wisdom-projects/holer

需求場景:
服務器中有很多視頻,有時候在外面想要看些視頻的時候就有些麻煩了.可以通過http共享然后使用vlc之類播放器播放.但是需要自制播放列表很是麻煩.
實現方法:
使用nginx 的 nginx_rtmp_module 插件可以實現 在網頁中點擊目錄方式在線觀看視頻.

所以nginx是必要的.而且要源碼編譯,編譯時候要加上nginx_rtmp_module 這個模塊.

下載編譯安裝

必要的編譯包自行安裝.gcc之類還有一些依賴包

 wget http://nginx.org/download/nginx-1.16.0.tar.gz
 wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
 tar xf nginx-1.16.0.tar.gz
 unzip master.zip
 cd nginx-1.16.0
 mv * ../
 cd ..
 ./configure --with-http_ssl_module  --add-module=../nginx-rtmp-module-master
 make -j4
 make install

至此nginx編譯安裝完成.

配置nginx

vim /usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

rtmp { #不接受推流這里可以不需要
    server {
        listen 1935;
 
        application vod {
            play /mnt/s2t; #這是一個目錄的名稱,如果是linux,則寫具體位置如/opt/video
        }
    }
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        charset utf8;

        #access_log  logs/host.access.log  main;

        location / {
            root   /mnt/s2t;
	    autoindex on;
	    auth_basic "needAuth";
        auth_basic_user_file /usr/local/nginx/conf/passwd.db;
	    index  index.html index.htm;
        }
 
}

生成登錄驗證密碼文件

htpasswd -c /usr/local/nginx/conf/passwd.db makeit

測試訪問

/usr/local/nginx/sbin/nginx -s reload

關於 倍速播放
經測試火狐瀏覽器支持倍速播放的. 其他chrome,opera 不支持

參考:

關於模塊更多信息

https://github.com/arut/nginx-rtmp-module


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM