码迷,mamicode.com
首页 > 其他好文 > 详细

FFmpeg mov_read_ftyp函数剖析

时间:2017-12-28 17:13:12      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:mov_read_ftyp

函数说明

    读取文件格式,最小版本以及兼容格式,然后存储到metadata,metadata作为AVFormatContext成员变量,可以通过t = av_dict_get(pAVFormatContext->metadata, "major_brand", NULL, AV_DICT_IGNORE_SUFFIX);
查看文件格式

/* read major brand, minor version and compatible brands and store them as metadata */
static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
    uint32_t minor_ver;
    int comp_brand_size;
    char* comp_brands_str;
    uint8_t type[5] = {0};
    int ret = ffio_read_size(pb, type, 4);
    if (ret < 0)
        return ret;

    if (strcmp(type, "qt  "))
        c->isom = 1;
    av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
    //fc结构体是AVFormatContext
    av_dict_set(&c->fc->metadata, "major_brand", type, 0);
    minor_ver = avio_rb32(pb); /* minor version */
    av_dict_set_int(&c->fc->metadata, "minor_version", minor_ver, 0);

    comp_brand_size = atom.size - 8;
    if (comp_brand_size < 0)
        return AVERROR_INVALIDDATA;
    comp_brands_str = av_malloc(comp_brand_size + 1); /* Add null terminator */
    if (!comp_brands_str)
        return AVERROR(ENOMEM);

    ret = ffio_read_size(pb, comp_brands_str, comp_brand_size);
    if (ret < 0) {
        av_freep(&comp_brands_str);
        return ret;
    }
    comp_brands_str[comp_brand_size] = 0;
    av_dict_set(&c->fc->metadata, "compatible_brands", comp_brands_str, 0);
    av_freep(&comp_brands_str);

    return 0;
}
                    Brand                  Extension          Mime type
MP4             mp41,mp42       .mp4                  video/mp4,audio/mp4,application/mp4
QuickTim    qt                        .mov                    video/quicktime

参考
http://www.ftyps.com

FFmpeg mov_read_ftyp函数剖析

标签:mov_read_ftyp

原文地址:http://blog.51cto.com/fengyuzaitu/2055570

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!