ffmpeg 获取视频宽高

 1 int main(int argc, char *argv[])

 2 {

 3     const char* file_name = "video.mp4";

 4     int ret;

 5     unsigned int i;

 6 

 7     AVFormatContext *ifmt_ctx = NULL;

 8 

 9     av_register_all();

10     if ((ret = avformat_open_input(&ifmt_ctx, file_name, NULL, NULL)) < 0) {

11         printf("Cannot open input file\n");

12         return ret;

13     }

14 

15     if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) {

16         printf("Cannot find stream information\n");

17         return ret;

18     }

19 

20     for (i = 0; i < ifmt_ctx->nb_streams; i++) {

21         if (ifmt_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

22             printf("width:%d\n",ifmt_ctx->streams[i]->codec->width);

23             printf("height:%d\n",ifmt_ctx->streams[i]->codec->height);

24         }

25     }

26 

27     return 0;

28 }

 

或者用mediainfo

http://blog.csdn.net/leixiaohua1020/article/details/11902195

 1 int main()

 2 {

 3     MediaInfo MI;  

 4     CString width,height;  

 5     MI.Open("file.mp4");  

 6     width = MI.Get(stream_t::Stream_Video,0,"Width").c_str();  

 7     height = MI.Get(stream_t::Stream_Video,0,"Height").c_str();  

 8     printf("width: %s, height: %s\n", width, height);

 9     MI.Close();  

10 }

要是内存数据可以参考

http://blog.csdn.net/leixiaohua1020/article/details/12980423

即自己写好buffer的回调函数然后注册……

你可能感兴趣的:(ffmpeg)