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
impl MediaFile
Sourcepub async fn open(path: impl AsRef<Path>) -> Result<Self, Error>
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.
Sourcepub fn with_end(self, end: FileEnd) -> Self
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.
Sourcepub fn encoded_video(&self) -> Result<EncodedVideo, Error>
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.
Sourcepub fn encoded_audio(&self) -> Result<EncodedAudio, Error>
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.
Sourcepub async fn video(&self, config: VideoFileConfig) -> Result<VideoSource, Error>
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.
Sourcepub fn audio(&self) -> Result<AudioSource, Error>
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.