【Android RTMP】RTMP 直播推流服务器搭建 ( Ubuntu 18.04.4 虚拟机 )
文章目錄
- 安卓直播推流專欄博客總結(jié)
- 一、 Android RTMP 直播推流簡(jiǎn)介
- 二、 Nginx、RTMP Module 編譯環(huán)境源碼準(zhǔn)備
- 三、 pcre、OpenSSL、zlib 函數(shù)庫安裝
- 四、 編譯安裝 Nginx
- 五、 配置 RTMP
- 六、 修改 Nginx 和 RTMP Module 權(quán)限
- 七、 虛擬機(jī)網(wǎng)絡(luò)配置
- 八、 啟動(dòng) Nginx 服務(wù)器
安卓直播推流專欄博客總結(jié)
Android RTMP 直播推流技術(shù)專欄 :
0 . 資源和源碼地址 :
- 資源下載地址 : 資源下載地址 , 服務(wù)器搭建 , x264 , faac , RTMPDump , 源碼及交叉編譯庫 , 本專欄 Android 直播推流源碼 ;
- GitHub 源碼地址 : han1202012 / RTMP_Pusher
1. 搭建 RTMP 服務(wù)器 : 下面的博客中講解了如何在 VMWare 虛擬機(jī)中搭建 RTMP 直播推流服務(wù)器 ;
- 【Android RTMP】RTMP 直播推流服務(wù)器搭建 ( Ubuntu 18.04.4 虛擬機(jī) )
2. 準(zhǔn)備視頻編碼的 x264 編碼器開源庫 , 和 RTMP 數(shù)據(jù)包封裝開源庫 :
-
【Android RTMP】RTMPDumb 源碼導(dǎo)入 Android Studio ( 交叉編譯 | 配置 CMakeList.txt 構(gòu)建腳本 )
-
【Android RTMP】Android Studio 集成 x264 開源庫 ( Ubuntu 交叉編譯 | Android Studio 導(dǎo)入函數(shù)庫 )
3. 講解 RTMP 數(shù)據(jù)包封裝格式 :
-
【Android RTMP】RTMP 數(shù)據(jù)格式 ( FLV 視頻格式分析 | 文件頭 Header 分析 | 標(biāo)簽 Tag 分析 | 視頻標(biāo)簽 Tag 數(shù)據(jù)分析 )
-
【Android RTMP】RTMP 數(shù)據(jù)格式 ( FLV 視頻格式分析 | AVC 序列頭格式解析 )
4. 圖像數(shù)據(jù)采集 : 從 Camera 攝像頭中采集 NV21 格式的圖像數(shù)據(jù) , 并預(yù)覽該數(shù)據(jù) ;
-
【Android RTMP】Android Camera 視頻數(shù)據(jù)采集預(yù)覽 ( 視頻采集相關(guān)概念 | 攝像頭預(yù)覽參數(shù)設(shè)置 | 攝像頭預(yù)覽數(shù)據(jù)回調(diào)接口 )
-
【Android RTMP】Android Camera 視頻數(shù)據(jù)采集預(yù)覽 ( NV21 圖像格式 | I420 圖像格式 | NV21 與 I420 格式對(duì)比 | NV21 轉(zhuǎn) I420 算法 )
-
【Android RTMP】Android Camera 視頻數(shù)據(jù)采集預(yù)覽 ( 圖像傳感器方向設(shè)置 | Camera 使用流程 | 動(dòng)態(tài)權(quán)限申請(qǐng) )
5. NV21 格式的圖像數(shù)據(jù)編碼成 H.264 格式的視頻數(shù)據(jù) :
-
【Android RTMP】x264 編碼器初始化及設(shè)置 ( 獲取 x264 編碼參數(shù) | 編碼規(guī)格 | 碼率 | 幀率 | B幀個(gè)數(shù) | 關(guān)鍵幀間隔 | 關(guān)鍵幀解碼數(shù)據(jù) SPS PPS )
-
【Android RTMP】x264 圖像數(shù)據(jù)編碼 ( Camera 圖像數(shù)據(jù)采集 | NV21 圖像數(shù)據(jù)傳到 Native 處理 | JNI 傳輸字節(jié)數(shù)組 | 局部引用變量處理 | 線程互斥 )
-
【Android RTMP】x264 圖像數(shù)據(jù)編碼 ( NV21 格式中的 YUV 數(shù)據(jù)排列 | Y 灰度數(shù)據(jù)拷貝 | U 色彩值數(shù)據(jù)拷貝 | V 飽和度數(shù)據(jù)拷貝 | 圖像編碼操作 )
6. 將 H.264 格式的視頻數(shù)據(jù)封裝到 RTMP 數(shù)據(jù)包中 :
-
【Android RTMP】RTMPDump 封裝 RTMPPacket 數(shù)據(jù)包 ( 封裝 SPS / PPS 數(shù)據(jù)包 )
-
【Android RTMP】RTMPDump 封裝 RTMPPacket 數(shù)據(jù)包 ( 關(guān)鍵幀數(shù)據(jù)格式 | 非關(guān)鍵幀數(shù)據(jù)格式 | x264 編碼后的數(shù)據(jù)處理 | 封裝 H.264 視頻數(shù)據(jù)幀 )
-
【Android RTMP】RTMPDump 推流過程 ( 獨(dú)立線程推流 | 創(chuàng)建推流器 | 初始化操作 | 設(shè)置推流地址 | 啟用寫出 | 連接 RTMP 服務(wù)器 | 發(fā)送 RTMP 數(shù)據(jù)包 )
7. 階段總結(jié) : 阿里云服務(wù)器中搭建 RTMP 服務(wù)器 , 并使用電腦軟件推流和觀看直播內(nèi)容 ;
-
【Android RTMP】RTMP 直播推流 ( 阿里云服務(wù)器購買 | 遠(yuǎn)程服務(wù)器控制 | 搭建 RTMP 服務(wù)器 | 服務(wù)器配置 | 推流軟件配置 | 直播軟件配置 | 推流直播效果展示 )
-
【Android RTMP】RTMP 直播推流階段總結(jié) ( 服務(wù)器端搭建 | Android 手機(jī)端編碼推流 | 電腦端觀看直播 | 服務(wù)器狀態(tài)查看 )
8. 處理 Camera 圖像傳感器導(dǎo)致的 NV21 格式圖像旋轉(zhuǎn)問題 :
-
【Android RTMP】NV21 圖像旋轉(zhuǎn)處理 ( 問題描述 | 圖像順時(shí)針旋轉(zhuǎn) 90 度方案 | YUV 圖像旋轉(zhuǎn)細(xì)節(jié) | 手機(jī)屏幕旋轉(zhuǎn)方向 )
-
【Android RTMP】NV21 圖像旋轉(zhuǎn)處理 ( 圖像旋轉(zhuǎn)算法 | 后置攝像頭順時(shí)針旋轉(zhuǎn) 90 度 | 前置攝像頭順時(shí)針旋轉(zhuǎn) 90 度 )
9. 下面這篇博客比較重要 , 里面有一個(gè)快速搭建 RTMP 服務(wù)器的腳本 , 強(qiáng)烈建議使用 ;
- 【Android RTMP】NV21 圖像旋轉(zhuǎn)處理 ( 快速搭建 RTMP 服務(wù)器 Shell 腳本 | 創(chuàng)建 RTMP 服務(wù)器鏡像 | 瀏覽器觀看直播 | 前置 / 后置攝像頭圖像旋轉(zhuǎn)效果展示 )
10. 編碼 AAC 音頻數(shù)據(jù)的開源庫 FAAC 交叉編譯與 Android Studio 環(huán)境搭建 :
-
【Android RTMP】音頻數(shù)據(jù)采集編碼 ( 音頻數(shù)據(jù)采集編碼 | AAC 高級(jí)音頻編碼 | FAAC 編碼器 | Ubuntu 交叉編譯 FAAC 編碼器 )
-
【Android RTMP】音頻數(shù)據(jù)采集編碼 ( FAAC 頭文件與靜態(tài)庫拷貝到 AS | CMakeList.txt 配置 FAAC | AudioRecord 音頻采樣 PCM 格式 )
11. 解析 AAC 音頻格式 :
- 【Android RTMP】音頻數(shù)據(jù)采集編碼 ( AAC 音頻格式解析 | FLV 音頻數(shù)據(jù)標(biāo)簽解析 | AAC 音頻數(shù)據(jù)標(biāo)簽頭 | 音頻解碼配置信息 )
12 . 將麥克風(fēng)采集的 PCM 音頻采樣編碼成 AAC 格式音頻 , 并封裝到 RTMP 包中 , 推流到客戶端 :
-
【Android RTMP】音頻數(shù)據(jù)采集編碼 ( FAAC 音頻編碼參數(shù)設(shè)置 | FAAC 編碼器創(chuàng)建 | 獲取編碼器參數(shù) | 設(shè)置 AAC 編碼規(guī)格 | 設(shè)置編碼器輸入輸出參數(shù) )
-
【Android RTMP】音頻數(shù)據(jù)采集編碼 ( FAAC 編碼器編碼 AAC 音頻解碼信息 | 封裝 RTMP 音頻數(shù)據(jù)頭 | 設(shè)置 AAC 音頻數(shù)據(jù)類型 | 封裝 RTMP 數(shù)據(jù)包 )
-
【Android RTMP】音頻數(shù)據(jù)采集編碼 ( FAAC 編碼器編碼 AAC 音頻采樣數(shù)據(jù) | 封裝 RTMP 音頻數(shù)據(jù)頭 | 設(shè)置 AAC 音頻數(shù)據(jù)類型 | 封裝 RTMP 數(shù)據(jù)包 )
一、 Android RTMP 直播推流簡(jiǎn)介
Android 端直播推流原理 :
① 數(shù)據(jù)采集 : 使用 Camera 相機(jī)采集圖像數(shù)據(jù) , 使用 AudioRecord 采集聲音 ;
② 數(shù)據(jù)編碼 : 將圖像和聲音分別進(jìn)行編碼 , 視頻使用 H.264 格式進(jìn)行編碼 , 音頻使用 AAC 格式進(jìn)行編碼 ;
③ 數(shù)據(jù)打包 : 將 H.264 格式的視頻數(shù)據(jù) , 和 AAC 格式的音頻數(shù)據(jù) , 打包為 RTMP 格式的數(shù)據(jù)包 ;
④ 數(shù)據(jù)發(fā)送 : 將上述 RTMP 數(shù)據(jù)包發(fā)送到流媒體服務(wù)器 ;
二、 Nginx、RTMP Module 編譯環(huán)境源碼準(zhǔn)備
需要在 Linux 服務(wù)器中搭建 NGINX RTMP 服務(wù)器 , 下面是搭建 NGINX RTMP 流媒體服務(wù)器環(huán)境及源碼準(zhǔn)備 ;
1 . 下載 nginx 源碼 : 到 NGINX 服務(wù)器下載地址 下載 nginx 源碼 , 也可以點(diǎn)擊此處 , 直接 下載源碼 ;
2 . 下載 nginx rtmp 服務(wù)器應(yīng)用 : arut/nginx-rtmp-module , 不要直接下載測(cè)試或者不穩(wěn)定版本 , 下載其發(fā)布版本 , 點(diǎn)擊 Releases 查看 發(fā)布版本 , 這里選擇 v1.2.1 發(fā)布版本 進(jìn)行下載 ;
3 . 編譯環(huán)境準(zhǔn)備 : 下載完畢后 , 在 Ubuntu 的 root 用戶目錄下 , 創(chuàng)建 rtmp 目錄 , 將兩個(gè)包拷貝到 rtmp 目錄中 , nginx 服務(wù)器與 nginx-rtmp-module 在該目錄下進(jìn)行編譯安裝 ;
4 . 解壓源碼 :
① 解壓 nginx 源碼 : tar xvf nginx-1.15.3.tar.gz ;
② 解壓 nginx-rtmp-module 源碼 : tar xvf nginx-rtmp-module-1.2.1.tar.gz ;
三、 pcre、OpenSSL、zlib 函數(shù)庫安裝
1 . 查看編譯配置 : ./configure --help 可以查看編譯配置選項(xiàng) ;
root@octopus:~/rtmp# cd nginx-1.15.3 root@octopus:~/rtmp/nginx-1.15.3# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src root@octopus:~/rtmp/nginx-1.15.3# ./configure --help--help print this message--prefix=PATH set installation prefix... --add-module=PATH enable external module...--with-debug enable debug loggingroot@octopus:~/rtmp/nginx-1.15.3#2 . 使用到的編譯配置 :
① – prefix=PATH : 代碼編譯后的安裝目錄 ;
② – add-module=PATH : 啟用外部模塊 , 就是啟用 RTMP 模塊 ;
3 . 編譯配置 : 執(zhí)行 ./configure --prefix=./bin --add-module=…/nginx-rtmp-module-1.2.1 命令 , 配置編譯選項(xiàng) ;
① --prefix=./bin 配置 : 將編譯結(jié)果 , 安裝到當(dāng)前目錄下的 bin 目錄 ;
② --add-module=…/nginx-rtmp-module-1.2.1 配置 : 啟用外部的 RTMP 直播推流模塊 ;
4 . 配置失敗 : the HTTP rewrite module requires the PCRE library , 下面安裝 PCRE 庫 ;
root@octopus:~/rtmp/nginx-1.15.3# ./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1 checking for OS+ Linux 5.3.0-28-generic x86_64 checking for C compiler ... found+ using GNU C compiler+ gcc version: 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) ... 省略1萬行configuring additional modules adding module in ../nginx-rtmp-module-1.2.1+ ngx_rtmp_module was configured checking for PCRE library ... not found checking for PCRE library in /usr/local/ ... not found checking for PCRE library in /usr/include/pcre/ ... not found checking for PCRE library in /usr/pkg/ ... not found checking for PCRE library in /opt/local/ ... not found./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.root@octopus:~/rtmp/nginx-1.15.3#5 . 更新 apt-get 源 : 源 存儲(chǔ)在 /etc/apt/sources.list 文件中 ;
① 備份源 :
mv /etc/apt/sources.list /etc/apt/sourses.list.backup② 添加源 : 創(chuàng)建 /etc/apt/sources.list 文件 , 并將下面的內(nèi)容拷貝到其中 ; 這是 163 網(wǎng)易提供的源 ;
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse③ 更新源 :
sudo apt-get update6 . 安裝 pcre : 執(zhí)行 sudo apt-get install libpcre3 libpcre3-dev 命令 , 安裝成功 ;
root@octopus:~/rtmp/nginx-1.15.3# sudo apt-get install libpcre3 libpcre3-dev7 . 再次執(zhí)行編譯配置選項(xiàng) : 執(zhí)行 ./configure --prefix=./bin --add-module=…/nginx-rtmp-module-1.2.1 命令 , 報(bào)錯(cuò) SSL modules require the OpenSSL library , 繼續(xù)安裝 OpenSSL 庫 ;
root@octopus:~/rtmp/nginx-1.15.3# ./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1 checking for OS+ Linux 5.3.0-28-generic x86_64 checking for C compiler ... found+ using GNU C compiler+ gcc version: 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) ... 省略1萬行configuring additional modules adding module in ../nginx-rtmp-module-1.2.1+ ngx_rtmp_module was configured checking for PCRE library ... found checking for PCRE JIT support ... found checking for OpenSSL library ... not found checking for OpenSSL library in /usr/local/ ... not found checking for OpenSSL library in /usr/pkg/ ... not found checking for OpenSSL library in /opt/local/ ... not found./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option.root@octopus:~/rtmp/nginx-1.15.3#8 . 安裝 OpenSSL 庫 :
sudo apt-get install openssl libssl-dev9 . 繼續(xù)嘗試配置 : 報(bào)錯(cuò) the HTTP gzip module requires the zlib library , 缺少 zlib 庫 , 繼續(xù)安裝 zlib 庫 ;
root@octopus:~/rtmp/nginx-1.15.3# ./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1 checking for OS+ Linux 5.3.0-28-generic x86_64 checking for C compiler ... found+ using GNU C compiler+ gcc version: 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) ... 省略configuring additional modules adding module in ../nginx-rtmp-module-1.2.1+ ngx_rtmp_module was configured checking for PCRE library ... found checking for PCRE JIT support ... found checking for OpenSSL library ... found checking for zlib library ... not found./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option.10 . 安裝 zlib 庫 : sudo apt-get install zlib1g-dev ;
sudo apt-get install zlib1g-dev11 . 繼續(xù)嘗試配置 : 這會(huì)成功了 , 可以開始編譯了 ;
root@octopus:~/rtmp/nginx-1.15.3# ./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1 checking for OS+ Linux 5.3.0-28-generic x86_64 checking for C compiler ... found+ using GNU C compiler+ gcc version: 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) checking for gcc -pipe switch ... found checking for -Wl,-E switch ... found... 省略configuring additional modules adding module in ../nginx-rtmp-module-1.2.1+ ngx_rtmp_module was configured checking for PCRE library ... found checking for PCRE JIT support ... found checking for OpenSSL library ... found checking for zlib library ... found creating objs/MakefileConfiguration summary+ using system PCRE library+ using system OpenSSL library+ using system zlib librarynginx path prefix: "./bin"nginx binary file: "./bin/sbin/nginx"nginx modules path: "./bin/modules"nginx configuration prefix: "./bin/conf"nginx configuration file: "./bin/conf/nginx.conf"nginx pid file: "./bin/logs/nginx.pid"nginx error log file: "./bin/logs/error.log"nginx http access log file: "./bin/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"root@octopus:~/rtmp/nginx-1.15.3#12 . 總結(jié) : 這里總結(jié)下上面的坑 , 巨坑 , 百度了半小時(shí) ;
① 需要安裝的庫 : pcre、OpenSSL、zlib ;
② 相應(yīng)的安裝命令 :
sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install openssl libssl-dev sudo apt-get install zlib1g-dev四、 編譯安裝 Nginx
1 . 生成的 Makefile 文件 : 上面執(zhí)行完 ./configure --prefix=./bin --add-module=…/nginx-rtmp-module-1.2.1 命令后 , 會(huì)生成 Makefile 文件 ;
2 . 編譯安裝 : 執(zhí)行 make install 進(jìn)行編譯安裝 , 執(zhí)行完畢后 , 生成 bin 目錄 , 編譯生成的文件都安裝在這里 ;
3 . 查看 bin 目錄 : bin 目錄下生成了 444 個(gè)文件 ;
① conf : 服務(wù)器配置腳本目錄 , 有很多配置腳本 ;
② html : HTTP 網(wǎng)頁放在這里 ;
③ logs : 存放日志 ;
④ sbin : 可執(zhí)行文件 ;
五、 配置 RTMP
1 . 配置 conf/nginx.conf 腳本 : Nginx 服務(wù)器默認(rèn)是沒有 RTMP 功能的 , 需要手動(dòng)配置 , 這里就需要在 conf/nginx.conf 腳本中進(jìn)行配置 ;
2 . Nginx RTMP 配置示例 : 在 nginx-rtmp-module-1.2.1/test 目錄下 , 有一個(gè) nginx.conf 配置文件 , 該配置文件提供了 Nginx 服務(wù)器中的 RTMP 配置方法 , 僅做參考 ;
worker_processes 1;error_log logs/error.log debug;events {worker_connections 1024; }rtmp {server {listen 1935;application myapp {live on;#record keyframes;#record_path /tmp;#record_max_size 128K;#record_interval 30s;#record_suffix .this.is.flv;#on_publish http://localhost:8080/publish;#on_play http://localhost:8080/play;#on_record_done http://localhost:8080/record_done;}} }http {server {listen 8080;location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /path/to/nginx-rtmp-module/;}location /control {rtmp_control all;}#location /publish {# return 201;#}#location /play {# return 202;#}#location /record_done {# return 203;#}location /rtmp-publisher {root /path/to/nginx-rtmp-module/test;}location / {root /path/to/nginx-rtmp-module/test/www;}} }3 . RTMP 配置模塊 : 下面是專門配置 RTMP 的模塊 ;
① server : 表示服務(wù)器 ;
② listen 1935 : 表示其監(jiān)聽 1935 端口號(hào) , HTTP 協(xié)議默認(rèn)端口是 80, RTMP 協(xié)議的默認(rèn)端口是 1935 ;
③ application myapp : 對(duì)應(yīng) RTMP 地址中的應(yīng)用 , 如下所示 ;
④ live on : 啟動(dòng)直播 ;
⑤ drop_idle_publisher 5s : 閑置 5 秒以上的連接會(huì)被丟棄 ;
⑥ RTMP 地址示例 : rtmp://192.168.1.15:1935/myapp ;
//RTMP 地址格式 rtmp://IP地址:端口號(hào)/應(yīng)用名稱⑦ RTMP 配置示例 :
rtmp {server {listen 1935;application myapp {live on;drop_idle_publisher 5s;#record keyframes;#record_path /tmp;#record_max_size 128K;#record_interval 30s;#record_suffix .this.is.flv;#on_publish http://localhost:8080/publish;#on_play http://localhost:8080/play;#on_record_done http://localhost:8080/record_done;}} }4 . HTTP 模塊配置 : 需要修改 333 個(gè)位置 , /path/to/nginx-rtmp-module/ 替換為真實(shí)的 nginx-rtmp-module 目錄 , 即 /root/rtmp/nginx-rtmp-module-1.2.1/
http {server {listen 8080;location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {#root /path/to/nginx-rtmp-module/;root /root/rtmp/nginx-rtmp-module-1.2.1/;}location /control {rtmp_control all;}#location /publish {# return 201;#}#location /play {# return 202;#}#location /record_done {# return 203;#}location /rtmp-publisher {#root /path/to/nginx-rtmp-module/test;root /root/rtmp/nginx-rtmp-module-1.2.1/test;}location / {#root /path/to/nginx-rtmp-module/test/www;root /root/rtmp/nginx-rtmp-module-1.2.1/test/www;}} }5 . 端口檢查 : 該 Nginx RTMP 服務(wù)器啟動(dòng)后 , 需要使用 8080 和 1935 兩個(gè)端口 , 確保這兩個(gè)端口可以使用 ;
lsof -i:8080 lsof -i:19356 . 最終配置文件 : user root; 是必須的 , 如果在 root 用戶下啟動(dòng) Nginx , 必須配置該選項(xiàng) ; 非 root 用戶啟動(dòng) Nginx 服務(wù)器 , 配置 user nobody;
user root; worker_processes 1;error_log logs/error.log debug;events {worker_connections 1024; }rtmp {server {listen 1935;application myapp {live on;}} }http {server {listen 8080;location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /root/rtmp/nginx-rtmp-module-1.2.1/;}location /control {rtmp_control all;}location /rtmp-publisher {root /root/rtmp/nginx-rtmp-module-1.2.1/test;}location / {root /root/rtmp/nginx-rtmp-module-1.2.1/test/www;}} }六、 修改 Nginx 和 RTMP Module 權(quán)限
啟動(dòng)時(shí)出現(xiàn) 403 錯(cuò)誤 , 懷疑是文件權(quán)限不足 , 這里將 nginx-1.15.3 和 nginx-rtmp-module-1.2.1 賦予所有的權(quán)限 ;
root@octopus:~/rtmp# chmod -R 777 nginx-1.15.3 root@octopus:~/rtmp# chmod -R 777 nginx-rtmp-module-1.2.1七、 虛擬機(jī)網(wǎng)絡(luò)配置
配置虛擬機(jī)網(wǎng)絡(luò) : 使用 橋接模式 , 這樣虛擬機(jī)相當(dāng)于局域網(wǎng)中的一個(gè)服務(wù)器 , 局域網(wǎng)內(nèi)的手機(jī)可以與該服務(wù)器 ( 虛擬機(jī) ) 通信 ;
八、 啟動(dòng) Nginx 服務(wù)器
1 . Nginx 服務(wù)器路徑 : /root/rtmp/nginx-1.15.3/bin/sbin/nginx
2 . 啟動(dòng) Nginx 服務(wù)器 : 需要在 nginx-1.15.3 目錄下啟動(dòng) , 因?yàn)橐檎?logs/error.log 日志文件 , 只有在該目錄下 , 才能按照 logs/error.log 路徑查找到該錯(cuò)誤日志文件 ;
root@octopus:~/rtmp/nginx-1.15.3# bin/ conf/ html/ logs/ sbin/ root@octopus:~/rtmp/nginx-1.15.3# bin/sbin/nginx root@octopus:~/rtmp/nginx-1.15.3#3 . 啟動(dòng)失敗示例 : 在 nginx-1.15.3/bin 目錄下啟動(dòng) , 報(bào)錯(cuò)信息 ;
root@octopus:~/rtmp/nginx-1.15.3/bin# ./sbin/nginx nginx: [alert] could not open error log file: open() "./bin/logs/error.log" failed (2: No such file or directory) 2020/06/08 23:22:02 [emerg] 79171#0: open() "./bin/conf/nginx.conf" failed (2: No such file or directory) root@octopus:~/rtmp/nginx-1.15.3/bin#4 . 啟動(dòng)后查看端口號(hào) :
lsof -i:1935 命令 , 查看當(dāng)前 1935 端口的應(yīng)用 ;
lsof -i:8080 命令 , 查看當(dāng)前 8080 端口命令 ;
root@octopus:~/rtmp/nginx-1.15.3# /root/rtmp/nginx-1.15.3/bin/sbin/nginx root@octopus:~/rtmp/nginx-1.15.3# lsof -i:1935 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 86054 root 6u IPv4 277762 0t0 TCP *:1935 (LISTEN) nginx 86055 root 6u IPv4 277762 0t0 TCP *:1935 (LISTEN) root@octopus:~/rtmp/nginx-1.15.3# lsof -i:8080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 86054 root 7u IPv4 277763 0t0 TCP *:http-alt (LISTEN) nginx 86055 root 7u IPv4 277763 0t0 TCP *:http-alt (LISTEN) root@octopus:~/rtmp/nginx-1.15.3#5 . 瀏覽器訪問 RTMP 服務(wù)器端 : 在瀏覽器端訪問 虛擬機(jī)中的 RTMP 服務(wù)器 , 地址是 http://192.168.1.15:8080/ ;
總結(jié)
以上是生活随笔為你收集整理的【Android RTMP】RTMP 直播推流服务器搭建 ( Ubuntu 18.04.4 虚拟机 )的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Netty】Netty 核心组件 (
- 下一篇: 【Android RTMP】Androi