0


心得:大疆无人机RTMP推流直播(Windows版本已成功)

大疆无人机rtmp推流直播到电脑(Windows版本已成功)

一、所需资源

1、nginx的Gryphon版本,它内部已经集成了rtmp的推流编译(nginx-Gryphon)
2、服务器状态检查程序stat.xsl(nginx-rtmp-module)
3、ffmpeg(ffmpeg)
4、VLC(VLC)

二、安装

1、将下载好的nginx 1.7.11.3 Gryphon解压修改文件名为nginx-1.7.11.3-Gryphon,绝对路径中不能有中文,必须全为英文!
2、在根目录中的conf文件夹中,若有nginx.conf文件,直接进入修改;若无,则创建一个。
3、在nginx文件中,将以下内容粘贴。


#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 {
        ##    return412;
        ##}

## 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   500502503504/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 ofIP-, 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即使访问路径,如localhost:1935/live。
4、在nginx.exe所在的目录,即根目录下,进入cmd窗口,输入nginx.exe或.\nginx.exe,启动nginx。
5、可以直接浏览器输入localhost验证是否启动nginx,若出现nginx的主页面,则成功。
6、将服务器状态检查程序解压,放到nginx根目录下。
在这里插入图片描述
7、将ffmpeg解压后,将其bin目录添加环境变量。
8、安装VLC

三、ffmpeg推流

ffmpeg推流是为了确定nginx的1935端口已打开并运行rtmp推流功能,以排除故障等问题。
1、在测试视频所在文件夹打开cmd窗口,输入指令 ffmpeg.exe -re -i .\视频名.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/live
2、若出现以下画面则推流失败,是因为nginx的1935端口未开启,或是rtmp未推流。

请添加图片描述
3、若出现以下画面,则成功,frame, fps等信息会不断地变化。
请添加图片描述

4、打开VLC,在左上角媒体中选择 打开网络串流 ,在网络URL中输入rtmp://127.0.0.1:1935/live,点击播放。
请添加图片描述
5、若是显示出视频,则成功。

四、无人机rtmp推流

1、保证电脑和无人机遥控器(或遥控器连接的手机)在同一局域网中(即同一路由器或热点)。
2、电脑确认ip地址,打开cmd窗口输入命令ipconfig,确定电脑ip地址。
3、无人机进入自定义直播功能中,输入地址,一般为 rtmp://192.168.x.x:1935/live 或 rtmp://10.0.x.x:1935/live。
4、打开VLC,在左上角媒体中选择 打开网络串流 ,在网络URL中输入与 3 中同样的ip地址,点击播放。
请添加图片描述
5、若显示出无人机画面,则成功,一般延迟在 3~10s 内。(我是成功了,哈哈哈哈哈!)
注:若无人机无法传输视频,那么把Windows系统的防火墙关闭再试一试。

五、Python获取无人机实时视频

import cv2
import time

if __name__ =='__main__':# 无人机rtmp视频流url
    video_path ="rtmp://192.168.x.x:1935/live"# opencv获取视频流
    capture = cv2.VideoCapture(video_path)whileTrue:
        fps =0.0

        t1 = time.time()# 读取某一帧
        ref, frame = capture.read()
        fps =(fps +(1./(time.time()- t1)))/2print("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)&0xffif c ==27:
            capture.release()breakprint("Video Detection Done!")
    capture.release()
    cv2.destroyAllWindows()

本文转载自: https://blog.csdn.net/RSssr/article/details/129654853
版权归原作者 若颂颂颂颂 所有, 如有侵权,请联系我们删除。

“心得:大疆无人机RTMP推流直播(Windows版本已成功)”的评论:

还没有评论