什么是流传输?| 视频流传输如何工作

流传输是一种无需真正下载媒体文件即可观看视频或收听音频内容的方法。如果文件所有者使用 CDN,则可以提高流传输性能,并减少缓冲时间。

学习目标

阅读本文后,您将能够:

  • 了解流传输的工作方式
  • 了解哪些因素会延缓流传输
  • 说明如何使流传输更快

复制文章链接

什么是流传输?

流媒体

The first websites were simple pages of text with maybe an image or two. Today, however, anyone with a fast enough Internet connection can watch high-definition movies or make a video call over the Internet. This is possible because of a technology called streaming.

流传输将音频或视频文件从服务器连续传输到客户端。简而言之,消费者在连接 Internet 的设备上观看电视或收听播客时,就会发生流传输。使用流传输时,将远程存储客户端设备上播放的媒体文件,并通过 Internet 一次传输几秒钟。

流传输和下载之间有什么区别?

流传输是实时进行的,并且比下载媒体文件更高效。若下载视频文件,整个文件的副本都将保存到设备的硬盘驱动器上,并且直到整个文件下载完成后,视频才能播放。如果改为流传输,浏览器将在不实际复制和保存视频的情况下播放视频。视频将一次加载一点,而不是一次加载整个文件,并且浏览器加载的信息不会保存在本地。

想想湖泊与溪流之间的区别:两者都包含水,而且溪流所含的水量可能与湖泊一样多。区别在于,在溪流中,所有的水不会同时汇聚在一处。下载的视频文件更像一个湖泊,因为它占用大量硬盘空间(并且改变湖泊的位置需要很长时间)。流视频更像是溪流或河流,视频数据连续不断地快速流向用户的浏览器。

流传输如何工作?

就像通过 Internet 发送的其他数据一样,音频和视频数据也被分解为数据包。每个数据包都包含一小部分文件,客户端设备上的浏览器中的音频或视频播放器获取数据包流并将其解析为视频或音频。

Does streaming use the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP)?

Some streaming methods use UDP, and some use TCP. UDP and TCP are transport protocols, meaning they are used for moving packets of data across networks. Both are used with the Internet Protocol (IP). TCP opens a dedicated connection before transmitting data, and it ensures all data packets arrive in order. Unlike TCP, UDP does neither of these things. As a result, TCP is more reliable, but transmitting data via UDP does not take as long as it does via TCP, although some packets are lost along the way.

If TCP is like a package delivery service that requires the recipient to sign for the package, then UDP is like a delivery service that leaves packages on the front porch without knocking on the door to get a signature. The TCP delivery service loses fewer packages, but the UDP delivery service is faster, because packages can get dropped off even if no one is home to sign for them.

For streaming, in some cases speed is far more important than reliability. For instance, if someone is in a video conference, they would prefer to interact with the other conference attendees in real time than to sit and wait for every bit of data to be delivered. Therefore, a few lost data packets is not a huge concern, and UDP should be used.

In other cases, reliability is more important for streaming. For instance, both HTTP live streaming (HLS) and MPEG-DASH are streaming protocols that use TCP for transport. Many video-on-demand services use TCP.

什么是缓冲?

流传输和缓冲

Streaming media players load a few seconds of the stream ahead of time so that the video or audio can continue playing if the connection is briefly interrupted. This is known as buffering. Buffering ensures that videos can play smoothly and continuously. However, over slow connections, or if a network has a great deal of latency, a video can take a long time to buffer.

哪些因素会减慢流传输速度?

在网络端:

  • 网络延迟 :多种因素会影响延迟,包括用户尝试访问的内容的存储位置。
  • 网络拥塞 :如果通过网络发送的数据过多,就会降低流传输性能。

在用户端:

  • WiFi 问题 :重启 LAN 路由器,或从 WiFi 切换到以太网,有助于提高流传输性能。
  • 客户端设备运行缓慢 :播放视频需要大量处理能力。如果流传输视频的设备同时在运行很多其他进程,或者设备总是运行缓慢,则流传输性能可能会受到影响。
  • 带宽不足 :对于流视频,家庭网络需要约 4 Mbps 的带宽;对于高清视频,可能需要更大的带宽。

如何使流传输更快?

流传输与其他类型的 Web 内容一样会遭受相同类型的延迟和性能下降。由于流传输的内容存储在其他位置,因此托管位置的影响较大,就像通过 Internet 访问任何类型的内容一样。如果纽约的用户尝试从洛斯盖多斯的 Netflix 服务器流传输,则视频内容必须跨越 3,000 英里才能到达该用户,并且视频将不得不花费很长时间进行缓冲,甚至可能完全无法播放。因此,Netflix 和其他流媒体提供商广泛使用分布式内容分发网络(CDN),将内容存储在全球各地更靠近用户的位置。

CDN 对流传输性能具有巨大的积极影响。Cloudflare Stream Delivery 利用 Cloudflare CDN 将视频内容存储在全球各地的所有 Cloudflare 数据中心中;由此缩短了视频启动时间延迟并减少了缓冲时间。

To learn more about using Cloudflare Stream, see our Developer documentation.