1. 程式人生 > >直播推流nginx-rtmp-module整合

直播推流nginx-rtmp-module整合

戰鬥民族俄羅斯人民開發的一款NGINX的流媒體外掛,除了直播發布音視訊流之外具備流媒體伺服器的常見功能
比如推拉流媒體資源
基於HTTP的FLV/MP4 VOD點播
HLS (HTTP Live Streaming) M3U8的支援
基於http的操作(釋出、播放、錄製)
可以很好的協同現有的流媒體伺服器以及播放器一起工作
線上呼叫ffmpeg對流媒體進行轉碼
H264/AAC音視訊編碼格式的支援
linux/BSD/MAC系統的支援

編譯方法:

Screenshot from 2016-06-08 14:00:01.png

在上一篇中,已經成功部署了nginx伺服器,但是沒有整合推流的功能.

1\下載該模組
2\進入nginx-1.10.1目錄,重新配置configure
3\增加引數–add-module=/path/to/nginx-rtmp-module

sudo ./configure --prefix=/usr/local/nginx --with-pcre=/home/wangxiong/Soft/nginx_station/pcre-8.37 --with-zlib=/home/wangxiong/Soft/nginx_station/zlib-1.2.8 --with-openssl=/home/wangxiong/Soft/nginx_station/openssl-1.0.1t  --with-http_ssl_module --add-module=/home/wangxiong/Soft/nginx_station/nginx-rtmp-module

4\sudo make
5\sudo make install

安裝完成後nginx目錄:
Screenshot from 2016-06-08 14:10:28.png

伺服器配置nginx.conf所在路徑

Screenshot from 2016-06-08 14:21:00.png

可以用gedit或者vim開啟>


#user  nobody;
worker_processes  1;

#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;
}


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 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
rtmp {  
     server {  
            listen 1935;  

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

配置好後重啟nginx;
在本地可以用ffmpeg命令進行推流,然後用ffplayer進行播放

如果用ffmpeg命令出現.so共享庫找不到的問題,解決方法配置全域性共享
vim /etc/ld.so.conf
在後面新增一行/usr/local/ffmpeg/lib
按Esc->wq儲存退出
sudo ldconfig,生效

./ffmpeg -re -i /home/wangxiong/Documents/VID_20160508_164615.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/myapp/testav

./ffmpeg -re -i /home/wangxiong/Documents/VID_20160508_164615.mp4 -c copy -f flv rtmp://localhost:1935/myapp/testav

推流結果

Screenshot from 2016-06-08 16:59:05.png

為了方便,直接用雷博士的android推流客戶端,github上克隆或下載simplest_ffmpeg_android_streamer!

接下來,檢視本地nginx伺服器的ip地址,這個就是安卓客戶端要填寫的流伺服器地址.

Screenshot from 2016-06-08 17:51:19.png

我的ip地址是192.168.1.116
1\用Eclipse匯入專案工程,配置好NDK自動編譯.
2\開啟MainActivity,填寫輸入檔案路徑,和流伺服器地址,當然我只是做了判斷,如果EditText不填寫,我就給一個預設的值.

               String folderurl = Environment.getExternalStorageDirectory()
                        .getPath();

                String urltext_input = urlEdittext_input.getText().toString();

                if (TextUtils.isEmpty(urltext_input)) {
                    urltext_input = "sintel.mp4";
                }
                String inputurl = folderurl + "/" + urltext_input;

                String outputurl = urlEdittext_output.getText().toString();

                String info = "";
                if (TextUtils.isEmpty(outputurl)) {
                    outputurl = "rtmp://192.168.1.116:1935/myapp/livestream";
                    // 192.168.1.116
                }
                stream(inputurl, outputurl); //native方法
                Log.e("inputurl", inputurl);
                Log.e("outputurl", outputurl);

執行build程式,點選 Start 按鈕,開始將SD卡下的視訊推到伺服器.

Screenshot from 2016-06-08 18:03:49.png

注意,因為直播,我這裡是在安卓上點選推流,然後在ubuntu開啟瀏覽器訪問rtmp流.
ps:安裝VLC播放器:sudo apt-get install vlc 一條命令搞定.

Screenshot from 2016-06-09 10:52:51.png

然後選擇播放應用程式,我已經安裝了VLC播放器,就用它了.

Screenshot from 2016-06-09 10:56:58.png

Screenshot from 2016-06-09 11:03:46.png

Screenshot from 2016-06-09 11:02:00.png

直播開始啦,只要手機一直有視訊推上來,播放器可以一直播放!!!

相關推薦

直播nginx-rtmp-module整合

戰鬥民族俄羅斯人民開發的一款NGINX的流媒體外掛,除了直播發布音視訊流之外具備流媒體伺服器的常見功能 比如推拉流媒體資源 基於HTTP的FLV/MP4 VOD點播 HLS (HTTP Live Streaming) M3U8的支援 基於http的操

直播實現RTMP協議的一些注意事項

018年8月4日第三次更新,詳細介紹了RTMP協議與遇到的坑,另外純Java重寫了RTMP協議,做了個Android 推流專案,包含安卓相機採集,編碼和RTMP推流,上傳到github了。 專案地址:https://github.com/gezhaoyou/SimpleLivePublisherLi

ubuntu下使用nginxnginx-rtmp-module配置直播伺服器

本來準備在centos伺服器上搭建的,因為筆者工作系統是ubuntu,因此直接在本機上搭建,更方便快捷,配置過程比較簡單,記錄一下。 目錄 配置環境 安裝obs-studio開始第一次推流 安裝vlc播放器開始拉流 配置環境 配置環境 配

nginx-rtmp-module授權機制實現直播多房間授權認證

假設nginx直播伺服器已經搭建完畢,如果還沒有搭建完畢可以查閱利用nginx的nginx-rtmp-module搭建流媒體直播伺服器這篇文章。在開發直播專案時推流應該是需要做許可權認證的,不是任何人都可以隨意向直播伺服器推流,這就需要許可權認證,實現起來也不復雜,只需要在nginx配置檔案中的rt

obs nginx-rtmp-module搭建媒體服務器實現直播 ding

video 接下來 監聽 comm 地址 什麽 ip地址 automake text 接下來我就簡單跟大家介紹一下利用nginx來搭建流媒體服務器。 我選擇的是騰訊雲服務器 1、下載nginx-rtmp-module: nginx-rtmp-module的官方gith

使用Nginx+nginx-rtmp-module+OBS搭建媒體伺服器

一、安裝Nginx 下載必備安裝包 建立安裝包存放資料夾 cd mkdir /usr/source #建立原始碼目錄 後面的原始碼都放在這個目錄 cd source yum -y install git #安裝git git clone https://github.

利用nginxnginx-rtmp-module搭建媒體伺服器實現直播

轉自:https://www.cnblogs.com/suiyuewuxin/p/7256972.html 使用環境是centos 7.0+nginx;可以實現簡單的流媒體服務。 先下載nginx-rtmp-module拓展: nginx-rtmp-module的官方github地址:h

利用nginxnginx-rtmp-module搭建媒體直播伺服器

Nginx除了做web伺服器之外在流媒體方面的支援也是有對應的模組,nginx-rtmp-module就是nginx的一個擴充套件模組,支援rtmp視訊推流,同時利用nginx作為web伺服器的有時可以很方便的實現直播拉流,專案官方地址是https://github.com/arut/nginx-r

通過nginx,nginx-rtmp-module實現媒體直播

1、 下載nginx http://nginx.org/en/download.html 下載nginx-rtmp-module: nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module

搭建直播伺服器,使用nginxnginx-rtmp-module搭建媒體伺服器;

現在,一起學習一下如何自己搭建一個流媒體伺服器吧! 本次搭建流媒體使用的環境是centos 7.0+nginx; 讓我們一起開始奇妙的流媒體之旅吧! 1、下載nginx-rtmp-module: 使用命令: git clone https://gi

obs nginx-rtmp-module搭建媒體伺服器實現直播 ding

歡迎大家來此瀏覽,希望大家一塊在此學習,共同交流進步。 接下來我就簡單跟大家介紹一下利用nginx來搭建流媒體伺服器。 我選擇的是騰訊雲伺服器 1、下載nginx-rtmp-module: 使用命令: git clone https://github.com/

FFmpeg+Nginx搭建RTMP直播服務

    Nginx是優秀的開源並且可以新增外掛的服務端,其中就有開源的RTMP外掛nginx-rtmp-module實現了RTMP推流服務。     專案地址為: https://github.com/arut/nginx-rtmp-module 搭建思路:    

基於nginx-rtmp-module測試

1、安裝nginx伺服器 (參考http://nginx.org/en/docs/) sudo apt-get install nginx 或者從原始碼安裝 wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz

直播系列4-使用nginx+nginx-rtmp-module+ffmpeg搭建媒體伺服器筆記(一)

第一部分 主要步驟及命令記錄: 2、為了增加對rtmp的支援,下載nginx-rtmp-module,地址:https://github.com/arut/nginx-rtmp-module#example-nginxconf,這個是個開源專案。解壓後,為了和我在網上看到的教程同步,我改了資料夾名字

nginxnginx-rtmp-module搭建媒體服務器

vedio sans nginx配置 mark dir pen isp 自己 需要 轉載自my student 克明zhang 現在,一起學習一下如何自己搭建一個流媒體服務器吧! 本次搭建流媒體使用的環境是centos 7.0+nginx; 讓我們一起開始奇妙的流媒體之

媒體技術學習筆記之(三)Nginx-Rtmp-Module統計某頻道在線觀看的客戶數

sele lec rest uri class origin 客戶 擴展 raw 獲得訂閱者人數,可以方便地顯示觀看流的客戶數。 查看已經安裝好的模塊 /usr/local/nginx/sbin/nginx -V 安裝從源編譯Nginx和Nginx-RTMP所

基於nginx-rtmp-module模塊實現的HTTP-FLV直播模塊(nginx-http-flv-module

發現 app1 多播 git app 命令 避免 put 編譯 本文後續的內容將在這裏更新:《基於nginx-rtmp-module模塊實現的HTTP-FLV直播模塊(nginx-http-flv-module)續》。註意:下文的配置很多已經不能用了,因為現在的實現跟早期

nginx-rtmp-module搭建媒體服務器

復制 file ftp fault ces 只需要 record chunk inf nginx搭建流媒體服務器 進入新建的文件夾prog 1、下載nginx-rtmp-modulegit clone https://github.com/arut/nginx-rtmp-m

linux CentOS7 nginx 1.13.12 nginx-rtmp-module搭建直播(親測非轉載)

我就真是服氣了一些人,轉載別人寫的東西之前不測試測下,十篇文章有八篇相同,害得我照你們的辦法弄不出來(承認能力有問題),自己弄了一個,完全親測,還有辟邪影象為證。有問題請呼我。安裝nginx依賴軟體 yum -y install gcc gcc-c++ autoconf automake ma

nginx-rtmp-module搭建rtmp媒體伺服器

前言 利用開源的nginx-rtmp-module和Nginx搭建流媒體伺服器。Nginx是一個非常出色的http伺服器,nginx-rtmp-module是一個開源的Nginx擴充套件模組,擁有很多功能特性,像接收rtmp推流拉流,hls直播等: 1.RTMP/HLS/MPEG