xref: /aosp_15_r20/external/webrtc/modules/video_coding/g3doc/index.md (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker<?% config.freshness.owner = 'brandtr' %?>
2*d9f75844SAndroid Build Coastguard Worker<?% config.freshness.reviewed = '2021-04-15' %?>
3*d9f75844SAndroid Build Coastguard Worker
4*d9f75844SAndroid Build Coastguard Worker# Video coding in WebRTC
5*d9f75844SAndroid Build Coastguard Worker
6*d9f75844SAndroid Build Coastguard Worker## Introduction to layered video coding
7*d9f75844SAndroid Build Coastguard Worker
8*d9f75844SAndroid Build Coastguard Worker[Video coding][video-coding-wiki] is the process of encoding a stream of
9*d9f75844SAndroid Build Coastguard Workeruncompressed video frames into a compressed bitstream, whose bitrate is lower
10*d9f75844SAndroid Build Coastguard Workerthan that of the original stream.
11*d9f75844SAndroid Build Coastguard Worker
12*d9f75844SAndroid Build Coastguard Worker### Block-based hybrid video coding
13*d9f75844SAndroid Build Coastguard Worker
14*d9f75844SAndroid Build Coastguard WorkerAll video codecs in WebRTC are based on the block-based hybrid video coding
15*d9f75844SAndroid Build Coastguard Workerparadigm, which entails prediction of the original video frame using either
16*d9f75844SAndroid Build Coastguard Worker[information from previously encoded frames][motion-compensation-wiki] or
17*d9f75844SAndroid Build Coastguard Workerinformation from previously encoded portions of the current frame, subtraction
18*d9f75844SAndroid Build Coastguard Workerof the prediction from the original video, and
19*d9f75844SAndroid Build Coastguard Worker[transform][transform-coding-wiki] and [quantization][quantization-wiki] of the
20*d9f75844SAndroid Build Coastguard Workerresulting difference. The output of the quantization process, quantized
21*d9f75844SAndroid Build Coastguard Workertransform coefficients, is losslessly [entropy coded][entropy-coding-wiki] along
22*d9f75844SAndroid Build Coastguard Workerwith other encoder parameters (e.g., those related to the prediction process)
23*d9f75844SAndroid Build Coastguard Workerand then a reconstruction is constructed by inverse quantizing and inverse
24*d9f75844SAndroid Build Coastguard Workertransforming the quantized transform coefficients and adding the result to the
25*d9f75844SAndroid Build Coastguard Workerprediction. Finally, in-loop filtering is applied and the resulting
26*d9f75844SAndroid Build Coastguard Workerreconstruction is stored as a reference frame to be used to develop predictions
27*d9f75844SAndroid Build Coastguard Workerfor future frames.
28*d9f75844SAndroid Build Coastguard Worker
29*d9f75844SAndroid Build Coastguard Worker### Frame types
30*d9f75844SAndroid Build Coastguard Worker
31*d9f75844SAndroid Build Coastguard WorkerWhen an encoded frame depends on previously encoded frames (i.e., it has one or
32*d9f75844SAndroid Build Coastguard Workermore inter-frame dependencies), the prior frames must be available at the
33*d9f75844SAndroid Build Coastguard Workerreceiver before the current frame can be decoded. In order for a receiver to
34*d9f75844SAndroid Build Coastguard Workerstart decoding an encoded bitstream, a frame which has no prior dependencies is
35*d9f75844SAndroid Build Coastguard Workerrequired. Such a frame is called a "key frame". For real-time-communications
36*d9f75844SAndroid Build Coastguard Workerencoding, key frames typically compress less efficiently than "delta frames"
37*d9f75844SAndroid Build Coastguard Worker(i.e., frames whose predictions are derived from previously encoded frames).
38*d9f75844SAndroid Build Coastguard Worker
39*d9f75844SAndroid Build Coastguard Worker### Single-layer coding
40*d9f75844SAndroid Build Coastguard Worker
41*d9f75844SAndroid Build Coastguard WorkerIn 1:1 calls, the encoded bitstream has a single recipient. Using end-to-end
42*d9f75844SAndroid Build Coastguard Workerbandwidth estimation, the target bitrate can thus be well tailored for the
43*d9f75844SAndroid Build Coastguard Workerintended recipient. The number of key frames can be kept to a minimum and the
44*d9f75844SAndroid Build Coastguard Workercompressability of the stream can be maximized. One way of achiving this is by
45*d9f75844SAndroid Build Coastguard Workerusing "single-layer coding", where each delta frame only depends on the frame
46*d9f75844SAndroid Build Coastguard Workerthat was most recently encoded.
47*d9f75844SAndroid Build Coastguard Worker
48*d9f75844SAndroid Build Coastguard Worker### Scalable video coding
49*d9f75844SAndroid Build Coastguard Worker
50*d9f75844SAndroid Build Coastguard WorkerIn multiway conferences, on the other hand, the encoded bitstream has multiple
51*d9f75844SAndroid Build Coastguard Workerrecipients each of whom may have different downlink bandwidths. In order to
52*d9f75844SAndroid Build Coastguard Workertailor the encoded bitstreams to a heterogeneous network of receivers,
53*d9f75844SAndroid Build Coastguard Worker[scalable video coding][svc-wiki] can be used. The idea is to introduce
54*d9f75844SAndroid Build Coastguard Workerstructure into the dependency graph of the encoded bitstream, such that _layers_ of
55*d9f75844SAndroid Build Coastguard Workerthe full stream can be decoded using only available lower layers. This structure
56*d9f75844SAndroid Build Coastguard Workerallows for a [selective forwarding unit][sfu-webrtc-glossary] to discard upper
57*d9f75844SAndroid Build Coastguard Workerlayers of the of the bitstream in order to achieve the intended downlink
58*d9f75844SAndroid Build Coastguard Workerbandwidth.
59*d9f75844SAndroid Build Coastguard Worker
60*d9f75844SAndroid Build Coastguard WorkerThere are multiple types of scalability:
61*d9f75844SAndroid Build Coastguard Worker
62*d9f75844SAndroid Build Coastguard Worker* _Temporal scalability_ are layers whose framerate (and bitrate) is lower than that of the upper layer(s)
63*d9f75844SAndroid Build Coastguard Worker* _Spatial scalability_ are layers whose resolution (and bitrate) is lower than that of the upper layer(s)
64*d9f75844SAndroid Build Coastguard Worker* _Quality scalability_ are layers whose bitrate is lower than that of the upper layer(s)
65*d9f75844SAndroid Build Coastguard Worker
66*d9f75844SAndroid Build Coastguard WorkerWebRTC supports temporal scalability for `VP8`, `VP9` and `AV1`, and spatial
67*d9f75844SAndroid Build Coastguard Workerscalability for `VP9` and `AV1`.
68*d9f75844SAndroid Build Coastguard Worker
69*d9f75844SAndroid Build Coastguard Worker### Simulcast
70*d9f75844SAndroid Build Coastguard Worker
71*d9f75844SAndroid Build Coastguard WorkerSimulcast is another approach for multiway conferencing, where multiple
72*d9f75844SAndroid Build Coastguard Worker_independent_ bitstreams are produced by the encoder.
73*d9f75844SAndroid Build Coastguard Worker
74*d9f75844SAndroid Build Coastguard WorkerIn cases where multiple encodings of the same source are required (e.g., uplink
75*d9f75844SAndroid Build Coastguard Workertransmission in a multiway call), spatial scalability with inter-layer
76*d9f75844SAndroid Build Coastguard Workerprediction generally offers superior coding efficiency compared with simulcast.
77*d9f75844SAndroid Build Coastguard WorkerWhen a single encoding is required (e.g., downlink transmission in any call),
78*d9f75844SAndroid Build Coastguard Workersimulcast generally provides better coding efficiency for the upper spatial
79*d9f75844SAndroid Build Coastguard Workerlayers. The `K-SVC` concept, where spatial inter-layer dependencies are only
80*d9f75844SAndroid Build Coastguard Workerused to encode key frames, for which inter-layer prediction is typically
81*d9f75844SAndroid Build Coastguard Workersignificantly more effective than it is for delta frames, can be seen as a
82*d9f75844SAndroid Build Coastguard Workercompromise between full spatial scalability and simulcast.
83*d9f75844SAndroid Build Coastguard Worker
84*d9f75844SAndroid Build Coastguard Worker## Overview of implementation in `modules/video_coding`
85*d9f75844SAndroid Build Coastguard Worker
86*d9f75844SAndroid Build Coastguard WorkerGiven the general introduction to video coding above, we now describe some
87*d9f75844SAndroid Build Coastguard Workerspecifics of the [`modules/video_coding`][modules-video-coding] folder in WebRTC.
88*d9f75844SAndroid Build Coastguard Worker
89*d9f75844SAndroid Build Coastguard Worker### Built-in software codecs in [`modules/video_coding/codecs`][modules-video-coding-codecs]
90*d9f75844SAndroid Build Coastguard Worker
91*d9f75844SAndroid Build Coastguard WorkerThis folder contains WebRTC-specific classes that wrap software codec
92*d9f75844SAndroid Build Coastguard Workerimplementations for different video coding standards:
93*d9f75844SAndroid Build Coastguard Worker
94*d9f75844SAndroid Build Coastguard Worker* [libaom][libaom-src] for [AV1][av1-spec]
95*d9f75844SAndroid Build Coastguard Worker* [libvpx][libvpx-src] for [VP8][vp8-spec] and [VP9][vp9-spec]
96*d9f75844SAndroid Build Coastguard Worker* [OpenH264][openh264-src] for [H.264 constrained baseline profile][h264-spec]
97*d9f75844SAndroid Build Coastguard Worker
98*d9f75844SAndroid Build Coastguard WorkerUsers of the library can also inject their own codecs, using the
99*d9f75844SAndroid Build Coastguard Worker[VideoEncoderFactory][video-encoder-factory-interface] and
100*d9f75844SAndroid Build Coastguard Worker[VideoDecoderFactory][video-decoder-factory-interface] interfaces. This is how
101*d9f75844SAndroid Build Coastguard Workerplatform-supported codecs, such as hardware backed codecs, are implemented.
102*d9f75844SAndroid Build Coastguard Worker
103*d9f75844SAndroid Build Coastguard Worker### Video codec test framework in [`modules/video_coding/codecs/test`][modules-video-coding-codecs-test]
104*d9f75844SAndroid Build Coastguard Worker
105*d9f75844SAndroid Build Coastguard WorkerThis folder contains a test framework that can be used to evaluate video quality
106*d9f75844SAndroid Build Coastguard Workerperformance of different video codec implementations.
107*d9f75844SAndroid Build Coastguard Worker
108*d9f75844SAndroid Build Coastguard Worker### SVC helper classes in [`modules/video_coding/svc`][modules-video-coding-svc]
109*d9f75844SAndroid Build Coastguard Worker
110*d9f75844SAndroid Build Coastguard Worker*   [`ScalabilityStructure*`][scalabilitystructure] - different
111*d9f75844SAndroid Build Coastguard Worker    [standardized scalability structures][scalability-structure-spec]
112*d9f75844SAndroid Build Coastguard Worker*   [`ScalableVideoController`][scalablevideocontroller] - provides instructions to the video encoder how
113*d9f75844SAndroid Build Coastguard Worker    to create a scalable stream
114*d9f75844SAndroid Build Coastguard Worker*   [`SvcRateAllocator`][svcrateallocator] - bitrate allocation to different spatial and temporal
115*d9f75844SAndroid Build Coastguard Worker    layers
116*d9f75844SAndroid Build Coastguard Worker
117*d9f75844SAndroid Build Coastguard Worker### Utility classes in [`modules/video_coding/utility`][modules-video-coding-utility]
118*d9f75844SAndroid Build Coastguard Worker
119*d9f75844SAndroid Build Coastguard Worker*   [`FrameDropper`][framedropper] - drops incoming frames when encoder systematically
120*d9f75844SAndroid Build Coastguard Worker    overshoots its target bitrate
121*d9f75844SAndroid Build Coastguard Worker*   [`FramerateController`][frameratecontroller] - drops incoming frames to achieve a target framerate
122*d9f75844SAndroid Build Coastguard Worker*   [`QpParser`][qpparser] - parses the quantization parameter from a bitstream
123*d9f75844SAndroid Build Coastguard Worker*   [`QualityScaler`][qualityscaler] - signals when an encoder generates encoded frames whose
124*d9f75844SAndroid Build Coastguard Worker    quantization parameter is outside the window of acceptable values
125*d9f75844SAndroid Build Coastguard Worker*   [`SimulcastRateAllocator`][simulcastrateallocator] - bitrate allocation to simulcast layers
126*d9f75844SAndroid Build Coastguard Worker
127*d9f75844SAndroid Build Coastguard Worker### General helper classes in [`modules/video_coding`][modules-video-coding]
128*d9f75844SAndroid Build Coastguard Worker
129*d9f75844SAndroid Build Coastguard Worker*   [`FecControllerDefault`][feccontrollerdefault] - provides a default implementation for rate
130*d9f75844SAndroid Build Coastguard Worker    allocation to [forward error correction][fec-wiki]
131*d9f75844SAndroid Build Coastguard Worker*   [`VideoCodecInitializer`][videocodecinitializer] - converts between different encoder configuration
132*d9f75844SAndroid Build Coastguard Worker    structs
133*d9f75844SAndroid Build Coastguard Worker
134*d9f75844SAndroid Build Coastguard Worker### Receiver buffer classes in [`modules/video_coding`][modules-video-coding]
135*d9f75844SAndroid Build Coastguard Worker
136*d9f75844SAndroid Build Coastguard Worker*   [`PacketBuffer`][packetbuffer] - (re-)combines RTP packets into frames
137*d9f75844SAndroid Build Coastguard Worker*   [`RtpFrameReferenceFinder`][rtpframereferencefinder] - determines dependencies between frames based on information in the RTP header, payload header and RTP extensions
138*d9f75844SAndroid Build Coastguard Worker*   [`FrameBuffer`][framebuffer] - order frames based on their dependencies to be fed to the decoder
139*d9f75844SAndroid Build Coastguard Worker
140*d9f75844SAndroid Build Coastguard Worker[video-coding-wiki]: https://en.wikipedia.org/wiki/Video_coding_format
141*d9f75844SAndroid Build Coastguard Worker[motion-compensation-wiki]: https://en.wikipedia.org/wiki/Motion_compensation
142*d9f75844SAndroid Build Coastguard Worker[transform-coding-wiki]: https://en.wikipedia.org/wiki/Transform_coding
143*d9f75844SAndroid Build Coastguard Worker[motion-vector-wiki]: https://en.wikipedia.org/wiki/Motion_vector
144*d9f75844SAndroid Build Coastguard Worker[mpeg-wiki]: https://en.wikipedia.org/wiki/Moving_Picture_Experts_Group
145*d9f75844SAndroid Build Coastguard Worker[svc-wiki]: https://en.wikipedia.org/wiki/Scalable_Video_Coding
146*d9f75844SAndroid Build Coastguard Worker[sfu-webrtc-glossary]: https://webrtcglossary.com/sfu/
147*d9f75844SAndroid Build Coastguard Worker[libvpx-src]: https://chromium.googlesource.com/webm/libvpx/
148*d9f75844SAndroid Build Coastguard Worker[libaom-src]: https://aomedia.googlesource.com/aom/
149*d9f75844SAndroid Build Coastguard Worker[openh264-src]: https://github.com/cisco/openh264
150*d9f75844SAndroid Build Coastguard Worker[vp8-spec]: https://tools.ietf.org/html/rfc6386
151*d9f75844SAndroid Build Coastguard Worker[vp9-spec]: https://storage.googleapis.com/downloads.webmproject.org/docs/vp9/vp9-bitstream-specification-v0.6-20160331-draft.pdf
152*d9f75844SAndroid Build Coastguard Worker[av1-spec]: https://aomediacodec.github.io/av1-spec/
153*d9f75844SAndroid Build Coastguard Worker[h264-spec]: https://www.itu.int/rec/T-REC-H.264-201906-I/en
154*d9f75844SAndroid Build Coastguard Worker[video-encoder-factory-interface]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/api/video_codecs/video_encoder_factory.h;l=27;drc=afadfb24a5e608da6ae102b20b0add53a083dcf3
155*d9f75844SAndroid Build Coastguard Worker[video-decoder-factory-interface]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/api/video_codecs/video_decoder_factory.h;l=27;drc=49c293f03d8f593aa3aca282577fcb14daa63207
156*d9f75844SAndroid Build Coastguard Worker[scalability-structure-spec]: https://w3c.github.io/webrtc-svc/#scalabilitymodes*
157*d9f75844SAndroid Build Coastguard Worker[fec-wiki]: https://en.wikipedia.org/wiki/Error_correction_code#Forward_error_correction
158*d9f75844SAndroid Build Coastguard Worker[entropy-coding-wiki]: https://en.wikipedia.org/wiki/Entropy_encoding
159*d9f75844SAndroid Build Coastguard Worker[modules-video-coding]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/
160*d9f75844SAndroid Build Coastguard Worker[modules-video-coding-codecs]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/codecs/
161*d9f75844SAndroid Build Coastguard Worker[modules-video-coding-codecs-test]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/codecs/test/
162*d9f75844SAndroid Build Coastguard Worker[modules-video-coding-svc]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/svc/
163*d9f75844SAndroid Build Coastguard Worker[modules-video-coding-utility]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/utility/
164*d9f75844SAndroid Build Coastguard Worker[scalabilitystructure]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/svc/create_scalability_structure.h?q=CreateScalabilityStructure
165*d9f75844SAndroid Build Coastguard Worker[scalablevideocontroller]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/svc/scalable_video_controller.h?q=ScalableVideoController
166*d9f75844SAndroid Build Coastguard Worker[svcrateallocator]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/svc/svc_rate_allocator.h?q=SvcRateAllocator
167*d9f75844SAndroid Build Coastguard Worker[framedropper]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/utility/frame_dropper.h?q=FrameDropper
168*d9f75844SAndroid Build Coastguard Worker[frameratecontroller]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/utility/framerate_controller.h?q=FramerateController
169*d9f75844SAndroid Build Coastguard Worker[qpparser]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/utility/qp_parser.h?q=QpParser
170*d9f75844SAndroid Build Coastguard Worker[qualityscaler]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/utility/quality_scaler.h?q=QualityScaler
171*d9f75844SAndroid Build Coastguard Worker[simulcastrateallocator]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/utility/simulcast_rate_allocator.h?q=SimulcastRateAllocator
172*d9f75844SAndroid Build Coastguard Worker[feccontrollerdefault]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/fec_controller_default.h?q=FecControllerDefault
173*d9f75844SAndroid Build Coastguard Worker[videocodecinitializer]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/include/video_codec_initializer.h?q=VideoCodecInitializer
174*d9f75844SAndroid Build Coastguard Worker[packetbuffer]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/packet_buffer.h?q=PacketBuffer
175*d9f75844SAndroid Build Coastguard Worker[rtpframereferencefinder]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/rtp_frame_reference_finder.h?q=RtpFrameReferenceFinder
176*d9f75844SAndroid Build Coastguard Worker[framebuffer]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/video_coding/frame_buffer2.h?q=FrameBuffer
177*d9f75844SAndroid Build Coastguard Worker[quantization-wiki]: https://en.wikipedia.org/wiki/Quantization_(signal_processing)
178