需要获取视频文件中音频流的信息,比如语言什么的,后来发现,这些信息都包含在AVDictionary这个结构体里。
下面列出获取方法
AVFormatContext *pFormatCtx = avformat_alloc_context();
for (int i = 0; i < pFormatCtx->nb_streams; i++) {
if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
videoStream = i;
} else if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {//有可能有多路音轨
LOGE("audioStream = %d", i);
AVDictionaryEntry *t = NULL;
while ((t = av_dict_get(pFormatCtx->streams[i]->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
LOGE("%s: %s", t->key, t->value);
}
audioStream = i;
}
}
结果
nb_streams = 3
audioStream = 1
language: eng
BPS: 127999
BPS-eng: 127999
DURATION: 01:59:03.147000000
DURATION-eng: 01:59:03.147000000
NUMBER_OF_FRAMES: 334835
NUMBER_OF_FRAMES-eng: 334835
NUMBER_OF_BYTES: 114289728
NUMBER_OF_BYTES-eng: 114289728
_STATISTICS_WRITING_APP: mkvmerge v9.4.2 ('So High') 32bit
_STATISTICS_WRITING_APP-eng: mkvmerge v9.4.2 ('So High') 32bit
_STATISTICS_WRITING_DATE_UTC: 2018-03-17 00:41:28
_STATISTICS_WRITING_DATE_UTC-eng: 2018-03-17 00:41:28
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
audioStream = 2
language: chi
BPS: 128003
BPS-eng: 128003
DURATION: 01:59:03.125000000
DURATION-eng: 01:59:03.125000000
NUMBER_OF_FRAMES: 334834
NUMBER_OF_FRAMES-eng: 334834
NUMBER_OF_BYTES: 114292834
NUMBER_OF_BYTES-eng: 114292834
_STATISTICS_WRITING_APP: mkvmerge v9.4.2 ('So High') 32bit
_STATISTICS_WRITING_APP-eng: mkvmerge v9.4.2 ('So High') 32bit
_STATISTICS_WRITING_DATE_UTC: 2018-03-17 00:41:28
_STATISTICS_WRITING_DATE_UTC-eng: 2018-03-17 00:41:28
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
单独获取单个信息的方法
AVDictionaryEntry *t = NULL;
t = av_dict_get(d, "language", NULL, AV_DICT_IGNORE_SUFFIX);
LOGE("language: %s", t->value);
t = av_dict_get(d, "DURATION", NULL, AV_DICT_IGNORE_SUFFIX);
LOGE("DURATION: %d", (int) (*t->value));
语言缩写遵循的是ISO_639-2或者ISO_639-1标准,目前遇到的都是ISO_639-2标准
可以查看这里 https://baike.baidu.com/item/ISO_639-2/9935792?fr=aladdin