ffmpeg+nginx+video实现rtsp流转hls流,通过H5查看监控视频

一、FFmpeg下载:http://ffmpeg.zeranoe.com/builds/ 
下载并解压FFmpeg文件夹,配置环境变量:在“Path”变量原有变量值内容上加上d:\ffmpeg\bin,验证:ffmpeg -version 出现版本号则成功。
二、官网下载windows  Stable version版Nginx安装nginx服务器,配置:config和mime.types。
1.在nginx\conf\nginx.conf中:
  http {
     include       mime.types;
     default_type  application/octet-stream;
     sendfile        on;
     keepalive_timeout  65;
     access_log off;
    server {
修改:    
    listen       20000;
        server_name  localhost;
       修改:
         location / {
            root   html;
            index  index.html index.htm;
        }

为了能访问到hls流协议新增:


location /hls {  
types{  
application/vnd.apple.mpegurl m3u8;  
video/mp2t ts;  
}  
root html;  
add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;

 }  


或者解决跨域完整的配置,http块的server块内,增加:

 
 
location /hls { # Disable cache add_header Cache-Control no-cache; # CORS setup add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Expose-Headers' 'Content-Length'; # allow CORS preflight requests if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root html; }


2.在nginx\conf\mime.types中
为了支持hls流协议新增:
application/x-mpegURL m3u8; 
application/vnd.apple.mpegurl m3u8;

video/mp2t   ts;


mac下nginx目录:/usr/local/Cellar/nginx 和 /usr/local/etc/nginx

mac下ffmpeg目录:/usr/local/Cellar/ffmpeg


3.在命令行中输入即可转换:也可写成脚本的形式运行。


ffmpeg -i "rtsp://admin:slkj0520@192.168.0.100:554/h264/ch1/main/av_stream"  -vcodec copy -acodec aac -ar 44100 -strict -2 -ac 1 -f hls -s 1280x720 -q 10 -hls_wrap  15 D:/app/nginx-1.12.2/html/hls/slkj.m3u8 (ok)


三、在H5中查看:

1.引进:

 <link href="videolive/css/video.css" rel="stylesheet">
  <script src="videolive/js/video.js"></script>
  <script src="videolive/js/videojs-live.js"></script>

  2.使用video则可以在pc机浏览器上查看视频:

  <video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="500" height="500" 
  data-setup='{}'>
    <source src="http://192.168.10.245:20000/hls/test.m3u8" type="application/x-mpegURL"> 
  </video> 

三、在JAVA代码中查看方法

List<String> commend = new ArrayList<String>();
        commend.add("ffmpeg");
        commend.add("-i");
        commend.add("\""+"rtsp://admin:ajb123456@192.168.10.36"+"\"");
        commend.add("-c");
        commend.add("copy");
        commend.add("-f");
        commend.add("hls");
        commend.add("-hls_time");
        commend.add("2.0");
        commend.add("-hls_list_size");
        commend.add("0");
        commend.add("-hls_wrap");
        commend.add("15");
        commend.add("C:/wjanzhuang/nginx/html/hls/hls1/test.m3u8");
        try {
            ProcessBuilder builder = new ProcessBuilder(); //创建系统进程
            builder.command(commend);
            builder.start();//启动进程
        } catch (Exception e) {
            e.printStackTrace();
        }

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值