打开文件,主要是探测协议类型,如果是网络文件则创建网络链接
avformat_open_input(&ifmt_ctx, in_filename, NULL, NULL);
获取流信息
avformat_find_stream_info(ifmt_ctx, NULL);
打印媒体信息
av_dump_format(ifmt_ctx, 0, in_filename, 0);
遍历查找视频/音频流索引
for (uint32_t i = 0; i < ifmt_ctx->nb_streams; i++)
fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO
AVPacket *pkt = av_packet_alloc();
读取数据包
while (1)
{
av_read_frame(ifmt_ctx, pkt);
if (pkt->stream_index == audioindex)
...
if (pkt->stream_index == videoindex)
...
av_packet_unref(pkt);
}
av_packet_free(&pkt);
avformat_close_input(&ifmt_ctx);