#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
extern "C" {
#include <avcodec.h>
#include <avformat.h>
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
//g++ avf.cpp -I/usr/include/libavcodec -I/usr/include/libavformat -lavformat -lavcodec -L/usr/lib/libavformat.so -L/usr/lib/libavcodec.so -o avf
using namespace std;
int main(int argc, char *argv[])
{
av_log_set_level(0);
av_register_all();
AVFormatContext *pFormatCtx;
const char *filename=argv[1];
// Open video file
if(av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0)
{
cout < < "can't open file" << endl;
exit(-1);
}
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
{
cout << "can't get stream info" << endl; exit(-1); } //dump_format(pFormatCtx, 0, filename, false); int i, videoStream; AVCodecContext *pCodecCtx; //http://ffmpeg.org/doxygen/0.6/structAVCodecContext.html AVCodecContext *pCodecCtx2; pCodecCtx=pFormatCtx->streams[0]->codec;
pCodecCtx2=pFormatCtx->streams[1]->codec;
AVCodec* vCodec;//http://ffmpeg.org/doxygen/0.6/structAVCodec.html
AVCodec* aCodec;
vCodec=avcodec_find_decoder(pCodecCtx->codec_id);
aCodec=avcodec_find_decoder(pCodecCtx2->codec_id);
cout < < "Video codec : " << vCodec->name < < endl;
cout << "Width : " << pCodecCtx->width < < endl;
cout << "Height : " << pCodecCtx->height < < endl;
cout << "Duration : " << pFormatCtx->duration < < endl;
//cout << "codec id : " << (int)pCodecCtx2 << endl;
cout << "Audio codec : " << aCodec->name < < endl;
cout << "Audio channels : " << pCodecCtx2->channels < < endl;
cout << "Audio samplerate : " << pCodecCtx2->sample_rate < < endl;
cout << "Audio bitrate : " << pCodecCtx2->bit_rate < < endl;
avcodec_close(pCodecCtx);
avcodec_close(pCodecCtx2);
av_close_input_file(pFormatCtx);
return 0;
}