ffmpeg+HLS实现直播与回放
Nginx配置视频服务器
server { listen 28024; server_name localhost; location /hls{ add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; types{ application/vnd.apple.mpegurl m3u8; video/mp2t ts; } alias /data/hls; expires -1; add_header Cache-Control no-cache; } access_log off; } }
FFmpeg拉流转码
ffmpeg -re -rtsp_transport tcp -i 'rtsp://{IP}:9090/dss/monitor/params?cameraid={设备ID}${管道}&substream={码流}' \
-c copy -map 0 -f segment -segment_list /data/hlstest.m3u8 -segment_list_flags +live -segment_time 10 -hls_list_size 20 /data/hls/output%03d.ts
-segment_list 配置输出的列表文件名
-segment_time 切片时长
-hls_list_size 保存最后切片数量
FFmpeg拉流推送HLS服务
ffmpeg -re -rtsp_transport tcp -i 'rtsp://112.85.138.10:9090/dss/monitor/params?cameraid=1000401$0&substream=1' \
-vcodec copy -vprofile baseline -f flv -s 1280x720 -segment_list_flags +live -segment_time 10 -hls_list_size 20 'rtmp://192.168.200.31:28099/hls/test2'
-segment_list 配置输出的列表文件名
-segment_time 切片时长
-hls_list_size 保存最后切片数量
HLS服务Nginx服务器
1下载nginx-rtmp-module
yum install git
git clone https://github.com/arut/nginx-rtmp-module.git
2下载编译nginx
yum -y install pcre-devel openssl openssl-devel gcc gcc-c++
wget http://nginx.org/download/nginx-1.8.1.tar.gz tar -zxvf nginx-1.8.1.tar.gz cd nginx-1.8.1 ./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module make && make install
3修改nginx.conf
worker_processes 8;
events {
worker_connections 1024;
}
rtmp {
server {
listen 28011;
chunk_size 4000;
# TV mode: one publisher, many subscribers
application mylive {
# enable live streaming
live on;
}
application hls {
live on;
hls on;
hls_path /data/hls;
hls_fragment 5s;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 28012;
server_name localhost;
location /hls{
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias /data/hls;
expires -1;
add_header Cache-Control no-cache;
}
}
access_log off;
}
相关技术推荐
视频拉流 Linux安装FFmpeg
海康&大华&DSS视频拉流-RTSP转RTMP多媒体播放技术
广告植入
C:\>ffmpeg.exe.lnk -i C:\Users\Administrator\Desktop\视频\zhgd.mp4 -c:v libx264 -c:a aac -strict -2 -hls_list_size 0 -t 1:30 -hls_time 10 -f hls c:/test.m3u8
加微信:wonter 发送:技术Q
医疗微信群:
加微信:wonter 发送:医疗Q
更多文章关注公众号:
![](https://images.cnblogs.com/cnblogs_com/Javame/604499/o_cto.png)