Segment

Struct Segment 

Source
pub struct Segment<W: Write> { /* private fields */ }
Expand description

A fully-built Matroska segment. This is where actual video/audio frames are written.

This is created via SegmentBuilder. Once built in this way, the list of tracks and their parameters become immutable.

§Finalization

Once you are done writing frames to this segment, you must call Segment::finalize on it. This performs a few final writes, and the resulting WebM may not be playable without it. Notably, for memory safety reasons, just dropping a Segment will not finalize it!

Implementations§

Source§

impl<W: Write> Segment<W>

Source

pub fn add_frame( &mut self, track: impl Into<TrackNum>, data: &[u8], timestamp_ns: u64, keyframe: bool, ) -> Result<(), Error>

Adds a frame to the track with the specified track number. If you have a VideoTrack or AudioTrack, you can either pass it directly, or call track_number() to get the underlying TrackNum.

The timestamp must be in nanosecond units, and must be monotonically increasing with respect to all other timestamps written so far, including those of other tracks! Repeating the last written timestamp is allowed, however players generally don’t handle this well if both such frames are on the same track.

Source

pub fn finalize(self, duration: Option<u64>) -> Result<Writer<W>, Writer<W>>

Finalizes the segment and consumes it, returning the underlying writer. Note that the finalizing process will itself trigger writes (such as to write seeking information).

The resulting WebM may not be playable if you drop the Segment without calling this first!

You may specify an explicit duration to be written to the segment’s Duration element. However, this requires seeking and thus will be ignored if the writer was not created with Seek support.

Finalization is known to fail if no frames have been written.

Trait Implementations§

Source§

impl<W: Write> Debug for Segment<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Segment<W>

§

impl<W> RefUnwindSafe for Segment<W>
where W: RefUnwindSafe,

§

impl<W> Send for Segment<W>
where W: Send,

§

impl<W> !Sync for Segment<W>

§

impl<W> Unpin for Segment<W>

§

impl<W> UnwindSafe for Segment<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.