Skip to main content

MediaFile

Struct MediaFile 

Source
pub struct MediaFile { /* private fields */ }
Expand description

An MP4 file, ready to publish as it is or to decode.

Opening reads the boxes that describe the file and none of its media. Cheap to clone: clones share the file and its clock.

Implementations§

Source§

impl MediaFile

Source

pub async fn open(path: impl AsRef<Path>) -> Result<Self, Error>

Opens the MP4 file at path, plain or fragmented, and reads its sample index.

The file plays once, and with_end makes it loop. The index stays in memory, about 40 bytes per sample, which is 22 MB for two hours of 30 fps video with 48 kHz AAC.

§Errors

Fails with Error::Device if the file cannot be read, is not an MP4 file, is corrupt, or holds neither audio nor video.

Source

pub fn with_end(self, end: FileEnd) -> Self

Returns this file with end as what its streams do at the end of the file.

With FileEnd::Restart, every stream starts over after the longest track ends, and timestamps keep rising across the passes.

Source

pub fn info(&self) -> &MediaInfo

Returns the file’s tracks, codecs and length.

Source

pub fn path(&self) -> &Path

Returns the path the file was opened from.

Source

pub fn encoded_video(&self) -> Result<EncodedVideo, Error>

Returns the file’s H.264 video as it is, paced to the wall clock.

For LocalBroadcast::set_encoded_video. Each access unit is due when its decode time comes. Passthrough costs no CPU and keeps the original quality, but it publishes one rendition at the file’s size and bitrate. Keyframes come only where the file has them, and nothing can ask for another. A stream that starts while the file already plays starts at the next keyframe. A read error ends the stream with that error.

§Errors

Fails with Error::InvalidConfig if the file has no video, or video in another codec than H.264.

Source

pub fn encoded_audio(&self) -> Result<EncodedAudio, Error>

Returns the file’s AAC audio as it is, paced to the wall clock.

For LocalBroadcast::set_encoded_audio, with the trade-offs of encoded_video.

§Errors

Fails with Error::InvalidConfig if the file has no audio, or audio in another codec than AAC.

Source

pub async fn video(&self, config: VideoFileConfig) -> Result<VideoSource, Error>

Decodes the file’s H.264 video in real time into a raw source, like a camera.

Each picture comes when its presentation time is due, at the file’s size and in the decoder’s own memory, so a hardware decoder’s pictures reach a hardware encoder without a copy. The renditions of the broadcast scale them. The rate is the track’s average. The decoder opens before this returns, and decodes whether or not a broadcast wants the source.

Cancellation safe: dropping the future stops the decode thread.

§Errors

Fails with Error::InvalidConfig for a file without H.264 video, and with Error::Decoder if no decoder of the VideoFileConfig::decoder backend opens. A read or decode error later fails the source, as VideoSource::failure reports.

Source

pub fn audio(&self) -> Result<AudioSource, Error>

Decodes the file’s AAC audio in real time into a raw source, like a microphone.

The samples keep the file’s rate and layout and come when they are due.

§Errors

Fails with Error::InvalidConfig if the file has no AAC audio, and with Error::Decoder if the decoder does not open.

Trait Implementations§

Source§

impl Clone for MediaFile

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MediaFile

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more