函數說明
一般使用av_find_stream_info函數探測碼流格式,它的作用是爲pFormatContext->streams填充上正確的音視頻格式信息。可以通過av_dump_format函數將音視頻數據格式通過av_log輸出到指定的文件或者控制檯,方便開發者瞭解輸入的視音頻格式,對於程序的調用,刪除該函數的調用沒有任何的影響
函數參數
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
is_output等於0代表,打印輸入的視音頻文件格式信息
代碼
av_dump_format(pFormatContext, 0, "", 0);
通過av_log_set_callback設置日誌文件輸出,輸出的結果如下:
Input #0, h264, from '':
Duration: N/A, bitrate: N/A
Stream #0:0, 0, 1/1200000: Video: h264 (Baseline), yuvj420p, 1920x1080, 25 fps, 0.04 tbr, 1200k tbn
函數代碼
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
{
int i;
uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
if (ic->nb_streams && !printed)
return;
av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n",
is_output ? "Output" : "Input",
index,
is_output ? ic->oformat->name : ic->iformat->name,
is_output ? "to" : "from", url);
dump_metadata(NULL, ic->metadata, " ");
if (!is_output) {
av_log(NULL, AV_LOG_INFO, " Duration: ");
if (ic->duration != AV_NOPTS_VALUE) {
int hours, mins, secs, us;
int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
secs = duration / AV_TIME_BASE;
us = duration % AV_TIME_BASE;
mins = secs / 60;
secs %= 60;
hours = mins / 60;
mins %= 60;
av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
(100 * us) / AV_TIME_BASE);
} else {
av_log(NULL, AV_LOG_INFO, "N/A");
}
if (ic->start_time != AV_NOPTS_VALUE) {
int secs, us;
av_log(NULL, AV_LOG_INFO, ", start: ");
secs = llabs(ic->start_time / AV_TIME_BASE);
us = llabs(ic->start_time % AV_TIME_BASE);
av_log(NULL, AV_LOG_INFO, "%s%d.%06d",
ic->start_time >= 0 ? "" : "-",
secs,
(int) av_rescale(us, 1000000, AV_TIME_BASE));
}
av_log(NULL, AV_LOG_INFO, ", bitrate: ");
if (ic->bit_rate)
av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000);
else
av_log(NULL, AV_LOG_INFO, "N/A");
av_log(NULL, AV_LOG_INFO, "\n");
}
for (i = 0; i < ic->nb_chapters; i++) {
AVChapter *ch = ic->chapters[i];
av_log(NULL, AV_LOG_INFO, " Chapter #%d:%d: ", index, i);
av_log(NULL, AV_LOG_INFO,
"start %f, ", ch->start * av_q2d(ch->time_base));
av_log(NULL, AV_LOG_INFO,
"end %f\n", ch->end * av_q2d(ch->time_base));
dump_metadata(NULL, ch->metadata, " ");
}
if (ic->nb_programs) {
int j, k, total = 0;
for (j = 0; j < ic->nb_programs; j++) {
AVDictionaryEntry *name = av_dict_get(ic->programs[j]->metadata,
"name", NULL, 0);
av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id,
name ? name->value : "");
dump_metadata(NULL, ic->programs[j]->metadata, " ");
for (k = 0; k < ic->programs[j]->nb_stream_indexes; k++) {
dump_stream_format(ic, ic->programs[j]->stream_index[k],
index, is_output);
printed[ic->programs[j]->stream_index[k]] = 1;
}
total += ic->programs[j]->nb_stream_indexes;
}
if (total < ic->nb_streams)
av_log(NULL, AV_LOG_INFO, " No Program\n");
}
for (i = 0; i < ic->nb_streams; i++)
if (!printed[i])
dump_stream_format(ic, i, index, is_output);
av_free(printed);
}
FFmpeg av_dump_format函數使用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.