mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-12-23 04:26:27 +00:00
Add skip fn for skipping remaining bytes in a box.
This commit is contained in:
parent
67303df65e
commit
f04ebb4b61
3 changed files with 20 additions and 57 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -7,7 +7,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mp4"
|
name = "mp4"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mp4"
|
name = "mp4"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
authors = ["Alf <alf.g.jr@gmail.com>"]
|
authors = ["Alf <alf.g.jr@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
73
src/atoms.rs
73
src/atoms.rs
|
@ -390,11 +390,7 @@ fn parse_mvhd_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Mv
|
||||||
let timescale = f.read_u32::<BigEndian>().unwrap();
|
let timescale = f.read_u32::<BigEndian>().unwrap();
|
||||||
let duration = f.read_u32::<BigEndian>().unwrap();
|
let duration = f.read_u32::<BigEndian>().unwrap();
|
||||||
let rate = f.read_u32::<BigEndian>().unwrap();
|
let rate = f.read_u32::<BigEndian>().unwrap();
|
||||||
|
skip(f, current, size);
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
|
|
||||||
Ok(MvhdBox{
|
Ok(MvhdBox{
|
||||||
version,
|
version,
|
||||||
|
@ -433,11 +429,8 @@ fn parse_trak_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Tr
|
||||||
_ => break
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
skip(f, current, size);
|
||||||
|
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
Ok(trak)
|
Ok(trak)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,11 +467,7 @@ fn parse_tkhd_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Tk
|
||||||
|
|
||||||
let width = f.read_u32::<BigEndian>().unwrap() >> 8;
|
let width = f.read_u32::<BigEndian>().unwrap() >> 8;
|
||||||
let height = f.read_u32::<BigEndian>().unwrap() >> 8;
|
let height = f.read_u32::<BigEndian>().unwrap() >> 8;
|
||||||
|
skip(f, current, size);
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
|
|
||||||
Ok(TkhdBox {
|
Ok(TkhdBox {
|
||||||
version,
|
version,
|
||||||
|
@ -514,11 +503,8 @@ fn parse_edts_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Ed
|
||||||
_ => break
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
skip(f, current, size);
|
||||||
|
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
Ok(edts)
|
Ok(edts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,11 +525,7 @@ fn parse_elst_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<El
|
||||||
};
|
};
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
}
|
}
|
||||||
|
skip(f, current, size);
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
|
|
||||||
Ok(ElstBox {
|
Ok(ElstBox {
|
||||||
version,
|
version,
|
||||||
|
@ -578,11 +560,8 @@ fn parse_mdia_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Md
|
||||||
_ => break
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
skip(f, current, size);
|
||||||
|
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
Ok(mdia)
|
Ok(mdia)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,11 +579,7 @@ fn parse_mdhd_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Md
|
||||||
let duration = f.read_u32::<BigEndian>().unwrap();
|
let duration = f.read_u32::<BigEndian>().unwrap();
|
||||||
let language = f.read_u16::<BigEndian>().unwrap();
|
let language = f.read_u16::<BigEndian>().unwrap();
|
||||||
let language_string = get_language_string(language);
|
let language_string = get_language_string(language);
|
||||||
|
skip(f, current, size);
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
|
|
||||||
Ok(MdhdBox {
|
Ok(MdhdBox {
|
||||||
version,
|
version,
|
||||||
|
@ -653,11 +628,7 @@ fn parse_hdlr_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Hd
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
_ => String::from("null"),
|
_ => String::from("null"),
|
||||||
};
|
};
|
||||||
|
skip(f, current, size);
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
|
|
||||||
Ok(HdlrBox {
|
Ok(HdlrBox {
|
||||||
version,
|
version,
|
||||||
|
@ -695,11 +666,8 @@ fn parse_minf_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Mi
|
||||||
_ => break
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
skip(f, current, size);
|
||||||
|
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
Ok(minf)
|
Ok(minf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,11 +681,7 @@ fn parse_vmhd_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Vm
|
||||||
let flags = u32::from(flags_a) << 16 | u32::from(flags_b) << 8 | u32::from(flags_c);
|
let flags = u32::from(flags_a) << 16 | u32::from(flags_b) << 8 | u32::from(flags_c);
|
||||||
let graphics_mode = f.read_u16::<BigEndian>().unwrap();
|
let graphics_mode = f.read_u16::<BigEndian>().unwrap();
|
||||||
let op_color = f.read_u16::<BigEndian>().unwrap();
|
let op_color = f.read_u16::<BigEndian>().unwrap();
|
||||||
|
skip(f, current, size);
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
|
|
||||||
Ok(VmhdBox {
|
Ok(VmhdBox {
|
||||||
version,
|
version,
|
||||||
|
@ -769,11 +733,7 @@ fn parse_stts_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<St
|
||||||
sample_counts.push(sc);
|
sample_counts.push(sc);
|
||||||
sample_deltas.push(sd);
|
sample_deltas.push(sd);
|
||||||
}
|
}
|
||||||
|
skip(f, current, size);
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
|
|
||||||
Ok(SttsBox {
|
Ok(SttsBox {
|
||||||
version,
|
version,
|
||||||
|
@ -810,13 +770,16 @@ fn parse_stsd_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<St
|
||||||
_ => break
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
skip(f, current, size);
|
||||||
|
|
||||||
// Skip remaining bytes.
|
|
||||||
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
|
||||||
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
|
||||||
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
|
||||||
Ok(StsdBox {
|
Ok(StsdBox {
|
||||||
version,
|
version,
|
||||||
flags,
|
flags,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn skip(f: &mut BufReader<File>, current: u64, size: u32) {
|
||||||
|
let after = f.seek(SeekFrom::Current(0)).unwrap();
|
||||||
|
let remaining_bytes = (size as u64 - (after - current)) as i64;
|
||||||
|
f.seek(SeekFrom::Current(remaining_bytes - HEADER_SIZE as i64)).unwrap();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue