Class Vp8StreamDecoder
Decodes a VP8 video stream (RFC 6386) a frame at a time, as WebM and IVF files carry it: key frames and inter frames, with the last, golden and alternate references, motion vectors and hidden frames. The frames equal libvpx's sample for sample. Feed the frames in stream order; decoding starts at a key frame. Containers are not read here: Egami.Video reads WebM and IVF and uses this decoder, and any other source of VP8 frames can too.
public sealed class Vp8StreamDecoder : IDisposable
- Inheritance
-
Vp8StreamDecoder
- Implements
- Inherited Members
Examples
// VP8 frames in stream order, here from an IVF file (Egami.Video reads WebM and IVF for you).
using Vp8StreamDecoder decoder = new() { ConcealErrors = false };
YuvRaster<byte>? picture = null;
foreach (byte[] packet in IvfFrames("clip.ivf"))
{
Vp8FrameInfo info = decoder.Decode(packet);
if (!info.IsShown)
{
continue; // a hidden frame, typically an alternate reference: it only updates the references
}
picture ??= YuvRaster.Create(info.Width, info.Height, ChromaFormat.Yuv420, YuvColor.Bt601Limited);
decoder.CopyFrameTo(picture); // the picture is the caller's: change it or keep it
shown++;
}
picture?.Dispose();
Remarks
The decoder keeps four frame buffers from the context's Memory for its life and decodes a frame's macroblock rows on up to MaxParallelism threads (as many as the frame's token partitions allow). Its frame size is checked against the context's Limits. An instance is not thread-safe.
Constructors
Vp8StreamDecoder(EgamiContext?)
Starts a stream.
public Vp8StreamDecoder(EgamiContext? context = null)
Parameters
contextEgamiContextThe memory, threads and limits to use; Default when null.
Properties
ConcealErrors
Gets or sets whether broken frames are concealed instead of throwing. When set, a frame whose data runs out has the macroblocks it could not read copied from the previous frame (mid-gray when there is none), a frame whose header cannot be read shows the previous frame again, and an inter frame with no key frame before it predicts from mid-gray; the frame's IsConcealed says so. Defaults to false: broken data throws CorruptDataException.
public bool ConcealErrors { get; set; }
Property Value
Methods
CopyFrameTo(YuvRaster<byte>)
Copies the frame the last Decode(ReadOnlySpan<byte>) showed into destination: its Y, U and V planes, which
the decoder's references do not share, so the copy can be changed or kept.
public void CopyFrameTo(YuvRaster<byte> destination)
Parameters
destinationYuvRaster<byte>A 4:2:0 8-bit raster of the frame's size; its color is left as it is (VP8 is BT.601, limited range).
Exceptions
- InvalidOperationException
The last frame decoded was not shown, or none has been.
- ArgumentException
destinationis not 4:2:0 at the frame's size.
Decode(ReadOnlySpan<byte>)
Decodes one VP8 frame and updates the references. When the result's IsShown is true, CopyFrameTo(YuvRaster<byte>) then copies the picture out; a hidden frame (typically an alternate reference) only updates the references.
public Vp8FrameInfo Decode(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame's data, as a WebM block or an IVF frame holds it.
Returns
- Vp8FrameInfo
What the frame was.
Exceptions
- CorruptDataException
The data is broken, or the stream does not start with a key frame, and ConcealErrors is false.
- LimitExceededException
A key frame's size breaks the context's safety limits.
Dispose()
Returns the frame buffers to the memory source and stops the decoder's threads.
public void Dispose()
Reset()
Drops the references; the next frame must be a key frame (or, with ConcealErrors, is concealed).
public void Reset()