Nginx+ffmpeg+ckplayer海康監控攝像頭在web頁面播放RTSP轉RTMP
阿新 • • 發佈:2019-02-20
#user nobody; 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; } rtmp { server { listen 1935; chunk_size 4000; # TV mode: one publisher, many subscribers application mylive { # enable live streaming live on; } } } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8080; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
第四步啟動伺服器,測試
1:執行cmd命令,啟動nginx-rtmp.exe服務1、啟動: C:\nginx-1.10.2>start nginx-rtmp 或 C:\nginx-1.10.2>nginx-rtmp.exe 注:建議使用第一種,第二種會使你的cmd視窗一直處於執行中,不能進行其他命令操作。 2、停止: C:\nginx-1.10.2>nginx-rtmp.exe -s stop 或 C:\nginx-1.10.2>nginx-rtmp.exe -s quit 注:stop是快速停止nginx,可能並不儲存相關資訊;quit是完整有序的停止nginx,並儲存相關資訊。 3、重新載入Nginx: C:\nginx-1.10.2>nginx-rtmp.exe -s reload 當配置資訊修改,需要重新載入這些配置時使用此命令。
(start nginx-rtmp.exe:啟動nginx服務,然後看程序中是否有nginx-rtmp.exe)
2.開啟網頁輸入:localhost或者127.0.0.1本機ip加埠8080
(顯示一下介面說明啟動成功)
第五步FFMpeg推流
1:海康的攝像頭提供rtsp流地址,格式如下 rtsp://admin:[email protected]:554/Streaming/channels/101,想了解這個rtsp的格式是怎麼拼的,網上有很多資料,不過得找最新的格式,我就被舊的格式給整了半天。3:進入cmd,如圖所示進入到你解壓對應的位置。4:執行命令:rtmp://192.168.1.84:1935/mylive/test2 這個就是剛才部署的nginx了 ,mylive是在conf配置檔案裡面配置的,可以修改,test2可以隨便修改。執行成功如圖:這個時候就可以訪問rtmp流了。5:常用引數說明:主要引數:i 設定輸入流 f 設定輸出格式 ss 開始時間 視訊引數:
b 設定視訊流量,預設為200Kbit/s-r 設定幀速率,預設為25
s 設定畫面的寬與高-aspect 設定畫面的比例
vn 不處理視訊-vcodec 設定視訊編解碼器,未設定時則使用與輸入流相同的編解碼器
音訊引數:
ar 設定取樣率
ac 設定聲音的Channel數
acodec 設定聲音編解碼器,未設定時則使用與輸入流相同的編解碼器an 不處理音訊