mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-05-20 01:08:06 +00:00
ace2799c75
This introduces the 'Metadata' trait to enable access to common video metadata such title, year, cover art and more. Reading 'title', 'description', 'poster' and 'year' metadata is implemented here.
31 lines
741 B
Rust
31 lines
741 B
Rust
use std::{
|
|
convert::TryFrom,
|
|
io::{Read, Seek},
|
|
};
|
|
|
|
use serde::Serialize;
|
|
|
|
use crate::mp4box::*;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
|
|
pub struct DataBox {
|
|
pub data: Vec<u8>,
|
|
pub data_type: DataType,
|
|
}
|
|
|
|
impl<R: Read + Seek> ReadBox<&mut R> for DataBox {
|
|
fn read_box(reader: &mut R, size: u64) -> Result<Self> {
|
|
let start = box_start(reader)?;
|
|
|
|
let data_type = DataType::try_from(reader.read_u32::<BigEndian>()?)?;
|
|
|
|
reader.read_u32::<BigEndian>()?; // reserved = 0
|
|
|
|
let current = reader.seek(SeekFrom::Current(0))?;
|
|
let mut data = vec![0u8; (start + size - current) as usize];
|
|
reader.read_exact(&mut data)?;
|
|
|
|
Ok(DataBox { data, data_type })
|
|
}
|
|
}
|