#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "avcodec.lib")
#define CERR(err) if (err) \
int main(int argc, char* argv[])
const char* url = "v1080.mp4";
AVFormatContext* ic = nullptr;
int re = avformat_open_input(&ic, url,
avformat_find_stream_info(ic, NULL);
av_dump_format(ic,1, url,
for (int i = 0; i < ic->nb_streams; i++)
if (ic->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
cout << "========音频=======" << endl;
cout << "sample_rate:" << as->codecpar->sample_rate << endl;
else if (ic->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
cout << "========视频=======" << endl;
cout << "width:" << vs->codecpar->width << endl;
cout << "height:" << vs->codecpar->height << endl;
auto video_codec_id = vs->codecpar->codec_id;
AVCodecParameters* video_par = vs->codecpar;
AVCodecContext* decode_c = XCodec::Create(video_codec_id, false);
avcodec_parameters_to_context(decode_c, video_par);
cout << "decode.Open() error" << endl;
AVFrame* frame = decode.CreateFrame();
XVideoView* view = XVideoView::Create();
view->Init(video_par->width, video_par->height, (XVideoView::Format)video_par->format);
re = av_read_frame(ic, &pkt);
if (vs && pkt.stream_index == vs->index)
while (decode.Recv(frame))
cout << frame->pts << " " << flush;
else if (as && pkt.stream_index == as->index)
avformat_close_input(&ic);
