MP4学习(七)ts-mp4源码阅读(5)mvhd box的解析

mvhd box的解析


常见的MP4结构图




mvhd box的定义


// mvhd box  
typedef struct {  
    u_char    size[4]; // 大小  
    u_char    name[4]; // 名字  
    u_char    version[1]; // box版本,0或1,一般为0  
    u_char    flags[3]; // 标识  
    u_char    creation_time[4]; // 创建时间(相对于UTC时间1904-01-01零点的秒数)  
    u_char    modification_time[4]; // 修改时间  
    u_char    timescale[4]; // 文件媒体在1秒时间内的刻度值,可以理解为1秒长度的时间单元数  
    u_char    duration[4]; // 该track的时间长度,用duration和time scale值可以计算track时长  
    u_char    rate[4]; // 推荐播放速率  
    u_char    volume[2]; // 与rate类似,表示音量  
    u_char    reserved[10]; // 保留位  
    u_char    matrix[36]; // 视频变换矩阵  
    u_char    preview_time[4]; // 下面四个成员表示pre-defined  
    u_char    preview_duration[4];  
    u_char    poster_time[4];  
    u_char    selection_time[4];  
    u_char    selection_duration[4];  
    u_char    current_time[4];  
    u_char    next_track_id[4]; // 下一个track使用的id号  
} mp4_mvhd_atom;  



mvhd box的解析


// 读取mvhd box
int
Mp4Meta::mp4_read_mvhd_atom(int64_t atom_header_size, int64_t atom_data_size)
{
    int64_t             atom_size;
    uint32_t            timescale;
    mp4_mvhd_atom       *mvhd;
    mp4_mvhd64_atom     mvhd64;

    if (sizeof(mp4_mvhd_atom) - 8 > (size_t)atom_data_size)
        return -1;

	// 读取mvhd box
    IOBufferReaderCopy(meta_reader, &mvhd64, sizeof(mp4_mvhd64_atom));
    mvhd = (mp4_mvhd_atom*)&mvhd64;

    if (mvhd->version[0] == 0) {
        timescale = mp4_get_32value(mvhd->timescale);

    } else {        // 64-bit duration
        timescale = mp4_get_32value(mvhd64.timescale);
    }

	// 读取timescale字段
    this->timescale = timescale;

    atom_size = atom_header_size + atom_data_size;

    mvhd_atom.buffer = TSIOBufferCreate();
    mvhd_atom.reader = TSIOBufferReaderAlloc(mvhd_atom.buffer);

    TSIOBufferCopy(mvhd_atom.buffer, meta_reader, atom_size, 0);
    mp4_meta_consume(atom_size);

    return 1;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值