stbl(Sample Table Box)

Created
Jan 23, 2022 09:36 AM
Tags
use crate::atoms::*; use crate::atoms::{ co64::Co64Box, ctts::CttsBox, stco::StcoBox, stsc::StscBox, stsd::StsdBox, stss::StssBox, stsz::StszBox, stts::SttsBox, }; #[derive(Debug, Clone, PartialEq, Default)] pub struct StblBox { pub stsd: StsdBox, pub stts: SttsBox, pub ctts: Option<CttsBox>, pub stss: Option<StssBox>, pub stsc: StscBox, pub stsz: StszBox, pub stco: Option<StcoBox>, pub co64: Option<Co64Box>, } impl StblBox { pub fn get_type(&self) -> BoxType { BoxType::StblBox } pub fn get_size(&self) -> u64 { let mut size = HEADER_SIZE; size += self.stsd.box_size(); size += self.stts.box_size(); if let Some(ref ctts) = self.ctts { size += ctts.box_size(); } if let Some(ref stss) = self.stss { size += stss.box_size(); } size += self.stsc.box_size(); size += self.stsz.box_size(); if let Some(ref stco) = self.stco { size += stco.box_size(); } if let Some(ref co64) = self.co64 { size += co64.box_size(); } size } }
在MP4文件中,媒体数据被分成多个chunk,每个chunk可包含多个sample,而sample则由帧组成(通常1个sample对应1个帧)
 
Box Type: ‘stbl’ Container: Media Information Box (‘minf’) Mandatory: Yes Quantity: Exactly one
 
The sample table contains all the time and data indexing of the media samples in a track. Using the tables here, it is possible to locate samples in time, determine their type (e.g. I-frame or not), and determine their size, container, and offset into that container. If the track that contains the Sample Table Box references no data, then the Sample Table Box does not need to contain any sub-boxes (this is not a very useful media track). If the track that the Sample Table Box is contained in does reference data, then the following sub-boxes are required: Sample Description, Sample Size, Sample To Chunk, and Chunk Offset. Further, the Sample Description Box shall contain at least one entry. A Sample Description Box is required because it contains the data reference index field which indicates which Data Reference Box to use to retrieve the media samples. Without the Sample Description, it is not possible to determine where the media samples are stored. The Sync Sample Box is optional. If the Sync Sample Box is not present, all samples are sync samples.
 
stbl中比较关键的box包含stsd、stco、stsc、stsz、stts、stss、ctts
下面是这几个box概要的介绍:
  • stsd:给出视频、音频的编码、宽高、音量等信息,以及每个sample中包含多少个frame;
  • stco:thunk在文件中的偏移;
  • stsc:每个thunk中包含几个sample;
  • stsz:每个sample的size(单位是字节);
  • stts:每个sample的时长;
  • stss:哪些sample是关键帧;
  • ctts:帧解码到渲染的时间差值,通常用在B帧的场景;