moov(Movie Box)

Created
Jan 18, 2022 04:31 PM
Tags
Movie Box,存储 mp4 的 metadata,一般位于mp4文件的开头。
The metadata for a presentation is stored in the single Movie Box which occurs at the top-level of a file. Normally this box is close to the beginning or end of the file, though this is not required.
mvhd:Movie Header Box,mp4文件的整体信息,比如创建时间、文件时长等;
trak:Track Box,一个mp4可以包含一个或多个轨道(比如视频轨道、音频轨道),轨道相关的信息就在trak里。trak是container box,至少包含两个box,tkhd、mdia;
 
⚠️
mvhd针对整个影片,tkhd针对单个track,mdhd针对媒体,vmhd针对视频,smhd针对音频,可以认为是从 宽泛 > 具体,前者一般是从后者推导出来的。
 
use crate::atoms::{mvex::MvexBox, mvhd::MvhdBox, trak::TrakBox}; use crate::atoms::{BoxType, HEADER_SIZE}; #[derive(Debug, Clone, PartialEq, Default)] pub struct MoovBox { pub mvhd: MvhdBox, pub mvex: Option<MvexBox>, pub traks: Vec<TrakBox>, } impl MoovBox { pub fn get_type(&self) -> BoxType { BoxType::MoovBox } pub fn get_size(&self) -> u64 { let mut size = HEADER_SIZE + self.mvhd.box_size(); for trak in self.traks.iter() { size += trak.box_size(); } size } }