encodeI420Frame method
Convenience wrapper around encodeFrame for tightly-packed I420
(a.k.a. YUV 4:2:0 planar). The input must contain exactly
width*height + 2*(width/2)*(height/2) == width*height*3/2
bytes laid out as Y plane, then U plane, then V plane. Y stride
is taken as width; UV stride as width/2. Throws
ArgumentError on a wrong-sized buffer.
Implementation
EncodedVp8Frame encodeI420Frame(Uint8List i420,
{bool? forceKey, int? qiOverride}) {
final ySize = width * height;
final uvSize = (width >> 1) * (height >> 1);
final expected = ySize + 2 * uvSize;
if (i420.length != expected) {
throw ArgumentError(
'encodeI420Frame: expected $expected bytes for ${width}x$height '
'I420, got ${i420.length}');
}
final y = Uint8List.sublistView(i420, 0, ySize);
final u = Uint8List.sublistView(i420, ySize, ySize + uvSize);
final v = Uint8List.sublistView(i420, ySize + uvSize, expected);
return encodeFrame(
srcY: y,
srcU: u,
srcV: v,
srcYStride: width,
srcUvStride: width >> 1,
forceKey: forceKey,
qiOverride: qiOverride,
);
}