转码推流服务器搭建

转码推流服务器安装:

基础工具:

yum install lrzsz -y 
yum -y install gcc automake autoconf libtool make gcc gcc-c++ bzip2 xz
yum install unzip -y
yum install gcc-c++ -y
yum install pcre pcre-devel -y
yum install zlib zlib-devel -y 
yum install openssl openssl-devel -y
yum install wget
yum install vim 

nasm和yasm安装:

创建文件夹 yasm
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -zxvf  yasm-1.3.0.tar.gz
cd yasm-1.3.0 
./configure
make && make install
创建文件夹 nasm
wget http://www.nasm.us/pub/nasm/releasebuilds/2.13/nasm-2.13.tar.gz
tar -zxvf  nasm-2.13.tar.gz
cd nasm-2.13
./configure
make && make install

x264安装

在/usr/local目录
​
yum install git
git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-shared  --enable-static --disable-asm
make && make install

ffmpeg工具安装:

在/usr/local/创建ffmpeg文件夹,并进入.
​
wget http://www.ffmpeg.org/releases/ffmpeg-4.1.tar.gz
tar -zxvf ffmpeg-4.1.tar.gz
cd ffmpeg-4.1
./configure --enable-gpl --enable-libx264 (绑定libx264)
make && make install
​
vim /etc/ld.so.conf  末行添加/usr/local/ffmpeg/lib
​
#刷新配置命令
ldconfig
​
ffmpeg -version  报错
ffmpeg: error while loading shared libraries: libx264.so.164: cannot open shared object file: No such file or directory
报错处理:whereis ibx264.so.164  找文件位置.
也可以进入 /usr/local/ffmpeg/ffmpeg-4.1目录,使用ldd ffmpeg  查询缺失依赖包.
​
​
vim /etc/profile
在最后PATH添加环境变量:
#export PATH=$PATH:/usr/local/ffmpeg/bin  (适用于下载的ffmpeg有bin目录的)
export LD_LIBRARY_PATH=/usr/local/lib/
保存退出
查看是否生效
source /etc/profile  设置生效
​

下载nginx及模块包:

mkdir /usr/local/nginx
cd /usr/local/nginx
​
wget https://nginx.org/download/nginx-1.14.2.tar.gz
https://github.com/winshining/nginx-http-flv-module(通过github下载后上传到nginx文件夹)
​
tar -zvxf nginx-http-flv-module-master.tar.gz -C /usr/local/nginx
tar -zvxf nginx-1.14.2.tar.gz -C /usr/local/nginx
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx  --add-module=/usr/local/nginx/nginx-http-flv-module-master
make && make install

配置nginx的配置文件:

user root;
worker_processes auto;
#worker_processes 2;
#worker_cpu_affinity 01 10;
pid /run/nginx.pid;
​
events {
    worker_connections  1024;
}
​
http {
    include       mime.types;
    default_type  application/octet-stream;
​
    sendfile        on;
​
    keepalive_timeout  65;
​
    server {
    listen 1111;
    server_name localhost;
    
    location / {
        root html;
        index index.html;
        try_files $uri $uri/ /index.html;
    }
    }
​
    server {
        location /live { #推流后访问入口
            flv_live on;
            chunked_transfer_encoding on;
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
        }
    }
}
​
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
​
rtmp {
    out_queue           4096;
    out_cork            8;
    max_streams         128;
    timeout             15s;
    drop_idle_publisher 15s;
​
    server {
​
        listen 1935;
        application http_flv {
            live on;
            record off;
        gop_cache off;
        }
    }
}
​

进入nginx的sbin目录,启动nginx.

网络流地址:

rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4

推流地址:

ffmpeg -re -rtsp_transport tcp -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4 -vcodec libx264 -an -f flv -s 960x540 rtmp://192.168.10.98:1935/http_flv/tower

http_flv对应nginx配置文件application的名称.

tower是流的名称.

拉流地址:

方式一:

rtmp://192.168.10.98:1935/http_flv/tower

方式二:

http://192.168.10.98/live?port=1935&app=http_flv&stream=tower

live对应推流后的访问入口.

http_flv对应http_flv对应nginx配置文件application的名称和推流中的http_flv.

tower是流的名称.

流停止(注意nginx要环境变量,nginx服务停止就可以)

vim /etc/profile

source /etc/profile

末尾上 export PATH=$PATH:/usr/local/nginx/sbin

nginx结束命令 nginx -s stop

  • 33
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ffmpeg是一个用于处理多媒体数据的开源软件,可以进行音视频的录制、转码、处理和推流等操作。而Nginx是一个轻量级的Web服务器和反向代理服务器,可以用于搭建RTMP服务器来进行视频推流。 要使用ffmpeg进行推流,首先需要安装ffmpeg软件,并且确保摄像头设备已连接到计算机上。然后通过执行推流命令,指定输入的视频设备、编码方式、推流地址等参数,即可将视频数据推送到指定的RTMP服务器。 在Linux系统下,可以使用以下命令将本地视频文件推流到RTMP服务器: ffmpeg -i /dev/video0 -codec libx264 -g 10 -f flv rtmp://192.168.137.9:1935/live/stream0 这个命令中,/dev/video0代表输入的视频设备,-codec libx264指定使用libx264编码器,-g 10表示每10帧进行一次关键帧的设置,-f flv指定输出格式为FLV,而rtmp://192.168.137.9:1935/live/stream0则是指定的RTMP服务器地址和推流路径。 如果希望通过ffplay来拉流播放,可以使用以下命令: ffplay rtmp://192.168.137.9:1935/live/stream0 这个命令中,rtmp://192.168.137.9:1935/live/stream0是指定的RTMP服务器地址和推流路径。 同时,为了在Nginx中配置RTMP服务器,需要编辑Nginx的配置文件,在其中添加RTMP服务器的相关配置。具体操作如下: 1. 打开Nginx的配置文件:vi /usr/local/nginx/conf/nginx.conf 2. 在对应位置添加如下内容: rtmp { server { listen 1935; #监听的端口(默认) chunk_size 4096; #数据传输块的大小(默认) application video { play /opt/nginx/video; #视频文件存放的位置,访问方式: rtmp://localhost:1935/video } } } 以上就是使用ffmpeg和Nginx进行推流的方法。如果还有其他问题,请随时提出。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值