#include <stdio.h>
#include <stdlib.h>
extern "C"{
#include <libavcodec\avcodec.h>
#include <libavutil\avutil.h>
#include <libavformat\avformat.h>
}
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avutil.lib")
#pragma comment(lib,"avformat.lib")
int main(int argc, char* argv[])
{
// 设置日志的标准, 高于该标准的将不会被显示
av_log_set_level(AV_LOG_DEBUG);
// 注册所有的编解码器
av_register_all();
AVFormatContext* pCtx = NULL;
if (avformat_open_input(&pCtx, "D:/test.mp4", NULL, NULL) != 0)
{
av_log(NULL, AV_LOG_ERROR, "打开输入文件失败了!\n");
goto end;
}
if (avformat_find_stream_info(pCtx, NULL) < 0)
{
av_log(&pCtx, AV_LOG_ERROR, "查找失败了");
goto end;
}
for (int i = 0; i < pCtx->nb_streams; ++i)
{
printf("***********************************************\n");
av_dump_format(pCtx, 0, 0, 0);
}
printf("***********************************************\n");
/*int audioIndex = -1;
int videoIndex = -1;
for (int i = 0; i < pCtx->nb_streams; ++i)
{
if (pCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoIndex = i;
}
if (pCtx->streams[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO)
{
audioIndex = i;
}
} */
end:
system("pause");
return 0;
}
#include <stdlib.h>
extern "C"{
#include <libavcodec\avcodec.h>
#include <libavutil\avutil.h>
#include <libavformat\avformat.h>
}
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avutil.lib")
#pragma comment(lib,"avformat.lib")
int main(int argc, char* argv[])
{
// 设置日志的标准, 高于该标准的将不会被显示
av_log_set_level(AV_LOG_DEBUG);
// 注册所有的编解码器
av_register_all();
AVFormatContext* pCtx = NULL;
if (avformat_open_input(&pCtx, "D:/test.mp4", NULL, NULL) != 0)
{
av_log(NULL, AV_LOG_ERROR, "打开输入文件失败了!\n");
goto end;
}
if (avformat_find_stream_info(pCtx, NULL) < 0)
{
av_log(&pCtx, AV_LOG_ERROR, "查找失败了");
goto end;
}
for (int i = 0; i < pCtx->nb_streams; ++i)
{
printf("***********************************************\n");
av_dump_format(pCtx, 0, 0, 0);
}
printf("***********************************************\n");
/*int audioIndex = -1;
int videoIndex = -1;
for (int i = 0; i < pCtx->nb_streams; ++i)
{
if (pCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoIndex = i;
}
if (pCtx->streams[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO)
{
audioIndex = i;
}
} */
end:
system("pause");
return 0;
}