mvhd(Movie Header Box)

Created
Jan 22, 2022 09:14 AM
Tags
Box Type: ‘mvhd’ Container: Movie Box (‘moov’) Mandatory: Yes Quantity: Exactly one
MP4文件的整体信息,跟具体的视频流、音频流无关,比如创建时间、文件时长等。
use crate::atoms::{BoxType, HEADER_EXT_SIZE, HEADER_SIZE}; pub struct MvhdBox { pub version: u8, pub flags: u32, pub creation_time: u64, pub modification_time: u64, pub timescale: u32, pub duration: u64, pub rate: FixedPointU16, } impl MvhdBox { pub fn get_type(&self) -> BoxType { BoxType::MvhdBox } pub fn get_size(&self) -> u64 { let mut size = HEADER_SIZE + HEADER_EXT_SIZE; if self.version == 1 { size += 28; } else if self.version == 0 { size += 16; } size += 80; size } }
version is an integer that specifies the version of this box (0 or 1 in this specification) creation_time is an integer that declares the creation time of the presentation (in seconds since
midnight, Jan. 1, 1904, in UTC time)
modification_time is an integer that declares the most recent time the presentation was modified (in seconds since midnight, Jan. 1, 1904, in UTC time)
timescale is an integer that specifies the time-scale for the entire presentation; this is the number of time units that pass in one second. For example, a time coordinate system that measures time in sixtieths of a second has a time scale of 60.
duration is an integer that declares length of the presentation (in the indicated timescale). This
property is derived from the presentation’s tracks: the value of this field corresponds to the duration of the longest track in the presentation.
rate is a fixed point 16.16 number that indicates the preferred rate to play the presentation; 1.0
(0x00010000) is normal forward playback
volume is a fixed point 8.8 number that indicates the preferred playback volume. 1.0 (0x0100) is full volume.
matrix provides a transformation matrix for the video; (u,v,w) are restricted here to (0,0,1), hex values (0,0,0x40000000).
next_track_ID is a non-zero integer that indicates a value to use for the track ID of the next track to be added to this presentation. Zero is not a valid track ID value. The value of next_track_ID shall be larger than the largest track-ID in use. If this value is equal to or larger than all 1s (32-bit max int), and a new media track is to be added, then a search must be made in the file for a unused track identifier.
 
creation_time:文件创建时间;
modification_time:文件修改时间;
timescale:一秒包含的时间单位(整数)。举个例子,如果timescale等于1000,那么,一秒包含1000个时间单位(后面track等的时间,都要用这个来换算,比如track的duration为10,000,那么,track的实际时长为10,000/1000=10s;
duration:影片时长(整数),根据文件中的track的信息推导出来,等于时间最长的track duration;
rate:推荐的播放速率,32位整数,高16位、低16位分别代表整数部分、小数部分([16.16]),举例 0x0001 0000 代表1.0,正常播放速度;volume:播放音量,16位整数,高8位、低8位分别代表整数部分、小数部分([8.8]),举例 0x01 00 表示 1.0,即最大音量;
matrix:视频的转换矩阵,一般可以忽略不计;
next_track_ID:32位整数,非0,一般可以忽略不计。当要添加一个新的track到这个影片时,可以使用的track id,必须比当前已经使用的track id要大。也就是说,添加新的track时,需要遍历所有track,确认可用的track id;