一、所需資源
1、nginx的Gryphon版本,它內(nèi)部已經(jīng)集成了rtmp的推流編譯(nginx-Gryphon)
2、服務(wù)器狀態(tài)檢查程序stat.xsl(nginx-rtmp-module)
3、ffmpeg(ffmpeg)
4、VLC(VLC)
二、安裝
1、將下載好的nginx 1.7.11.3 Gryphon解壓修改文件名為nginx-1.7.11.3-Gryphon,絕對(duì)路徑中不能有中文,必須全為英文!
2、在根目錄中的conf文件夾中,若有nginx.conf文件,直接進(jìn)入修改;若無(wú),則創(chuàng)建一個(gè)。
3、在nginx文件中,將以下內(nèi)容粘貼。
#user nobody;
# multiple workers works !
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 8192;
# max value 32768, nginx recycling connections+registry optimization =
# this.value * 20 = max concurrent connections currently tested with one worker
# C1000K should be possible depending there is enough ram/cpu power
# multi_accept on;
}
rtmp {
server {
listen 1935;
chunk_size 4000;
application live {
live on;
}
}
}
http {
#include /nginx/conf/naxsi_core.rules;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr:$remote_port - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
# # loadbalancing PHP
# upstream myLoadBalancer {
# server 127.0.0.1:9001 weight=1 fail_timeout=5;
# server 127.0.0.1:9002 weight=1 fail_timeout=5;
# server 127.0.0.1:9003 weight=1 fail_timeout=5;
# server 127.0.0.1:9004 weight=1 fail_timeout=5;
# server 127.0.0.1:9005 weight=1 fail_timeout=5;
# server 127.0.0.1:9006 weight=1 fail_timeout=5;
# server 127.0.0.1:9007 weight=1 fail_timeout=5;
# server 127.0.0.1:9008 weight=1 fail_timeout=5;
# server 127.0.0.1:9009 weight=1 fail_timeout=5;
# server 127.0.0.1:9010 weight=1 fail_timeout=5;
# least_conn;
# }
sendfile off;
#tcp_nopush on;
server_names_hash_bucket_size 128;
## Start: Timeouts ##
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 30;
send_timeout 10;
keepalive_requests 10;
## End: Timeouts ##
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
## Caching Static Files, put before first location
#location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
# expires 14d;
# add_header Vary Accept-Encoding;
#}
# For Naxsi remove the single # line for learn mode, or the ## lines for full WAF mode
location / {
#include /nginx/conf/mysite.rules; # see also http block naxsi include line
##SecRulesEnabled;
##DeniedUrl "/RequestDenied";
##CheckRule "$SQL >= 8" BLOCK;
##CheckRule "$RFI >= 8" BLOCK;
##CheckRule "$TRAVERSAL >= 4" BLOCK;
##CheckRule "$XSS >= 8" BLOCK;
root html;
index index.html index.htm;
}
# For Naxsi remove the ## lines for full WAF mode, redirect location block used by naxsi
##location /RequestDenied {
## return 412;
##}
## Lua examples !
# location /robots.txt {
# rewrite_by_lua '
# if ngx.var.http_host ~= "localhost" then
# return ngx.exec("/robots_disallow.txt");
# end
# ';
# }
#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; # single backend process
# fastcgi_pass myLoadBalancer; # or multiple, see example above
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$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 spdy;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_prefer_server_ciphers On;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!eNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
注:rtmp中的“application live” ,application+空格+live,live即使訪問(wèn)路徑,如localhost:1935/live。
4、在nginx.exe所在的目錄,即根目錄下,進(jìn)入cmd窗口,輸入nginx.exe或.\nginx.exe,啟動(dòng)nginx。
5、可以直接瀏覽器輸入localhost驗(yàn)證是否啟動(dòng)nginx,若出現(xiàn)nginx的主頁(yè)面,則成功。
6、將服務(wù)器狀態(tài)檢查程序解壓,放到nginx根目錄下。
7、將ffmpeg解壓后,將其bin目錄添加環(huán)境變量。
8、安裝VLC
三、ffmpeg推流
ffmpeg推流是為了確定nginx的1935端口已打開并運(yùn)行rtmp推流功能,以排除故障等問(wèn)題。
1、在測(cè)試視頻所在文件夾打開cmd窗口,輸入指令 ffmpeg.exe -re -i .\視頻名.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/live
2、若出現(xiàn)以下畫面則推流失敗,是因?yàn)閚ginx的1935端口未開啟,或是rtmp未推流。
3、若出現(xiàn)以下畫面,則成功,frame, fps等信息會(huì)不斷地變化。
4、打開VLC,在左上角媒體中選擇 打開網(wǎng)絡(luò)串流 ,在網(wǎng)絡(luò)URL中輸入rtmp://127.0.0.1:1935/live,點(diǎn)擊播放。
5、若是顯示出視頻,則成功。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-439094.html
四、無(wú)人機(jī)rtmp推流
1、保證電腦和無(wú)人機(jī)遙控器(或遙控器連接的手機(jī))在同一局域網(wǎng)中(即同一路由器或熱點(diǎn))。
2、電腦確認(rèn)ip地址,打開cmd窗口輸入命令ipconfig,確定電腦ip地址。
3、無(wú)人機(jī)進(jìn)入自定義直播功能中,輸入地址,一般為 rtmp://192.168.x.x:1935/live 或 rtmp://10.0.x.x:1935/live。
4、打開VLC,在左上角媒體中選擇 打開網(wǎng)絡(luò)串流 ,在網(wǎng)絡(luò)URL中輸入與 3 中同樣的ip地址,點(diǎn)擊播放。
5、若顯示出無(wú)人機(jī)畫面,則成功,一般延遲在 3~10s 內(nèi)。(我是成功了,哈哈哈哈哈?。?br> 注:若無(wú)人機(jī)無(wú)法傳輸視頻,那么把Windows系統(tǒng)的防火墻關(guān)閉再試一試。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-439094.html
五、Python獲取無(wú)人機(jī)實(shí)時(shí)視頻
import cv2
import time
if __name__ == '__main__':
# 無(wú)人機(jī)rtmp視頻流url
video_path = "rtmp://192.168.x.x:1935/live"
# opencv獲取視頻流
capture = cv2.VideoCapture(video_path)
while True:
fps = 0.0
t1 = time.time()
# 讀取某一幀
ref, frame = capture.read()
fps = (fps + (1. / (time.time() - t1))) / 2
print("fps= %.2f" % (fps))
frame = cv2.putText(frame, "fps= %.2f" % (fps), (0, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.imshow("video", frame)
c = cv2.waitKey(1) & 0xff
if c == 27:
capture.release()
break
print("Video Detection Done!")
capture.release()
cv2.destroyAllWindows()
到了這里,關(guān)于心得:大疆無(wú)人機(jī)RTMP推流直播(Windows版本已成功)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!