AVFormatContext 结构体中有一个属性是metadata,咱们在读取一个多媒体文件的时候,能够经过AVDictionaryEntry访问这个属性的数据。html
AVFormatContext *fmt_ctx = NULL; AVDictionaryEntry *tag = NULL; av_register_all(); if ((ret = avformat_open_input(&fmt_ctx, "path_to_file.mp3", NULL, NULL))){ printf("Fail to open file"); } //读取metadata中全部的tag while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))){ printf("Tag:%s , Value: %s", tag->key, tag->value); }
AvFormatContext
AVDictionaryEntry
读取metadata的官方示例spa
// read the format headers if (fmt_ctx->iformat->read_header(fmt_ctx) < 0) { printf("No header format"); return; } for (int i = 0; i < fmt_ctx->nb_streams; i++){ if (fmt_ctx->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) { AVPacket pkt = fmt_ctx->streams[i]->attached_pic; //使用QImage读取完整图片数据(注意,图片数据是为解析的文件数据,须要用QImage::fromdata来解析读取) QImage img = QImage::fromData((uchar*)pkt.data, pkt.size); imageWidget->setPixmap(QPixmap::fromImage(img)); break; } }
我给深度文件管理器添加的音乐文件预览播放的支持效果(Linux deepin):code