视频流上的TCP与UDP [英] TCP vs UDP on video stream

查看:904
本文介绍了视频流上的TCP与UDP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从网络编程考试中回来,他们问我们的一个问题是"如果您要流式传输视频,您将使用TCP还是UDP?对存储的两个视频都给出解释和实时视频流" .对于这个问题,他们只是希望为存储的视频提供TCP的简短答案,为实时视频提供一个UDP的简短答案,但是我在回家的路上就考虑了这个问题,使用UDP传输实时视频是否一定更好?我的意思是,如果您有足够的带宽,并说正在播放足球比赛或音乐会,那您真的需要使用UDP吗?

I just came home from my exam in network-programming, and one of the question they asked us was "If you are going to stream video, would you use TCP or UDP? Give an explanation for both stored video and live video-streams". To this question they simply expected a short answer of TCP for stored video and UDP for live video, but I thought about this on my way home, and is it necessarily better to use UDP for streaming live video? I mean, if you have the bandwidth for it, and say you are streaming a soccer match, or concert for that matter, do you really need to use UDP?

让我们说,当您在直播这场音乐会或使用TCP的任何内容时,您开始丢失数据包(在您和发送方之间的某些网络中发生了一些不好的事情),并且一整分钟您都没有收到任何数据包.视频流将暂停,一分钟后,数据包将再次开始通过(IP为您找到了一条新的路由).然后将发生的情况是,TCP将在您丢失的那一刻重新传输并继续向您发送实时流.假设带宽高于流的比特率,并且ping不太高,因此在很短的时间内,您丢失的一分钟将为您充当流的缓冲区. ,如果再次发生丢包,您将不会注意到.

Lets say that while you are streaming this concert or whatever using TCP you start losing packets (something bad happened in some network between you and the sender), and for a whole minute you don't get any packets. The video-stream will pause, and after the minute is gone packets start to get through again (IP found a new route for you). What would then happen is that TCP would retransmit the minute you lost and continue sending you the live stream. As an assumption the bandwidth is higher than the bit-rate on the stream, and the ping is not too high, so in a short amount of time, the one minute you lost will act as a buffer for the stream for you, that way, if packet-loss happens again, you won't notice.

现在,我可以想到某些设备不是一个好主意,例如视频会议,由于延迟,您需要始终处于视频流的结尾在视频聊天中简直太恐怖了,但是在足球比赛或音乐会中,如果您落后于直播一分钟又有什么关系呢?另外,可以保证您已获得所有数据,最好将它们保存起来以备以后查看,而不会出现任何错误.

Now, I can think of some appliances where this wouldn't be a good idea, like for instance video-conferences, where you need to always be at the end of the stream, because delay during a video-chat is just horrible, but during a soccer-match, or a concert what does it matter if you are a single minute behind the stream? Plus, you are guaranteed that you get all the data and it would be better to save for later viewing when it's coming in without any errors.

这使我想到了我的问题.使用TCP进行实时流传输是否有我不知道的缺点?或者真的应该是,如果您有带宽,那么应该使用TCP,因为它对网络更小"(流控制)?

So this brings me to my question. Are there any drawbacks that I don't know of about using TCP for live-streaming? Or should it really be, that if you have the bandwidth for it you should go for TCP given that it is "nicer" to the network (flow-control)?

推荐答案

使用TCP进行实时视频的缺点:

Drawbacks of using TCP for live video:

  1. 通常,实时视频流设备在设计时并未考虑TCP流.如果使用TCP,则OS必须为每个客户端缓冲未确认的段.这是不可取的,特别是在现场直播的情况下;大概是由于事件的奇异性,您同时在线的客户列表很长.预先录制的视频广播通常没有太大的问题,因为观众错开了他们的重播活动.因此,TCP更适合重播视频点播.
  2. IP多播大大降低了大观众的视频带宽需求; TCP阻止使用IP多播,但是UDP非常适合IP多播.
  3. 实况视频通常是从摄像机录制的恒定带宽的流;预先录制的视频流从磁盘中取出.当源流处于恒定带宽时(如实况事件那样),TCP的丢失补偿动态特性使得提供实况视频变得更加困难.如果要缓冲摄像机的磁盘空间,请确保有足够的缓冲空间以应对不可预测的网络事件和可变的TCP发送/退避速率.由于UDP不在乎网络传输层丢弃,因此UDP为您提供了对该应用程序的更多控制.
  1. Typically live video-streaming appliances are not designed with TCP streaming in mind. If you use TCP, the OS must buffer the unacknowledged segments for every client. This is undesirable, particularly in the case of live events; presumably your list of simultaneous clients is long due to the singularity of the event. Pre-recorded video-casts typically don't have as much of a problem with this because viewers stagger their replay activity; therefore TCP is more appropriate for replaying a video-on-demand.
  2. IP multicast significantly reduces video bandwidth requirements for large audiences; TCP prevents the use of IP multicast, but UDP is well-suited for IP multicast.
  3. Live video is normally a constant-bandwidth stream recorded off a camera; pre-recorded video streams come off a disk. The loss-backoff dynamics of TCP make it harder to serve live video when the source streams are at a constant bandwidth (as would happen for a live-event). If you buffer to disk off a camera, be sure you have enough buffer for unpredictable network events and variable TCP send/backoff rates. UDP gives you much more control for this application since UDP doesn't care about network transport layer drops.

仅供参考,在描述网络时,请勿使用包装"一词.网络发送数据包".

FYI, please don't use the word "packages" when describing networks. Networks send "packets".

这篇关于视频流上的TCP与UDP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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