zoukankan      html  css  js  c++  java
  • Nginx搭建RTMP服务器+FFmpeg实现海康威视摄像头预览

    场景

    Windows上搭建Nginx RTMP服务器并使用FFmpeg实现本地视频推流:

    https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/120868728

    在上面实现的是对本地视频的推流,要对接海康威视摄像头获取视频流并推流和预览。

    注:

    博客:
    https://blog.csdn.net/badao_liumang_qizhi
    关注公众号
    霸道的程序猿
    获取编程相关电子书、教程推送与免费下载。

    实现

    1、使用Nginx搭建RTMP服务器

    流程和上面搭建的时候一致。完整nginx的配置再记录一遍

    #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;
     
            application live {
                live on;
            }
      
            application hls {
                live on;
                hls on; 
                hls_path temp/hls; 
                hls_fragment 8s; 
            }
        }
    }
     
    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       110;
            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;
        #    }
        #}
     
    }

    2、启动nginx后,在FFmpeg.exe目录中再新建bat启动脚本

    ffmpeg.exe -i "rtsp://admin:admin123456@摄像头的ip:554/h264/ch1/main/av_stream" -vcodec copy -acodec copy -f flv rtmp://localhost:8822/hls/badao
    pause

    脚本说明:

    海康威视摄像头,

    它的rtsp数据流的地址为:rtsp://[username]:[password]@[ip]:[port]/[codec]/[channel]/[subtype]/av_stream
    说明:
    username: 用户名。例如admin。
    password: 密码。例如12345。
    ip: 为设备IP。例如 192.0.0.64。
    port: 端口号默认为554,若为默认可不填写。
    codec:有h264、MPEG-4、mpeg4这几种。
    channel: 通道号,起始为1。例如通道1,则为ch1。
    subtype: 码流类型,主码流为main,辅码流为sub。

    3、双击脚本启动FFmpeg实现摄像头推流

    4、然后打开VLC播放器-媒体-打开网络串流

    输入地址

    http://127.0.0.1:81/hls/badao.m3u8

     

  • 相关阅读:
    密码等级
    ie兼容透明
    分割线
    支付宝银行判断接口
    date只能选择今天之后的时间js
    离开页面之前提示,关闭,刷新等
    使用 Linux 系统的常用命令
    C#窗体简单增删改查
    1
    二维数组
  • 原文地址:https://www.cnblogs.com/badaoliumangqizhi/p/15522894.html
Copyright © 2011-2022 走看看