一.安装ffmpeg
二.搭建rtmp推流环境
1.下载nginx-rtmp-module
nginx-rtmp-module是一个nginx的插件,让nginx可支持rtmp协议。
链接:nginx-rtmp-module插件下载链接
提取码:w771
下载完成后进行解压,然后放在和nginx安装目录(不是nginx解压目录)同一等级下。
2.安装包含nginx-rtmp-module模块的nginx
注意:参考linux(centos)下安装nginx安装时,有一处命令要修改,既安装nginx时带上nginx-rtmp-module模块。
把下图中的./configure命令改为:
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
3.安装完成后目录结构
三.在nginx配置文件配置rtmp
在nginx.conf文件加上如下代码:
rtmp{
server {
listen 1935;
chunk_size 4000;
application live {
live on;
record off;
allow play all;
}
}
}
下面是完整的配置文件:
#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;
include vhosts/*.conf;
#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;
chunk_size 4000;
application live {
live on;
record off;
allow play all;
}
}
}
四.测试
1.把测试视频放在如下位置
2.执行ffmpeg推流命令
ffmpeg -re -i 96c72c9f00dba32ecfc1fa101b2988cd.mp4 -f flv rtmp://182.254.242.219:1935/live
3.使用VLC查看结果