您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
centos7搭建rtmp流媒體服務器
发布时间:2022-03-26 20:35:00编辑:雪饮阅读()
這裏以nginx1.18.0爲例
下載nginx1.18.0后我們解壓之
然後我們還要下載一個nginx模塊,這個模塊就是負責媒體服務器相關的,rtmp就可以用這個模塊來實現
這個模塊下載后也解壓,解壓路徑記住,後面編譯nginx1.18.0時候就要用
編譯nginx1.18.0
那麽接下來我們來到剛才下載的nginx1.18.0解壓后的目錄中進行編譯
./configure --prefix=/usr/local/nginx1180rtmp --add-module=/usr/local/src/nginx-rtmp-module
這裏—prefix自然就是nginx編譯后的存放目錄
--add-module就是指定要增加的那個模塊,也就是上面我們下載的這個流媒體模塊rtmp模塊的路徑(解壓后)。
然後就是常規的
make && make install
配置rtmp流媒體服務器
由於我本地已經有另外一個nginx占用了80服務,所以這次這個nginx.conf中默認監聽端口我修改為8080,同時rtmp服務我這裏監聽為82端口。
那麽rtmp服務需要指定一個application名稱,我這裏指定為app1,於是乎我這裏的配置如:
[root@localhost nginx-1.18.0]# cat /usr/local/nginx1180rtmp/conf/nginx.conf
#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;
}
rtmp {
server {
listen 82;
chunk_size 4096;
application app1 {
live on;
}
}
}
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 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;
# }
#}
}
那麽接下來我們就是啓動咱們的這個新的nginx服務器
/usr/local/nginx1180rtmp/sbin/nginx
推流
windows上面我采用ffmpeg推流(應該說大多數場景都是ffmpeg推流,應該沒有自己造輪子吧?)
那麽這裏我推流地址就是在rtmp流媒體服務器地址後面增加一個新字段,稱之為name。
基於上面我的配置,則我的rtmp流媒體的地址就是rtmp://192.168.43.170:82/app1
那麽再增加一個推流name,我定義為name1,則實際推流地址就是rtmp://192.168.43.170:82/app1/name1
那麽在ffmpeg中推流如:
ffmpeg -re -i D:\BaiduNetdiskDownload\0.mp4 -vcodec libx264 -acodec aac -f flv rtmp://192.168.43.170:82/app1/name1
ffmpeg參數説明:
默认情况下,ffmpeg尝试以尽可能快的速度读取输入。
-re这个选项会将输入的读取速度降低到输入的本地帧速率。它对于实时输出(例如直播流)很有用。
看到的直播流就跳帧严重,半小时的视频,1分钟就播完了。加上-re之后就好多了。
-vcodec指定視頻編碼,libx264我的理解就是h.264,flv就是一種專門在網絡中傳輸速度比較快的視頻格式,所以要最後-f時候指定為flv,而指定flv時候若-vcodec 直接是copy我理解的就是視頻編碼保持原視頻編碼,那麽這樣在ffmpeg控制臺是會報錯的。
-acodec 指定音頻編碼,這裏音頻編碼對於flv來説常見搭配都是aac
最後一個沒有指定參數名僅僅指定了參數值,這個參數值就是輸出路徑,而該路徑也支持一個網絡地址,只要該網絡地址支持接收ffmpeg輸出的流即可。
測試rtmp服務器(拉流)
那麽推流后接下來就是拉流了。拉流這裏可以使用VLC media player
“媒體=》打開網絡串流”會彈出“打開媒體”的窗口
這裏會列出一些網絡協議樣例,雖然裏面沒有包含rtmp,但是在“請輸入網絡 URL”処輸入我們上面推流的地址
rtmp://192.168.43.170:82/app1/name1
然後點擊播放,會發現可以正常拉流播放了。

关键字词:centos7,rtmp,流媒體
相关文章
- webrtc實戰實現端對端即p2p視頻通話-turn服務器搭建
- centos7编辑GRUB_CMDLINE_LINUX
- 解決centos7二進制方式安裝docker啓動dockerd報錯中包
- centos7二进制安装docker及docker hello world项目运
- workerman服務治理系列之workerman服务(脚本)自启动(开机
- workerman作爲客戶端系列之socket5即s5代理搭建基於ce
- centos7全局安装composer
- centos7下redis配置远程连接
- centos7.6编译安装php7.2及整合mysql5.7与httpd2.4.9
- mysql5.7在centos7.6中的二进制源码包安装