Video sources are used to add video samples (frames) to output video tracks. All video sources extend the baseDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Vanilagy/mediabunny/llms.txt
Use this file to discover all available pages before exploring further.
VideoSource class.
CanvasSource
Captures frames from an HTML canvas or OffscreenCanvas element and encodes them for the output video track.Constructor
The canvas element to capture frames from.
Configuration object that controls video encoding.
Methods
add
Captures the current canvas state as a video frame, encodes it, and adds it to the output.The timestamp of the sample in seconds.
The duration of the sample in seconds.
Additional WebCodecs encoding options.
Resolves when the output is ready to receive more samples. Await this to respect backpressure.
close
Closes the source, preventing future samples and signaling no more data will be added to this track.Calling
close() is optional but recommended after adding the last sample for improved performance and reduced memory usage.VideoSampleSource
Adds raw, unencoded video samples (frames) to an output video track with automatic encoding.Constructor
Configuration object that controls video encoding. See CanvasSource for detailed properties.
Methods
add
Encodes a video sample (frame) and adds it to the output.The video sample to encode and add.
Additional WebCodecs encoding options.
Resolves when the output is ready to receive more samples. Await this to respect backpressure.
close
Closes the source. See CanvasSource.close() for details.EncodedVideoPacketSource
Directly pipes pre-encoded video packets into the output file without additional encoding.Constructor
The codec used to encode the packets:
'avc', 'hevc', 'vp8', 'vp9', or 'av1'.Methods
add
Adds an encoded packet to the output video track. Packets must be added in decode order, while timestamps must be presentation timestamps. B-frames are handled automatically.The encoded video packet to add. Cannot be a metadata-only packet.
Additional encoder metadata. You should pass this for the first call, including a valid decoder config.
Resolves when the output is ready to receive more samples. Await this to respect backpressure.
close
Closes the source. See CanvasSource.close() for details.MediaStreamVideoTrackSource
Encodes frames from a liveMediaStreamVideoTrack (e.g., webcam or screen capture) and pipes them to the output. Frames are automatically captured once the connected Output is started.
Constructor
The video MediaStreamTrack to capture frames from.
Configuration object that controls video encoding.
latencyMode is automatically set to 'realtime'. See CanvasSource for other properties.Properties
A promise that rejects upon any error within this source. This promise never resolves. You should handle this promise to catch internal errors.
Whether this source is currently paused as a result of calling
pause().Methods
pause
Pauses the capture of video frames. Frames emitted by the media stream are ignored while paused. This does not close the underlying track.resume
Resumes the capture of video frames after being paused.close
Stops capturing and closes the source. See CanvasSource.close() for details.Make sure to handle the
errorPromise field so that internal errors are properly surfaced.