rtmp

本文详细介绍了在CentOS系统上安装NGINX的过程,包括必要的GCC、PCRE、ZLIB、OpenSSL等依赖库的安装,以及RTMP模块的添加。同时,提供了配置示例,涵盖HTTP与RTMP服务的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统 virtualbox 上安装的centos

一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

yum -y install gcc gcc-c++

二. PCRE pcre-devel 安装

PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

yum install -y pcre pcre-devel

三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

yum install -y zlib zlib-devel

四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

yum install -y openssl openssl-devel

五、安装nginx 跟rtmp模块
1.官网下载直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html

2.解压

tar -zxvf nginx-1.13.8.tar.gz
  1. 下载rtmp 模块, nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module

  2. 安装nginx跟rtmp模块

    ./configure --prefix=/usr/local/nginx --add-module=…/nginx-rtmp-module --with-http_ssl_module

    make & make install

6.修改配置文件。进入 /usr/local/nginx/conf 文件夹。增添rtmp部分

worker_processes  1;
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 / {  
        add_header Cache-Control no-cache;
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        add_header 'Access-Control-Allow-Headers' 'Range';
        root   /var/www/html;  
        index  index.html index.htm;  
    }  
    error_page   500 502 503 504  /50x.html;  
    location = /50x.html {  
        root   html;  
    }  
}
}

rtmp {    
    
    server {    
        listen 1935;  #监听的端口  
        chunk_size 4000;    
        application hls {  #rtmp推流请求路径  
            live on;    
            hls on;    
            hls_path /var/www/html/hls;    
            hls_fragment 5s;    
        }    
    }    
}  

7.重启电脑。进入 /usr/local/nginx/sbin文件夹,执行./nginx启动nginx

安装ffmpeg

sudo apt-get install ffmpeg

推流

ffmpeg -re -i test.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://10.11.0.32:1935/hls

使用vlc播放

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值