ffmpeg+nginx+x264实现简单推流

nginx(建议重装nginx)

  • 所需依赖
 yum install unzip -y
 yum -y install gcc gcc-c++
 yum install pcre pcre-devel -y  
 yum install zlib zlib-devel -y 
 yum install -y openssl* ncurses-devel pcre-devel
 yum install yasm -y
  • 清理安装nginx+nginx-http-flv-module
#查询正在运行的nginx
ps -ef|grep nginx 
#关闭运行nginx
kill -9 pid
#查询所有nginx文件
sudo find / -name nginx*
#删除所有nginx文件目录
rm -rf /usr/src/nginx/*
#下载nginx
wget http://nginx.org/download/nginx-1.20.0.tar.gz
#下载nginx-http-flv-module
git clone https://github.com/winshining/nginx-http-flv-module.git
#解压
tar -zxvf nginx-1.20.0.tar.gz
#进入nginx目录
cd nginx-1.20.0/
#编译-安装
./configure --prefix=/usr/local/nginx --add-module=../nginx-http-flv-module
make
sudo make install
#复制同步
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#进入nginx/sbin测试启动
/usr/local/nginx/sbin/
./nginx
  • 编辑nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;
        
         # 前端拉流时使用
	      location /video {
            flv_live on;
            chunked_transfer_encoding on;
      			add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
      			add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
      			add_header Access-Control-Allow-Headers X-Requested-With;
      			add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
      			add_header 'Cache-Control' 'no-cache';
        }
        
         location / {
            root   html;
            index  index.html index.htm;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
      
    }
}

rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp {
    max_streams 128;
    timeout 15s;
    drop_idle_publisher 15s;  
    server {  
        listen 1935;  
        chunk_size 4096;
        application myvideo { 
          live on;
		  gop_cache on;
		  #开启录屏
          record off;
        }  
    }  
}

x264(视频流转码,必用,不然会推流失败)

http下载

tar -zxf x264-master.tar.gz
#编译安装
./configure --prefix=/usr/local/x264 --enable-shared --enable-static --enable-debug
#配置环境变量
vim /etc/profile
#新增
export PATH=$PATH:/usr/local/x264/bin
#刷新配置
source /etc/profile
#新增
vim /etc/profile
export PKG_CONFIG_PATH=/usr/local/x264/lib/pkgconfig
source /etc/profile
#新增
vim /etc/ld.so.conf
/usr/local/x264/lib
#刷新配置
ldconfig

ffmpeg

下载地址

#解压
tar -xvjf ffmpeg-snapshot.tar.bz2
#进入目录
cd ffmpeg
#编译配置 
./configure --prefix=/usr/local/ffmpeg  --enable-gpl --enable-libx264
#安装
make && make install
#新增
vim /etc/ld.so.conf,
#新增
/usr/local/ffmpeg/lib
#刷新
ldconfig
#全局配置
vim /etc/profile,
#新增
export PATH=$PATH:/usr/local/ffmpeg/bin
#执行
source /etc/profile
#测试
ffmpeg -version

在这里插入图片描述
如果出现ffmpeg: error while loading shared libraries: libavdevice.so.: cannot open shared object file: No such file or directory异常

#进入ffmpeg目录
cd ffmpeg
#查看需要那些依赖
ldd ffmpeg
#查看缺失依赖位置
find /usr -name 'libavdevice.so.58'
#export出来
export LD_LIBRARY_PATH=/usr/local/lib/
#再次测试
ffmpeg -version

推流

启动nginx,nginx目录的sbin目录下执行./nginx
最后ffmpeg的bin目录下执行命令测试

测试rtsp
ffmpeg -re -rtsp_transport tcp -i “rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4” -f flv -vcodec h264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -q 10 “rtmp://localhost:1935/myvideo/test”

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值