File Type Box

Created
Jan 18, 2022 04:31 PM
Tags
Box Type: `ftyp’
Container: File
Mandatory: Yes
Quantity: Exactly one
isom(ISO Base Media file)是在 MPEG-4 Part 12 中定义的一种基础文件格式,MP4、3gp、QT 等常见的封装格式,都是基于这种基础文件格式衍生的。
aligned(8) class FileTypeBox extends Box(‘ftyp’) { unsigned int(32) major_brand; unsigned int(32) minor_version; unsigned int(32) compatible_brands[]; }
This box identifies the specifications to which this file complies. Each brand is a printable four-character code, registered with ISO, that identifies a precise specification.
major_brand – is a brand identifier minor_version – is an informative integer for the minor version of the major brand compatible_brands – is a list, to the end of the box, of brands
major_brand:比如常见的 isom、mp41、mp42、avc1、qt等。它表示“最好”基于哪种格式来解析当前的文件。举例,major_brand 是 A,compatible_brands 是 A1,当解码器同时支持 A、A1 规范时,最好使用A规范来解码当前媒体文件,如果不支持A规范,但支持A1规范,那么,可以使用A1规范来解码;minor_version:提供 major_brand 的说明信息,比如版本号,不得用来判断媒体文件是否符合某个标准/规范;compatible_brands:文件兼容的brand列表。比如 mp41 的兼容 brand 为 isom。通过兼容列表里的 brand 规范,可以将文件 部分(或全部)解码出来
use crate::atoms::{BoxType, HEADER_SIZE}; pub struct FtypBox { pub major_brand: [u8; 4], pub minor_version: u32, pub compatible_brands: Vec<[u8; 4]>, } impl FtypBox { pub fn get_type(&self) -> BoxType { BoxType::FtypBox } pub fn get_size(&self) -> u64 { HEADER_SIZE + 8 + (4 * self.compatible_brands.len() as u64) } }