UDP Receiver 需要在 udp sender 之前启动 [英] UDP Receiver needs to start before udp sender

查看:16
本文介绍了UDP Receiver 需要在 udp sender 之前启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将视频从带有运行 Raspian Buster 的摄像头的树莓派 0w 发送到运行 Ubuntu 18.04 的机器.我正在使用 ffmpeg 在 raspi 端使用硬件编码为 h264,然后通过 UDP 使用 gst-launch-1.0 发送数据.问题是,如果我启动 raspi 流,然后启动接收器,则接收器永远不会连接.如果我启动接收器然后启动 raspi 流,那么它们会完美连接.

I'm trying to send video from a raspberry pi 0w with camera running Raspian Buster to a machine running Ubuntu 18.04. I'm using ffmpeg to encode to h264 using hardware on the raspi end, and then sending the data with gst-launch-1.0 over UDP. The issue is that if I start the raspi stream, and then start the receiver, the receiver never connects. If I start the receiver and then start the raspi stream, then they connect perfectly.

Raspi 编码并发送命令:

Raspi encode and send command:

ffmpeg -f video4linux2 -framerate 30 -video_size 1280x720 -i/dev/video0 -c:v h264_omx -b:v 2000k -f avi pipe:1 |gst-launch-1.0 --gst-debug=3 fdsrc !udpsink 主机=192.168.1.142 端口=8090

接收解码显示命令:

gst-launch-1.0 udpsrc 端口=8090 !队列 !h264解析!avdec_h264 !xvimagesink sync=false

我查看了 udpsinkudpsrc 属性并尝试使用 buffer-sizeblocksize,和 sync 没有运气.我还尝试使用 python 中的 ffmpeg 来查看问题是否出在接收端,问题完全相同.

I've looked at the udpsink and udpsrc properties and tried messing around with buffer-size, blocksize, and sync with no luck. I've also tried using ffmpeg from python to see if the issue was on the receiver side, with the exact same problem.


import cv2

cap = cv2.VideoCapture('udp://127.0.0.1:8090',cv2.CAP_FFMPEG)
if not cap.isOpened():
    print('VideoCapture not opened')
    exit(-1)

while True:
    ret, frame = cap.read()

    if not ret:
        print('frame empty')
        break

    cv2.imshow('image', frame)

    if cv2.waitKey(1)&0XFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

最后,我可能只是编写一个小协议,如果没有数据包通过,则切换发送方,但我希望 UDP 能更好地处理连接.

In the end, I might just write a small protocol that toggles the sender if no packets are getting through, but I was hoping that UDP would handle the connection better.

这个问题似乎很相似:UDP:客户端在服务器之前启动但没有解决我的问题,因为我对 gstreamer/ffmpeg 没有任何阻止能力.

This question seemed simliar: UDP: Client started before Server but didn't resolve my issue since I don't have any blocking ability with gstreamer/ffmpeg.

推荐答案

如果要随机访问,需要定期发送 SPS/PPS 数据.如果你不这样做,这些数据只会在一开始就被发送.此信息对于解码 H.264 流至关重要.考虑在 udpsink 之前添加 h264parse 并配置它的 config-interval 属性.

You need to send SPS/PPS data periodically if you want to have random access. If you don't, this data will only get send in the very beginning. This information is critical for decoding a H.264 stream. Consider adding h264parse before the udpsink and configure it's config-interval property.

这篇关于UDP Receiver 需要在 udp sender 之前启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆