windwos下使用ffmpeg+nginx+vlc实现将海康摄像头的rtsp协议转为rtmp协议

目录

一、准备工作

二、搭建rtmp服务器

1.运行nginx

1)修改nginx的配置文件

2)运行nginx

2.打开ffmpeg

1)运行ffmpeg

2)运行成功

三、测试

1.打开vlc

2.播放 

四、总结 


使用工具转流

提示:以下是本篇文章正文内容,下面案例可供参考

一、准备工作

1.下载ffmpeg

地址:http://ffmpeg.org/

2.下载nginx

地址:http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip

3.下载 nginx-rtmp-module

地址:http://t.csdnimg.cn/3YB01

可以参考这一篇博客,里面有下载的链接

4.下载vlc视频播放工具

地址:https://www.videolan.org/

具体下载,安装可以去查一下别的博客

二、搭建rtmp服务器

1.运行nginx

1)修改nginx的配置文件

下载好nginx以后找到conf,修改里面的 .conf 文件

#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;#上传flv文件块儿的大小
        application live { #创建一个叫live的应用
             live on;#开启live的应用
             allow publish 127.0.0.1;#
             allow play all;
        }
    }
}

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       8089;
        server_name  localhost;
		
		
		
		
		location /live {
			flv;
			chunked_transfer_encoding on;
			types {
				application/octet-stream flv;
			}
		}
		
		

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

}

 修改完成以后,保存配置文件

2)运行nginx

 在有nginx.exe的目录下面win+r 输入cmd,运行下面的两个命令

#杀死进程 可以用来检查一下有没有启动的nginx
taskkill /im nginx.exe -f

#运行nginx   nginx-win.conf可以改 有的是nginx.conf
nginx.exe -c conf\nginx-win.conf

 当出现有一个 |  在闪动,就证明nginx开启成功了

2.打开ffmpeg

先不要急,把这些rtsp的命名规则好好的先看看

​ 

举例说明:
DS-9632N-ST的IP通道01主码流:
rtsp://admin:12345@172.6.22.234:554/Streaming/Channels/101?transportmode=unicast
DS-9016HF-ST的IP通道01主码流:
rtsp://admin:12345@172.6.22.106:554/Streaming/Channels/1701?transportmode=unicast
DS-9016HF-ST的模拟通道01子码流:
rtsp://admin:12345@172.6.22.106:554/Streaming/Channels/102?transportmode=unicast  (单播)
rtsp://admin:12345@172.6.22.106:554/Streaming/Channels/102?transportmode=multicast (多播)
rtsp://admin:12345@172.6.22.106:554/Streaming/Channels/102 (?后面可省略,默认单播)
DS-9016HF-ST的零通道主码流(零通道无子码流):
rtsp://admin:12345@172.6.22.106:554/Streaming/Channels/001
DS-2DF7274-A的第三码流:
rtsp://admin:12345@172.6.10.11:554/Streaming/Channels/103

看完上面这些,大家应该就都明白rtsp协议的是怎么命名了,

这里大家就可以看着自己的参数改一下下面的命令

1)运行ffmpeg

 在有 ffmpeg.exe 的目录下面win+r 输入cmd ,运行下面的命令

ffmpeg.exe一般在bin目录下面

ffmpeg -rtsp_transport tcp -i rtsp://用户名:密码@摄像头的ip:554/streaming/channels/101 
-c:v copy -c:a aac -f flv rtmp://127.0.0.1:1935/live/100
2)运行成功

出现下面这样的就是运行成功了

 最下面的这一行数字会一直变化,这样就启动成功了

三、测试

这里就要使用下载的vlc播放器了

1.打开vlc

在 媒体 里面找到 打开网络串流 

2.播放 

将在上面用ffmpeg转成的rtmp流的地址输入

最后点击播放,就可以成功测试用ffmpeg转成的rtmp流是否成功

rtmp://127.0.0.1:1935/live/100

四、总结 

大家有时间可以转一下看看,也挺有意思的

vlc是一款强大的播放工具,如果是使用代码转好的流也可以用这个工具测试,是否转流成功

将rtsp转为rtmp,视频会有一点延迟,现在在浏览器播放rtmp的话需要下载flash插件

在2020年年底谷歌就停止了对flash的支持

所以想要将rtsp的转为http-flv

如果有人会将rtsp转为http-flv,可以在下方留言,有好的文章也可以放在评论区

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以通过以下步骤来实现Java与RTSPFFmpeg、HTML和Nginx的结合来实现频实时播放的监控系统: 1. 首先,你需要使用Java来创建一个监控系统的后端服务。你可以使用Java的网络编程库来监听RTSP流并将其解码。可以使用开源的库,例如JRTSP或者Xuggler来处理RTSP流,并将其换为可供播放的频流。 2. 接下来,你需要使用FFmpeg来处理频流。FFmpeg是一个强大的多媒体处理工具,可以用于码、解码、编码等操作。你可以使用FFmpeg来解码RTSP流,并将其换为HTML5支持的频格式,例如HLS(HTTP Live Streaming)或者MPEG-DASH(Dynamic Adaptive Streaming over HTTP)。 3. 在前端方面,你可以使用HTML和JavaScript来创建一个简单的频播放器。你可以使用HTML5的<video>标签来嵌入频,并使用JavaScript来控制频的播放、暂停等操作。你可以使用一些开源的频播放器库,例如video.js或者plyr来简化开发过程。 4. 最后,你可以使用Nginx作为反向代理服务器来提供频流的分发和缓存功能。Nginx可以将频流从后端服务器发给前端浏览器,并且可以缓存频文件以提高性能和可靠性。你可以配置Nginx来支持HLS或者MPEG-DASH协议,并且可以使用Nginx的HTTP模块来进行性能优化和安全加固。 综上所述,通过将Java、RTSPFFmpeg、HTML和Nginx结合起来,你可以实现一个监控频的实时播放系统。这个系统可以从RTSP流中提取频数据,经过FFmpeg处理后,通过HTML和JavaScript在浏览器中进行播放,并且可以使用Nginx提供性能优化和缓存支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值