1.接收流:

在需要接收流的节点上进行类似以下的配置:

 application live{live on;}

只要有这一项,就可以通过在浏览器等位置输入下面这个url来点播了

rtmp://127.0.0.1:1935/live

可以使用vlc播放视频流

下载vlc:

sudo apt install vlc

2.转推流:

a.直接转推:

#在application live上收到流后直接用push命令转推给下一个节点application live{live on;push rtmp://10.10.3.2/live;}

b.ffmpeg处理一下之后转推:

需要先安装ffmpeg:

sudo apt install ffmpeg

然后转推:

这里的转推是live收到流后先用ffmpeg处理完 发给另一个application sendout

然后在sendout里push出去给下一个节点

application live{live on;exec ffmpeg -re -i rtmp://localhost:1935/live/mystream -vcodec flv -acodec copy -s 32x32 -f flv rtmp://localhost:1935/sendout/mystream;}application sendout{live on;push rtmp://10.10.3.2/live;}

c.opencv读取然后进行人脸识别然后使用python脚本转推:

先理解一下只收流不转推:

import cv2
#从远端rtmp server的play下记录的视频文件中拉取流的方式:
#这个和下面的从live里拉流的方式二选一
vid_capture=cv2.VideoCapture("rtmp://远端ip:1935/play/friends.mp4")
#从本地rtmp server的live application中拉取流的方式(live是本地server收流的application)
#可以在live application收流的过程中开始拉
#可以在live application收到流之前拉(不知道太久行不行)
vid_capture=cv2.VideoCapture("rtmp://127.0.0.1:1935/live")
#这个文件需要从github上下载,google搜一下文件名就可以找到
#这个文件代表人脸识别算法
face_detect = cv2.CascadeClassifier('./haarcascade_frontalface_default.xml')
if (vid_capture.isOpened() == False):print("Error opening the video file")
else:fps = vid_capture.get(5)print("Frames per second : ", fps,'FPS')frame_count = vid_capture.get(7)print('Frame count : ', frame_count)while(vid_capture.isOpened()):ret, frame = vid_capture.read()if ret == True:gray = cv2.cvtColor(frame, code=cv2.COLOR_BGR2GRAY)face_zone = face_detect.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=3)for x, y, w, h in face_zone:cv2.rectangle(frame, pt1 = (x, y), pt2 = (x+w, y+h), color = [0,0,255], thickness=2)cv2.circle(frame, center = (x + w//2, y + h//2), radius = w//2, color = [0,255,0], thickness = 2)cv2.imshow('Frame', frame)key = cv2.waitKey(50)if key == ord('q'):breakelse:break
vid_capture.release()
cv2.destoryAllWindows()

收流并通过ffmpeg转推:

import cv2
import subprocess
vid_capture=cv2.VideoCapture("rtmp://127.0.0.1:1935/live")
nextnode = 'rtmp://10.10.2.2:1935/live'
face_detect = cv2.CascadeClassifier('./haarcascade_frontalface_default.xml')
size = (int(vid_capture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(vid_capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
sizeStr = str(size[0]) + 'x' + str(size[1])#command = ['ffmpeg','-y','-an', '-f', 'rawvideo', '-pix_fmt', 'bgr24', '-s', sizeStr, '-r', '25', '-i', '-', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-preset', 'ultrafast', '-f', 'flv', nextnode]
#转推的命令记录在这里
command = ['ffmpeg','-y','-an', '-f', 'rawvideo', '-pix_fmt', 'bgr24', '-s', sizeStr, '-i', '-', '-f', 'flv', nextnode]
#视频流处理完先转到pipe里,pipe的规则是把收到的流通过上面的command推出去
pipe = subprocess.Popen(command, shell=False, stdin=subprocess.PIPE)
if (vid_capture.isOpened() == False):print("Error opening the video file")
else:fps = vid_capture.get(5)print("Frames per second : ", fps,'FPS')frame_count = vid_capture.get(7)print('Frame count : ', frame_count)while(vid_capture.isOpened()):ret, frame = vid_capture.read()if ret == True:gray = cv2.cvtColor(frame, code=cv2.COLOR_BGR2GRAY)face_zone = face_detect.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=3)for x, y, w, h in face_zone:cv2.rectangle(frame, pt1 = (x, y), pt2 = (x+w, y+h), color = [0,0,255], thickness=2)cv2.circle(frame, center = (x + w//2, y + h//2), radius = w//2, color = [0,255,0], thickness = 2)cv2.imshow('Frame', frame)key = cv2.waitKey(10)#不断地把视频帧发到pipe里pipe.stdin.write(frame.tostring())if key == ord('q'):breakelse:break
vid_capture.release()
cv2.destoryAllWindows()
pipe.terminate()

使用cloudlab上的虚拟机做上面的实验会遇到一些问题,认为是节点的运算能力不够,或者远程桌面太卡。

本地开了两台虚拟机跑上面的实验没有问题

视频文件存储端的nginx.conf这么写就行:

worker_processes  1;events {worker_connections  1024;
}rtmp {server{listen 1935;chunk_size 4000;application play{play /usr/local/nginx/html/play;}}}http {server {listen      8080;# This URL provides RTMP statistics in XMLlocation /stat {rtmp_stat all;# Use this stylesheet to view XML as web page# in browserrtmp_stat_stylesheet stat.xsl;}location /stat.xsl {# XML stylesheet to view RTMP stats.# Copy stat.xsl wherever you want# and put the full directory path hereroot /path/to/stat.xsl/;}location /hls {# Serve HLS fragmentstypes {application/vnd.apple.mpegurl m3u8;video/mp2t ts;}root /tmp;add_header Cache-Control no-cache;}location /dash {# Serve DASH fragmentsroot /tmp;add_header Cache-Control no-cache;}}}

接收端的nginx.conf这么写就行(转推的内容需要加在里面):

worker_processes  1;events {worker_connections  1024;
}
rtmp {server{listen 1935;chunk_size 4000;application live{live on;}}}
http {server {listen      8080;# This URL provides RTMP statistics in XMLlocation /stat {rtmp_stat all;# Use this stylesheet to view XML as web page# in browserrtmp_stat_stylesheet stat.xsl;}location /stat.xsl {# XML stylesheet to view RTMP stats.# Copy stat.xsl wherever you want# and put the full directory path hereroot /path/to/stat.xsl/;}location /hls {# Serve HLS fragmentstypes {application/vnd.apple.mpegurl m3u8;video/mp2t ts;}root /tmp;add_header Cache-Control no-cache;}location /dash {# Serve DASH fragmentsroot /tmp;add_header Cache-Control no-cache;}}}

通过nginx-rtmp server进行视频流转发的几种方法相关推荐

  1. linux nginx rtmp 死机,nginx rtmp 实时直播视频流 发布者网络不稳定导致无法直播问题...

    nginx rtmp 实时直播视频流 发布者网络不稳定导致无法直播问题 直播项目使用nginx搭配rtmp扩展实现实时音视频流,最近一次直播讲师在外出差,使用酒店WiFi网络,苹果笔记本,Safari ...

  2. 记录Nginx的升级实践以及实现的三种方法详解

    方法一: 对于现在有的环境是通过源码包安装nginx的,由于库文件都存在,要升级nginx直接在虚拟机上编译安装好包 然后打包 ,更新到线上机器的/opt/nginx1.x上. 测试如下: scp n ...

  3. SQL Server 批量插入数据的两种方法(转)

    原文:http://blog.csdn.net/tjvictor/article/details/4360030 在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数 ...

  4. SQL Server 查看表定义的 2 种方法

    方法 1. 用SQL Server Management Studio 第一步找到要查看的表,右键 第二步点设计 方法 2. sp_help @objname = 'tableName' execut ...

  5. 【转载】SQL Server 批量插入数据的两种方法

    在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍SQL Server支持的两种批量 ...

  6. SQL Server 查看identity值的几种方法。

    方法 1. ident_incr('Table_name');#  增量    identity(A,B) 中的B值 ident_seed('Table_name'); # 种子    identit ...

  7. sql server 删除表数据的几种方法

    一.Truncate语法 TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行.但 TRUNCATE TABLE 比 DELETE 速度快, ...

  8. nginx 硬重启_nginx重启几种方法

    http://blog.csdn.net/zqinghai/article/details/71125045 ps -ef|grep nginx 平滑重启命令: kill -HUP 住进称号或进程号文 ...

  9. windows下live555+rtsp+ffmpeg媒体源,nginx+rtmp转发服务器,vlc播放rtmp媒体流

    1.下载live555+ffmpeg视频文件作为媒体源 将视频文件me-like-yuh.ts和ffmpeg推流脚本ffmpeg-rtsp2rtmp.bat放在mediaserver目录下 ffmpe ...

最新文章

  1. java多线程解读一(基础篇)
  2. Linux 文本格式显示折线图,linux 折线图
  3. 微信小程序轮播图中间变大_微信小程序实现带放大效果的轮播图
  4. 自定义tt文本模板实现MySql指数据库中生成实体类
  5. win7+GPU运行py-faster-rcnn
  6. iOS开发常用技能点(持续更新中。。。)
  7. 苹果手机怎么无线投屏?苹果手机无线投屏到电脑
  8. 【HTML】font标签font属性的使用方法
  9. ECCV 2022 | 谷歌提出:k-means Mask Transformer
  10. ios播放器横竖屏切换的问题
  11. 【树 图 科 技 头 条】2022年7月26日 星期二 @伍鸣 博士 受邀参加2022年7月29日举办的“2022开放原子开源峰会-区块链分论坛”并发表主题演讲
  12. 【加拿大签证】加拿大政府指定的签证办理中国体检医院一览【2019官方最新版,加拿大签证体检必看】
  13. wke播放优酷提示客户端权限的问题
  14. 亚马逊SP-API对接实践
  15. 10343 划分凸多边形(优先做)
  16. JS实现身份证号码15位转18位时最后一位的算法
  17. 游戏服务器怎么修复,永劫无间无法连接游戏服务器怎么解决
  18. 运营初创业公司的几点建议
  19. 在学期初小结本学期要做的事情
  20. COMSOL初始裂纹下随机裂纹走向分布模式对材料力学性能的影响

热门文章

  1. 接上篇。隔了很久之后才更新arch,次日又发现两个问题。
  2. 并行计算机结构 算法,并行计算──结构.算法.编程(第3版)
  3. 柔性电子:铁电 高分辨率和极大压力范围内内的线性响应
  4. 简单易懂 爬取某网站卫衣数据(python)及数据可视化分析(matplotlib、pyecharts)
  5. intouch 连接mysql_Intouch连接SQL Server数据库-OLEDB
  6. 用友软件下载地址汇总
  7. 操作系统 内存管理(一)
  8. C\C++头文件的作用
  9. 2021-2027全球与中国淀粉基可降解生物塑料市场现状及未来发展趋势
  10. 玩转 Apple 快捷指令,打卡、切图、查快递、扫码付款等!