Seven "live video technology explain" series: modern players principle

Seven cattle cloud released a live video solutions for real-time streaming of live network LiveNet and complete cloud solution to the end of June, many developers and network solutions for the details and usage scenarios are very interested.

Seven cattle combined real-time streaming network LiveNet practice and live cloud solutions, we use eight articles, more systematic introduction to the current hot key technologies of all aspects of live video, live video to help entrepreneurs are more comprehensive, in-depth understanding of live video technology, better technology selection.

 

This series of articles following outline:

(A) opening

(B) Acquisition

(C) processing

(D) encoding and encapsulation

(E) transmitting plug flow and

(Vi) delay optimization

(Vii) the principles of modern players

(Viii) SDK Performance Test Model

In the last delay optimization, we share a lot of simple and practical tuning tips. Benpian seven "live video technology explain" series: modern players principle.

In recent years, growth in multi-platform adaptation in demand caused the rise of adaptive rate streaming media player, forcing Web and mobile developers to rethink the logic associated video technology. First, sub-sub-giants released HLS, HDS and Smooth Streaming and other protocols, all the relevant details are hidden in the SDK specifically for them in. Developers are not free to modify the player and other multimedia engine logic: you can not change the rules, and cache sizes adaptive rate, or even your slice length. These players may be simple to use, but you do not have much choice to customize it even worse function can only endure.

But as different application scenarios, demand customizable features is growing. Just between live and on-demand, there is a difference in terms of different buffer management, ABR caching strategies and tactics. These needs gave birth to a series of more multimedia operations on the bottom of the birth of the API: Flash above Netstream, Media Source Extensions on HTML5, as well as Media Codec on Android, while the industry has emerged a standard HTTP-based streaming format MPEG-DASH . These more advanced capabilities provide greater flexibility for developers so they can build their own business needs of players and multimedia engine.

Today we share with you how to build a modern player, and what are the key components to build such a player needs. Generally speaking, a typical player can be decomposed into three parts: the UI, multimedia engine and a decoder, shown in Figure 1:

 

 

 

 

  • User Interface (UI): This is the top-level player portion. It defines the end-user experience by viewing different functional properties of three parts: the skin (the design of the player), UI (all features customizable playlists such as sharing and social), and business logic (specific business logic The advertising characteristics, and an authentication management device compatibility logic, etc.).

 

  • Multimedia Engine: here the playback control processing of all associated logic, as described parsed document, the pulling video clips, and adaptive rule set and the switching rate, etc., will be explained in detail in this section below. Because of these platform engines in general and binding is tight, you may need to use a variety of different engines in order to cover all platforms.

 

  • Decoders and DRM manager: the bottom part of the player is a decoder and DRM manager, this layer functions directly call the operating system exposed API. The main function of the decoder is to decode and render video content, and DRM manager is to control whether the right to play through the decryption process.

 

Next we will use an example to introduce the different roles played by each layer.

 

A user interface (UI)

UI layer is the top player, which you control the user can see and interact with things, but can also use your own brand to be customized to provide a unique user experience for your users. This layer closest to us that part of the front-end development. Within the UI, we also contains the business logic components that make up the uniqueness of your playback experience, although this part of the end-user can not function and interact directly.

UI part comprises three main components:

1. Skin

Skin is a generic term for visual relevant portion of the player: progress control, buttons, icons, and animations, etc., as shown in FIG. Most of the design and components of the same type, this component is implemented using CSS, designers or developers can easily bring integration (even if you are using the JW Player and Bitdash this package solution). 

 


2. UI logic


UI logic section defines all visible during playback and interactive user interaction: the playlist thumbnail, select the playback channels and social media sharing. Based on what you expect to achieve playback experience, but also in the past, this part join many other features, many of which exist in the form of plug-ins, you may be able to find some inspiration: https://github.com/videojs/video. JS / Wiki / Community Community plugins #-plugins
the UI logic section contains more features, we does not describe in detail, directly to the UI Eurosport player as an example of an intuitive feel for these functions.



 

 

从图 3 可以看出,除了传统的 UI 元素之外,还有一个非常有趣的特性,在用户观看 DVR 流媒体的时候,直播以小视窗的形式展示,观众可以通过这个小窗口随时回到直播中。由于布局或者 UI 和多媒体引擎完全独立,这些特性在 HTML5 中使用 dash.js 只需要几行代码就能实现。

对于 UI 部分来说,最好的实现方式是让各种特性都以插件/模块的形式添加到 UI 核心模块中。

3. 业务逻辑

除了上面两部分「可见」的功能特性之外,还有一个不可见的部分,这部分构成了你业务的独特性:认证和支付、频道和播放列表的获取,以及广告等。这里也包含一些技术相关的东西,比如用于 A/B 测试模块,以及和设备相关的配置,这些配置用于在多种不同类型的设备之间选择多个不同的媒体引擎。 
 

为了揭开底层隐藏的复杂性,我们在这里更详细的讲解一下这些模块:

设备检测与配置逻辑:这是最重要的特性之一,因为它将播放和渲染剥离开来了。例如,基于你浏览器的不同版本,播放器可能会自动为你选择一个基于 HTML5 MSE 的多媒体引擎 hls.js,或者为你选择一个基于 flash 的播放引擎 FlasHls 来播放 HLS 视频流。这部分的最大特点在于,无论你使用什么样的底层引擎,在上层都可以使用相同的 JavaScript 或者 CSS 来定制你的 UI 或者业务逻辑。


能够检测用户设备的能力允许你按需配置终端用户的体验:如果是在移动设备而非 4K 屏幕设备上播放,你可能需要从一个较低的码率开始。

A/B 测试逻辑:A/B 测试是为了能够在生产环节中灰度部分用户。例如,你可能会给部分 Chrome 用户提供一个新的按钮或者新的多媒体引擎,并且还能保证它所有的工作都正常如期进行。

广告(可选):在客户端处理广告是最复杂的业务逻辑之一。如 videojs-contrib-ads 这个插件模块的流程图给出一样,插入广告的流程中包含多个步骤。对于 HTTP 视频流来说,你或多或少会用到一些已有的格式如 VAST、VPAID 或者 Google IMA,它们能够帮你从广告服务器中拉取视频广告(通常是过时的非自适应格式),放在视频的前期、中期和后期进行播放,且不可跳过。

总结:

针对你的定制化需求,你可能选择使用包含所有经典功能的 JW Player 来播放(它也允许你定制部分功能),或者基于 Videojs 这样的开源播放器来定制你自己的功能特性。甚至为了在浏览器和原生播放器之间统一用户体验,你也可以考虑使用 React Native 来进行 UI 或者皮肤的开发,使用 Haxe 来进行业务逻辑的开发,这些优秀的库都可以在多种不同类型的设备之间共用同一套代码库。 

 

 

二、多媒体引擎

近年来,多媒体引擎更是以一种全新独立的组件出现在播放器架构中。在 MP4 时代,平台处理了所有播放相关的逻辑,而只将一部分多媒体处理相关的特性(仅仅是播放、暂停、拖拽和全屏模式等功能)开放给开发者。

然而,新的基于 HTTP 的流媒体格式需要一种全新的组件来处理和控制新的复杂性:解析声明文件、下载视频片段、自适应码率监控以及决策指定等等甚至更多。起初,ABR 的复杂性被平台或者设备提供商处理了。然而,随着主播控制和定制播放器需求的递增,一些新的播放器中慢慢也开放了一些更为底层的 API(如 Web 上的 Media Source Extensons,Flash 上的 Netstream 以及 Android 平台的 Media Codec),并迅速吸引来了很多基于这些底层 API 的强大而健壮的多媒体引擎。



 


接下来我们将详细讲解现代多媒体处理引擎中各组件的细节:

1. 声明文件解释和解析器

在基于 HTTP 的视频流中,一切都是以一个描述文件开始。该声明文件包含了媒体服务器所需理解的元信息:有多少种不同类型的视频质量、语言以及字母等,它们分别是什么。解析器从 XML 文件(对于 HLS 来说则是一种特殊的 m3u8 文件)中取得描述信息,然后从这些信息中取得正确的视频信息。当然,媒体服务器的类型很多,并不是所有都正确的实现了规范,因此解析器可能需要处理一些额外的实现错误。

一旦提取了视频信息,解析器则会从中解析出数据,用于构建流式的视觉图像,同时知道如何获取不同的视频片段。在某些多媒体引擎中,这些视觉图像先以一副抽象多媒体图的形式出现,然后在屏幕上绘制出不同 HTTP 视频流格式的差异特征。

在直播流场景中,解析器也必须周期性的重新获取声明文件,以便获得最新的视频片段信息。

2. 下载器(下载声明文件、多媒体片段以及密钥)

下载器是一个包装了处理 HTTP 请求原生 API 的模块。它不仅用于下载多媒体文件,在必要的时候也可以用于下载声明文件和 DRM 密钥。下载器在处理网络错误和重试方面扮演着非常重要的角色,同时能够收集当前可用带宽的数据。

注意:下载多媒体文件可能使用 HTTP 协议,也可能使用别的协议,如点对点实时通信场景中的 WebRTC 协议。

3. 流播放引擎

流播放引擎是和解码器 API 交互的中央模块,它将不同的多媒体片段导入编码器,同时处理多码率切换和播放时的差异性(如声明文件和视频切片的差异,以及卡顿时的自动跳帧)。

4. 资源质量参数预估器(带宽、CPU 和帧率等)


预估器从各种不同的维度获取数据(块大小,每片段下载时间,以及跳帧数),并将其汇聚起来用于估算用户可用的带宽和 CPU 计算能力。这是输出用于 ABR (Adaptive Bitrate, 自适应码率)切换控制器做判断。

5. ABR 切换控制器

ABR 切换器可能是多媒体引擎中最为关键的部分——通常也是大家最为忽视的部分。该控制器读取预估器输出的数据(带宽和跳帧数),使用自定义算法根据这些数据做出判断,告诉流播放引擎是否需要切换视频或者音频质量。

该领域有很多研究性的工作,其中最大的难点在于在再缓冲风险和切换频率(太频繁的切换可能导致糟糕的用户体验)之间找到平衡。

6. DRM 管理器(可选组件)

今天所有的付费视频服务都基于 DRM 管理,而 DRM 则很大程度上依赖于平台或者设备,我们将在后续讲解播放器的时候看到。多媒体引擎中的 DRM 管理器是更底层解码器中内容解密 API 的包装。

只要有可能,它会尽量通过抽象的方式来屏蔽浏览器或者操作系统实现细节的差异性。该组件通常和流处理引擎紧密连接在一起,因为它经常和解码器层交互。

7. 格式转换复用器(可选组件)


后文中我们将看到,每个平台在封包和编码方面都有它的局限性(Flash 读的是 FLV 容器封装的 H.264/AAC 文件,MSE 读的是 ISOBMFF 容器封装的 H.264/AAC 文件)。这就导致了有些视频片段在解码之前需要进行格式转换。例如,有了 MPEG2-TS 到 ISOBMFF 的格式转换复用器之后,hls.js 就能使用 MSE 格式的内容来播放 HLS 视频流。多媒体引擎层面的格式转换复用器曾经遭受质疑;然而,随着现代 JavaScript 或者 Flash 解释权性能的提升,它带来的性能损耗几乎可以忽略不计,对用户体验也不会造成多大的影响。

总结

多媒体引擎中也有非常多的不同组件和特性,从字幕到截图到广告插入等等。接下来我们也会单独写一篇文章来对比多种不同引擎的差异,通过一些测试和市场数据来为引擎的选择给出一些实质性的指导。值得注意的是,要构建一个兼容各平台的播放器,提供多个可自由替换的多媒体引擎是非常重要的,因为底层解码器是和用户平台相关的,接下来我们将重点讲解这方面的内容。

 

三、解码器和 DRM 管理器

出于解码性能(解码器)和安全考虑(DRM),解码器和 DRM 管理器与操作系统平台密切绑定。 

 

 

1. 解码器

解码器处理最底层播放相关的逻辑。它将不同封装格式的视频进行解包,并将其内容解码,然后将解码后的视频帧交给操作系统进行渲染,最终让终端用户看到。

由于视频压缩算法变得越来越复杂,解码过程是一个需要密集计算的过程,并且为了保证解码性能和流畅的播放体验,解码过程需要强依赖于操作系统和硬件。现在的大部分解码都依赖于 GPU 加速解码的帮助(这也是为什么免费而更强大的 VP9 解码器没有赢得 H.264 市场地位的原因之一)。如果没有 GPU 的加速,解码一个 1080P 的视频就会占去 70% 左右的 CPU 计算量,并且丢帧率还可能很严重。


在解码和渲染视频帧的基础之上,管理器也提供了一个原生的 buffer,多媒体引擎可以直接与该 buffer 进行交互,实时了解它的大小并在必要的时候刷新它。


我们前面提到,每个平台都有它自己的渲染引擎和相应的 API:Flash 平台有 Netstream,Android 平台有 Media Codec API,而 Web 上则有标准的 Media Sources Extensions。MSE 越来越吸引眼球,将来可能会成为继浏览器之后其它平台上的事实标准。

2. DRM 管理器

 


今天,在传输工作室生产的付费内容的时候,DRM 是必要的。这些内容必须防止被盗,因此 DRM 的代码和工作过程都向终端用户和开发者屏蔽了。解密过的内容不会离开解码层,因此也不会被拦截。

为了标准化 DRM 以及为各平台的实现提供一定的互通性,几个 Web 巨头一起创建了通用加密标准Common Encryption (CENC)  和通用的多媒体加密扩展Encrypted Media Extensions,以便为多个 DRM 提供商(例如,EME 可用于 Edge 平台上的 Playready 和 Chrome 平台上的 Widewine)构建一套通用的 API,这些 API 能够从 DRM 授权模块读取视频内容加密密钥用于解密。

CENC 声明了一套标准的加密和密钥映射方法,它可用于在多个 DRM 系统上解密相同的内容,只需要提供相同的密钥即可。


在浏览器内部,基于视频内容的元信息,EME 可以通过识别它使用了哪个 DRM 系统加密,并调用相应的解密模块(Content Decryption Module, CDM)解密 CENC 加密过的内容。解密模块 CDM 则会去处理内容授权相关的工作,获得密钥并解密视频内容。

CENC 没有规定授权的发放、授权的格式、授权的存储、以及使用规则和权限的映射关系等细节,这些细节的处理都由 DRM 提供商负责。 

 

四、总结

今天我们深入了解了一下视频播放器三个层面的不同内容,这个现代播放器结构最优秀之处在于其交互部分完全和多媒体引擎逻辑部分分离,让主播可以无缝而自由灵活的定制终端用户体验,同时在多种不同终端设备上使用不同的多媒体引擎还能保证顺利播放多种不同格式的视频内容。

在 Web 平台,得益于多媒体引擎如 dash.js、Shaka Player 和 hls.js 这些趋于成熟库的帮助, MSE 和 EME 正在成为播放的新标准,同时也越来越多有影响力的厂家使用这些播放引擎。近年来,注意力也开始伸向机顶盒和互联网电视,我们也看到越来越多这样的新设备使用 MSE 来作为其底层多媒体处理引擎。我们也将持续投入更多的力量去支持这些标准。 

Guess you like

Origin blog.csdn.net/ai2000ai/article/details/94721827