mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-06-02 13:39:54 +00:00
feat: mvex box中的mehd box改为可选,支持fmp4的解析
This commit is contained in:
parent
9e8f27be2a
commit
e85ef6a66f
|
@ -54,7 +54,9 @@ fn get_boxes(file: File) -> Result<Vec<Box>> {
|
|||
|
||||
if let Some(ref mvex) = &mp4.moov.mvex {
|
||||
boxes.push(build_box(mvex));
|
||||
boxes.push(build_box(&mvex.mehd));
|
||||
if let Some(mehd) = &mvex.mehd {
|
||||
boxes.push(build_box(mehd));
|
||||
}
|
||||
boxes.push(build_box(&mvex.trex));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::mp4box::{mehd::MehdBox, trex::TrexBox};
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
|
||||
pub struct MvexBox {
|
||||
pub mehd: MehdBox,
|
||||
pub mehd: Option<MehdBox>,
|
||||
pub trex: TrexBox,
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ impl MvexBox {
|
|||
}
|
||||
|
||||
pub fn get_size(&self) -> u64 {
|
||||
HEADER_SIZE + self.mehd.box_size() + self.trex.box_size()
|
||||
HEADER_SIZE + self.mehd.as_ref().map(|x| x.box_size()).unwrap_or(0) + self.trex.box_size()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,6 @@ impl<R: Read + Seek> ReadBox<&mut R> for MvexBox {
|
|||
current = reader.seek(SeekFrom::Current(0))?;
|
||||
}
|
||||
|
||||
if mehd.is_none() {
|
||||
return Err(Error::BoxNotFound(BoxType::MehdBox));
|
||||
}
|
||||
if trex.is_none() {
|
||||
return Err(Error::BoxNotFound(BoxType::TrexBox));
|
||||
}
|
||||
|
@ -79,7 +76,7 @@ impl<R: Read + Seek> ReadBox<&mut R> for MvexBox {
|
|||
skip_bytes_to(reader, start + size)?;
|
||||
|
||||
Ok(MvexBox {
|
||||
mehd: mehd.unwrap(),
|
||||
mehd,
|
||||
trex: trex.unwrap(),
|
||||
})
|
||||
}
|
||||
|
@ -90,7 +87,9 @@ impl<W: Write> WriteBox<&mut W> for MvexBox {
|
|||
let size = self.box_size();
|
||||
BoxHeader::new(self.box_type(), size).write(writer)?;
|
||||
|
||||
self.mehd.write_box(writer)?;
|
||||
if let Some(mehd) = &self.mehd{
|
||||
mehd.write_box(writer)?;
|
||||
}
|
||||
self.trex.write_box(writer)?;
|
||||
|
||||
Ok(size)
|
||||
|
|
Loading…
Reference in a new issue