Class Vp8StreamEncoder
Encodes a VP8 video stream (RFC 6386) a frame at a time: key frames, and inter frames that search the last, golden and alternate references for motion and code every VP8 vector mode. Each frame's Vp8FramePlan says what it is (key or inter, shown or hidden), its quality or quantizer, and which references it uses and refreshes, so rate control and group-of-frames planning stay with the caller: Egami.Video drives this encoder for WebM, MKV and IVF, and any other source of frames can too. The frames decode in libvpx exactly as in Vp8StreamDecoder.
public sealed class Vp8StreamEncoder : IDisposable
- Inheritance
-
Vp8StreamEncoder
- Implements
- Inherited Members
Examples
// 4:2:0 pictures of one size, here decoded from a clip; Egami.Video writes WebM and IVF and plans the frames for you.
using Vp8StreamEncoder encoder = new(pictures[0].Width, pictures[0].Height);
for (int i = 0; i < pictures.Count; i++)
{
Vp8FramePlan plan = new()
{
KeyFrame = i % 30 == 0, // a key frame a second at 30 frames a second
RefreshGolden = i % 10 == 0, // and a golden frame to fall back on every tenth
Quality = 70,
};
Vp8EncodedFrame frame = encoder.Encode(pictures[i], plan);
packets.Add(frame.Data.ToArray()); // a WebM block or an IVF frame; frame.LumaPsnr says how close it came
}
Remarks
The encoder keeps the stream's references in four frame buffers from the context's Memory. It codes a frame's macroblock rows on up to MaxParallelism threads, each row a little behind the one above; the output does not depend on the thread count. The frame size is checked against the context's Limits. An instance is not thread-safe.
Constructors
Vp8StreamEncoder(int, int, EgamiContext?)
Starts a stream of width × height frames.
public Vp8StreamEncoder(int width, int height, EgamiContext? context = null)
Parameters
widthintThe frame width, 1 to 16383.
heightintThe frame height, 1 to 16383.
contextEgamiContextThe memory, threads and limits to use; Default when null.
Exceptions
- ArgumentOutOfRangeException
The width or height is outside 1 to 16383.
- LimitExceededException
The frame size breaks the context's safety limits.
Properties
Height
Gets the frame height.
public int Height { get; }
Property Value
Width
Gets the frame width.
public int Width { get; }
Property Value
Methods
Dispose()
Returns the frame buffers to the memory source and stops the decoder's threads.
public void Dispose()
Encode(YuvRaster<byte>, Vp8FramePlan)
Encodes one frame as plan says and updates the references. The first frame is always a key frame.
public Vp8EncodedFrame Encode(YuvRaster<byte> frame, Vp8FramePlan plan)
Parameters
frameYuvRaster<byte>The picture: 4:2:0, 8 bits, at the stream's size; its color is taken as VP8's (BT.601, limited range).
planVp8FramePlanHow to code the frame.
Returns
- Vp8EncodedFrame
The frame's data, as a WebM block or an IVF frame holds it, and what coding it cost.
Exceptions
- ArgumentException
frameis not 4:2:0 8-bit at the stream's size, or the plan copies a reference onto itself.