简体   繁体   English

UDP 上的实时视频流

[英]Live video streaming over UDP

I am creating an application which records the desktop screen and sends it over a network.我正在创建一个记录桌面屏幕并通过网络发送的应用程序。 I was using TCP and it was working, however there was huge frame stutters even when doing it on the same machine.我正在使用 TCP 并且它正在工作,但是即使在同一台机器上执行它也会出现巨大的帧卡顿。 When the screen would change it would require more data to be sent, this usually caused the TCP client to take an abornal amount of time sending the data当屏幕发生变化时,需要发送更多数据,这通常会导致 TCP 客户端花费大量时间来发送数据

Client客户

byte[] encoded = Encoder.Encode(frame); // Takes in a bitmap image and only keeps
// the part of the image that has changed

byte[] compressed = DataCompressor.Compress(encoded); // GZIP Compresses image

byte[][] slices = ByteManipulator.SliceBytes(compressed, 15000); // Divides the
// image slices that are 15000 bytes in length

foreach (byte[] slice in slices)
{
     SendTo(slice, HostIPEP); // Sends to the server (The main issue)
}

The issue with the above code is that data does not receive in the correct order, due to it being UDP.上述代码的问题是数据没有按正确的顺序接收,因为它是 UDP。 How does one get around this issue to stream video like this over UDP?如何通过 UDP 解决像这样的 stream 视频的问题?

Well, the stutters come from the huge amount of data to transfer, at the begging, and when something change in screen content.嗯,口吃来自大量的数据传输,在乞讨时,以及屏幕内容发生变化时。

I think if you use professional encoder for image(screen content), it should be much better, for example, x264/x265/av1 encoder, especially AV1 Real-Time Screen Content Coding .我认为如果你使用专业的图像(屏幕内容)编码器,它应该会好得多,例如,x264/x265/av1 编码器,尤其是AV1 实时屏幕内容编码

For the transport, recommend to use WebRTC server, such as SRS or MediaSoup etc, please read more detail from this post .对于传输,建议使用 WebRTC 服务器,例如 SRS 或 MediaSoup 等,请阅读这篇文章的更多详细信息。

If use C# to build the app, there is also some native binding to use WebRTC in C#.如果使用 C# 构建应用程序,还有一些原生绑定使用 C# 中的 WebRTC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM