一、Ffmpeg
1.安装ffmpeg依赖库
1) 安装 libmp3lame.so
# cd lame-3.99.5
# ./configure
# make;make install
2) 安装 librtmp.so
# cd rtmpdump
# make CRYPTO=;make install
3) 安装 libspeex.so
# cd speex-1.2rc1
# ./configure
# make;make install
4) 环境变量配置
# export PKG_CONFIG=/usr/bin/pkg-config/
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
5) 修改 librtmp.pc
# vim /usr/local/lib/pkgconfig/librtmp.pc
替换所有内容如下:
prefix=/mingw
exec_prefix=${prefix}i
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: librtmp
Description: RTMP implementation
URL: http://rtmpdump.mplayerhq.hu
Version: v2.4
Requires.private:
Libs: -L${libdir} -L@OPENSSLLIB@ -lrtmp
Libs.private: -lws2_32 -lwinmm -lgdi32 -lm
Cflags: -I${includedir}
确认修改成功,运行:
# pkg-config --exists librtmp||echo no
当输出不为 no 时表示修改成功。
2.安装ffmpeg动态库
# cd ffmpeg
# ./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-librtmp --enable-libspeex --disable-yasm --enable-libmp3lame
make;make install
3.配置环境变量
1) 修改 /etc/profile
# vim /etc/profile
添加内容:
FFMPEG_HOME=/usr/local/ffmpeg
PATH=$PATH:$FFMPEG_HOME/bin
export PATH
修改生效
# source /etc/profile
2) 修改 /etc/ld.so.conf
# vim /etc/ld.so.conf
在include ld.so.conf.d/*.conf后面添加:
/usr/local/lib/
/usr/local/ffmpeg/lib/
执行 ldconfig 使 /etc/ld.so.conf 修改生效:
# ldconfig
4.安装g++
# yum -y install gcc-c++
二、安装nginx
参考网址:
1.下载源码
# mkdir nginx #创建源码目录 后面的源码都放在这个目录
# cd nginx
# yum -y install git #安装git
# wget http://nginx.org/download/nginx-1.16.0.tar.gz #从github服务器上将nginx的源代码下载下来
# git clone https://github.com/arut/nginx-rtmp-module.git #将rtmp模块的源码下载下来
wget https://www.openssl.org/source/openssl-1.1.0.tar.gz #下载OpenSSL源码包
wget https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz #下载pcre源码包
wget http://www.zlib.net/zlib-1.2.11.tar.gz #下载zlib包源码
#tar -zxvf 包名 #解压各个包源码
2. 编译
# cd nginx
# ./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.39 --with-openssl=../openssl-1.1.0 --with-zlib=../zlib-1.2.11 --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_v2_module --with-http_flv_module --with-http_mp4_module --add-module=../nginx-rtmp-module
# make;make install
3. 启动nginx
# /usr/local/nginx/sbin/nginx
停止nginx
# /usr/local/nginx/sbin/nginx -s stop
4.配置nginx.conf文件
rtmp {
server {
listen 1935;
#直播
application live {
live on;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
}
#点播
application vod {
play /tmp/video;
}
}
}
然后,针对hls,还需要在http里面增加一个location配置
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
具体配置可查看:
https://blog.csdn.net/code_better/article/details/54898098
重新加载nginx:
#/usr/local/nginx/sbin/nginx -s reload
5.查看1935和8080端口是否开启(若没开启,可以启动的是其他目录的nginx)
#netstat -natplu
rtmp流和hls流推流
第一个是rtmp流,推到了上面配置的live上:
ffmpeg -re -i "rtsp://admin:admin@192.168.xx.xx:554/h264/ch1/main/av_stream" -vcodec h264 -an -f flv -s 1280x720 -q 10 rtmp://192.168..xx.xx:1935/live/test
第二个HLS流,推送到hls上:
ffmpeg -re -i "rtsp://admin:admin@192.168.xx.xx:554/h264/ch1/main/av_stream" -vcodec h264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://192.168.xx.xx:1935/hls/test
直播拉流地址:
RTMP流:rtmp://192.168.xx.xx:1935/rtmplive/test
HLS流:http://192.168.xx.xx:8080/hls/test.m3u8
6.hls点播ffmpeg切片ts(可选)
在/usr/local/nginx/html目录下通过rz命令放入1.mp4文件
# ffmpeg -y -i 1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts
# ffmpeg -i 1.ts -c copy -map 0 -f segment -segment_list test.m3u8 -segment_time 5 a-%03d.ts