您的位置:首页 > 运维架构 > Nginx

nginx+ ffmpeg 实现 hls直播和点播

2016-05-17 00:00 591 查看
摘要: nginx+ ffmpeg hls直播和点播

一、搭建http服务器:

./configure --add-module=/home/andrew/Work/tools/nginx-rtmp-module --with-http_dav_module --without-http_rewrite_module

make && make install

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Nginx.conf配置:

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {

listen       80;

server_name  localhost;

location / {

root   html;

index  index.html index.htm;

client_body_temp_path  /usr/local/nginx/html/tmp;

dav_methods  PUT DELETE MKCOL COPY MOVE;

create_full_put_path   on;

dav_access             group:rw  all:r;

}

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root /home/andrew/Work/tools/nginx-rtmp-module;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

rtmp {

server {

listen 1935;

chunk_size 4096;

application myapp {

live on;

record all;

record_path /tmp/;

recorder all {

record all;

record_suffix -%d-%b-%y-%T.flv;

}

}

}

}


二、拉hls点播文件

将转封装后的m3u8文件存储到/usr/local/nginx/html目录下,通过ffmpeg可以拉到hls文件,即

./ffmpeg -f hls -i http://127.0.0.1/test2.m3u8 -y test2.mp4

三、拉hls直播文件

以直播的方式推流到流媒体服务器的某个路径

./ffmpeg -i test2.flv -y -f hls /usr/local/nginx/html/test2.m3u8

以直播的方式从流媒体服务器拉流,并转码后回推到该流媒体服务器

./ffmpeg -f hls -i http://192.168.40.131/test2.m3u8 -vcodec copy -f flv rtmp://192.168.40.131:1935/myapp/stream1

注释:

-f hls 可以省略
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息