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的回調函數然后注冊……


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM