1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-05-19 16:58:04 +00:00

Add Mp4Writer::into_writer (#44)

This commit is contained in:
John-John Tedro 2021-01-28 03:07:21 +01:00 committed by GitHub
parent 2a33b990e6
commit d73e80107d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,43 @@ pub struct Mp4Writer<W> {
duration: u64,
}
impl<W> Mp4Writer<W> {
/// Consume self, returning the inner writer.
///
/// This can be useful to recover the inner writer after completion in case
/// it's owned by the [Mp4Writer] instance.
///
/// # Examples
///
/// ```rust
/// use mp4::{Mp4Writer, Mp4Config};
/// use std::io::Cursor;
///
/// # fn main() -> mp4::Result<()> {
/// let config = Mp4Config {
/// major_brand: "isom / 0x69736F6D".into(),
/// minor_version: 512,
/// compatible_brands: vec![
/// "isom".into(),
/// "iso2".into(),
/// "avc1".into(),
/// "mp41".into(),
/// ],
/// timescale: 1000,
/// };
///
/// let data = Cursor::new(Vec::<u8>::new());
/// let mut writer = mp4::Mp4Writer::write_start(data, &config)?;
/// writer.write_end()?;
///
/// let data: Vec<u8> = writer.into_writer().into_inner();
/// # Ok(()) }
/// ```
pub fn into_writer(self) -> W {
self.writer
}
}
impl<W: Write + Seek> Mp4Writer<W> {
pub fn write_start(mut writer: W, config: &Mp4Config) -> Result<Self> {
let ftyp = FtypBox {