1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2025-04-15 08:14:15 +00:00
This commit is contained in:
damitha 2025-03-25 21:00:23 +11:00
parent 90d089bf83
commit 3f9084df05
4 changed files with 41 additions and 37 deletions

View file

@ -101,38 +101,31 @@ impl<R: Read + Seek> ReadBox<&mut R> for Hvc1Box {
let depth = reader.read_u16::<BigEndian>()?;
reader.read_i16::<BigEndian>()?; // pre-defined
let mut hvcc = None;
while reader.stream_position()? < start + size {
let header = BoxHeader::read(reader)?;
let BoxHeader { name, size: s } = header;
if s > size {
return Err(Error::InvalidData(
"hvc1 box contains a box with a larger size than it",
));
}
if name == BoxType::HvcCBox {
hvcc = Some(HvcCBox::read_box(reader, s)?);
} else {
skip_box(reader, s)?;
}
let header = BoxHeader::read(reader)?;
let BoxHeader { name, size: s } = header;
if s > size {
return Err(Error::InvalidData(
"hev1 box contains a box with a larger size than it",
));
}
let Some(hvcc) = hvcc else {
return Err(Error::InvalidData("hvcc not found"));
};
if name == BoxType::HvcCBox {
let hvcc = HvcCBox::read_box(reader, s)?;
skip_bytes_to(reader, start + size)?;
skip_bytes_to(reader, start + size)?;
Ok(Hvc1Box {
data_reference_index,
width,
height,
horizresolution,
vertresolution,
frame_count,
depth,
hvcc,
})
Ok(Hvc1Box {
data_reference_index,
width,
height,
horizresolution,
vertresolution,
frame_count,
depth,
hvcc,
})
} else {
Err(Error::InvalidData("hvcc not found"))
}
}
}

View file

@ -170,11 +170,11 @@ impl<W: Write> WriteBox<&mut W> for Mp4aBox {
writer.write_u32::<BigEndian>(0)?; // reserved
writer.write_u32::<BigEndian>(self.samplerate.raw_value())?;
if self.sound_version !=0 {
if let Some(ref qt_bytes) = self.qt_bytes {
writer.write_all(&qt_bytes)?;
if self.sound_version != 0 {
if let Some(ref qt_bytes) = self.qt_bytes {
writer.write_all(&qt_bytes)?;
}
}
}
if let Some(ref esds) = self.esds {
esds.write_box(writer)?;

View file

@ -4,7 +4,9 @@ use std::io::{Read, Seek, Write};
use crate::mp4box::vp09::Vp09Box;
use crate::mp4box::*;
use crate::mp4box::{avc1::Avc1Box, hev1::Hev1Box, hvc1::Hvc1Box, mp4a::Mp4aBox, opus::OpusBox, tx3g::Tx3gBox};
use crate::mp4box::{
avc1::Avc1Box, hev1::Hev1Box, hvc1::Hvc1Box, mp4a::Mp4aBox, opus::OpusBox, tx3g::Tx3gBox,
};
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize)]
pub struct StsdBox {

View file

@ -219,7 +219,10 @@ impl Mp4Track {
if let Some(ref dops) = opus.dops_box {
SampleFreqIndex::try_from(dops.input_sample_rate)
} else {
Err(Error::BoxInStblNotFound(self.track_id(), vec![BoxType::DopsBox]))
Err(Error::BoxInStblNotFound(
self.track_id(),
vec![BoxType::DopsBox],
))
}
} else {
Err(Error::BoxInStblNotFound(
@ -243,7 +246,10 @@ impl Mp4Track {
if let Some(ref dops) = opus.dops_box {
ChannelConfig::try_from(dops.output_channel_count)
} else {
Err(Error::BoxInStblNotFound(self.track_id(), vec![BoxType::DopsBox]))
Err(Error::BoxInStblNotFound(
self.track_id(),
vec![BoxType::DopsBox],
))
}
} else {
Err(Error::BoxInStblNotFound(
@ -344,7 +350,10 @@ impl Mp4Track {
return Ok(esds);
}
}
Err(Error::BoxInStblNotFound(self.track_id(), vec![BoxType::EsdsBox]))
Err(Error::BoxInStblNotFound(
self.track_id(),
vec![BoxType::EsdsBox],
))
}
pub fn picture_parameter_set(&self) -> Result<&[u8]> {