Nginx+nginx-rtmp+modul 视频直播点播系统搭建
安装包下载:
Nginx: http://nginx.org/download/nginx-1.5.0.tar.gz nginx-1.5.0.tar.gz
nginx-rtmp+modul:https://github.com/arut/nginx-rtmp-module 下载的是源码
nginx-rtmp-module-master.zip
cd /usr/local/nginx
上传文件到该目录
解压文件
tar -zxvf nginx-1.5.0.tar.gz
unzip nginx-rtmp-module-master.zip
系统需要安装
yum -y install gcc-c++
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
进入目录
cd /usr/local/nginx/nginx-1.5.0
查看 https://github.com/arut/nginx-rtmp-module#build 文档说明确定自己的版本
1.5.0 版本 应该用 一下命令
./configure --add-module=/usr/local/nginx/nginx-rtmp-module-master --with-http_ssl_module
/path/to/nginx-rtmp-module 是 nginx-rtmp+modul 解压后的路径
编译: make
安装: make install
进入 cd /usr/local/nginx 目录下
进入 sbin
./nginx -t 查看当前状态
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
安装成功
配置nginx.conf
进入 /usr/local/nginx/conf目录
打开文件 nginx.conf
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 4000;
application hls {
live on;
hls on;
hls_path /usr/local/nginx/hls;
hls_fragment 5s;
hls_playlist_length 15s;
hls_continuous on;
hls_cleanup on;
hls_nested on;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name 192.168.206.233;
location / {
root html;
index index.html index.htm;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias /usr/local/nginx/hls;
add_header Cache-Control no-cache;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
存后重启 nginx -s reload
问题:nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
或[root@localhost sbin]# kill -9 31263
解决: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
java 测试
import org.bytedeco.javacpp.avcodec;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameGrabber.Exception;
public class App {
public static void main(String[] args) throws Exception, org.bytedeco.javacv.FrameRecorder.Exception {
int noFrame = 0;
boolean err = false;
int width = 670, height = 480;
FFmpegFrameGrabber grabber =new FFmpegFrameGrabber("http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8");
grabber.setOption("rtsp_transport", "tcp");
System.out.println("grabber start");
grabber.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("rtmp://192.168.206.223:1935/hls/cctv6", width, height,1);
recorder.setInterleaved(true);
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setFormat("flv");
recorder.setFrameRate(25);
recorder.setPixelFormat(0);
recorder.setAudioChannels(grabber.getAudioChannels());
recorder.setAudioBitrate(grabber.getAudioBitrate());
System.out.println("recorder start");
recorder.start();
while(noFrame <= 5 && !err) {
System.out.println("8888");
Frame frame = grabber.grabImage();
if(frame == null) {
noFrame ++;
continue;
}
recorder.record(frame);
}
grabber.stop();
grabber.release();
recorder.stop();
recorder.release();
}
}
用 http播放
播放地址: http://192.168.206.223/hls/cctv6/index.m3u8

java 测试所需依赖包
<dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>1.4.4</version> </dependency> <dependency> <groupId>org.bytedeco.javacpp-presets</groupId> <artifactId>ffmpeg-platform</artifactId> <version>4.1-1.4.4</version> </dependency>

浙公网安备 33010602011771号