目录
使用工具转流
提示:以下是本篇文章正文内容,下面案例可供参考
一、准备工作
1.下载ffmpeg
2.下载nginx
地址:http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip
3.下载 nginx-rtmp-module
可以参考这一篇博客,里面有下载的链接
4.下载vlc视频播放工具
具体下载,安装可以去查一下别的博客
二、搭建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,可以在下方留言,有好的文章也可以放在评论区