一、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 *;
}
2.在nginx\conf\mime.types中
為了支持hls流協議新增:
application/x-mpegURL m3u8;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
3.在命令行中輸入即可轉換:也可寫成腳本的形式運行。
ffmpeg -i "rtsp://admin:ajb123456@192.168.10.36" -c copy -f hls -hls_time 2.0 -hls_list_size 0 -hls_wrap 15 C:/wjanzhuang/nginx/html/hls/test.m3u8
三、在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();
}