準備工具:IPCAMERA網頁高清攝像頭一個,nginx-rtmp-win32-master.zip ,FFMPEG
開始幹活:
1、先解壓nginx-rtmp-win32-master,這裡面內建了,這個比較簡單,找個合适的地方,直接解壓,解壓後的樣子是這樣的
看到nginx.exe了不,二話不說。直接運作就ok了,忘了 說一句,nginx預設配置需要用到8080和1935端口,如果想改端口,在conf目錄下邊有nginx.conf這個檔案,打開之後,就能看到了,改完端口以後,記得重新重新啟動一下nginx伺服器。貌似沒有重新啟動這一項啊,那就點選stop.bat,然後再點選nginx.exe。附上nginx.conf:
worker_processes 4;
#切換自動推送(多 worker 直播流)模式。預設為 off
rtmp_auto_push on;
#當 worker 被幹掉時設定自動推送連接配接逾時時間。預設為 100 毫秒
rtmp_auto_push_reconnect 1s;
error_log logs/error.log debug;
worker_rlimit_nofile 51200;
events {
worker_connections 51200;
}
rtmp {
server {
listen 1935;
application live {
#live on;
live on;
hls on;
hls_path temp/hls;
hls_fragment 20s;
hls_playlist_length 3000s;
hls_cleanup off;
idle_streams off;
publish_notify on;
drop_idle_publisher 70s;
record_unique off;
#record keyframes;
wait_video off;
interleave on;
wait_key off;
record all;
record_path temp/hls;
record_interval 3600s;
}
application hls {
live on;
hls on;
hls_path temp/hls;
hls_fragment 1s;
}
}
}
http {
server {
listen 8080;
location / {
root html;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root html;
}
location /hls {
#server hls fragments
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias temp/hls;
expires -1;
}
}
}
2、接下來就來安裝ffmpeg.沒啥好說的,找個合适的位置,直接下一步就ok。安裝完成記得看看環境變量裡面有沒有ffmpeg的配置。安裝完成以後,cmd裡面直接輸入ffmpeg
如圖:即為安裝成功了。
3、重頭戲來了,搞攝像頭。小弟是一搞android的,由于公司人手有限,才臨時客串一下。由于第一次搞,手忙腳亂的,都不知道怎麼擷取流。接下來我就不厭其煩的問度娘了。
1),先問度娘攝像頭怎麼連接配接我電腦。怎麼才能讓我連接配接上去呢。找到一件法器:ONVIF Device Test Tool。百度下載下傳安裝就行,點選打開軟體,界面是這樣的,點選discover devices,在下面就顯示裝置了,不知道為什麼有兩個,明明我就一個裝置,有大神知道的,可以聯系我Q278357251。右邊顯示一些攝像頭的基本資訊
點選
2)話不多說,直接畫步驟:
備注一下:第五步就能看到視訊了,1920x1080,高清無碼,咳咳,說多了。第六步拿到rtsp流位址。咱們就要這玩意。
3、拿到視訊流了,咱們就該轉碼播放了,rtsp目前在不安裝插件的情況下是不可以直接在網頁上面播放的,需要轉成網頁上可以播放的視訊格式才可以。
1)轉碼,把rtsp轉成rtmp推送到nginx的伺服器1935上面
在cmd裡面輸入:
ffmpeg -i rtsp://192.xxx.xxx.103:554/live1.264 -c:a copy -c:v libx264 -f flv rtmp://127.0.0.1:1935/live/stream
指令具體參數客戶參考官網 :http://ffmpeg.org/documentation.html
2)打開 http://127.0.0.1:8080,按照步驟,看到以下界面
備注:說明咱們轉碼推流成功了,由于這是自帶的測試demo,界面不要就怎麼改了。索性不改了。
打開我的phpstudy。找個jwplayer,,然後複制一下rtmp拉流位址,運作如下:代碼一會附上
ok,完畢
所用到部分資源,其他的可以百度下載下傳到:
https://download.csdn.net/download/qq_22802643/10332752