解码一直用的 FFmpeg,最近想在解码之前读取帧数,发现FFmpeg只能采用遍历的方式获得帧数。
网上查了一下,MediaInfo 貌似是一款不错的库。
下载 MediaInfo 库文件,解压得到 MediaInfoDLL.h 头文件和 MediaInfo.dll
文件。
开始编译出现错误,换了一个别人用的 MediaInfo.dll ,正常运行,不明所以。估计是 dll 编译生成的问题吧。
控制台下 SDK 开发,C++语言,有例程:
#include "MediaInfoDLL.h" #include <iostream> #include <iomanip> #include <string> using namespace MediaInfoDLL; int main ( ) { //Information about MediaInfo MediaInfo MI; String To_Display=MI.Option(__T("Info_Version"), __T("0.7.61.0;MediaInfoDLL_Example_MSVC;0.7.61.0")).c_str(); To_Display += __T("\r\n\r\nInfo_Parameters\r\n"); To_Display += MI.Option(__T("Info_Parameters")).c_str(); To_Display += __T("\r\n\r\nInfo_Codecs\r\n"); To_Display += MI.Option(__T("Info_Codecs")).c_str(); //An example of how to use the library To_Display += __T("\r\n\r\nOpen\r\n"); MI.Open(__T("d:\\picture\\video.avi")); //MI.Open(__T("Example.ogg")); To_Display += __T("\r\n\r\nInform with Complete=false\r\n"); MI.Option(__T("Complete")); To_Display += MI.Inform().c_str(); To_Display += __T("\r\n\r\nInform with Complete=true\r\n"); MI.Option(__T("Complete"), __T("1")); To_Display += MI.Inform().c_str(); To_Display += __T("\r\n\r\nCustom Inform\r\n"); MI.Option(__T("Inform"), __T("General;Example : FileSize=%FileSize%")); To_Display += MI.Inform().c_str(); To_Display += __T("\r\n\r\nGet with Stream=General and Parameter=\"FileSize\"\r\n"); To_Display += MI.Get(Stream_General, 0, __T("FileSize"), Info_Text, Info_Name).c_str(); To_Display += __T("\r\n\r\nGetI with Stream=General and Parameter=46\r\n"); To_Display += MI.Get(Stream_General, 0, 46, Info_Text).c_str(); To_Display += __T("\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n"); toStringStream SS; SS << std::setbase(10) << MI.Count_Get(Stream_Audio); To_Display += SS.str(); To_Display += __T("\r\n\r\nGet with Stream=General and Parameter=\"AudioCount\"\r\n"); To_Display += MI.Get(Stream_General, 0, __T("AudioCount"), Info_Text, Info_Name).c_str(); To_Display += __T("\r\n\r\nGet with Stream=Audio and Parameter=\"StreamCount\"\r\n"); To_Display += MI.Get(Stream_Audio, 0, __T("StreamCount"), Info_Text, Info_Name).c_str(); To_Display += __T("\r\n\r\nClose\r\n"); MI.Close(); std::wcout << To_Display; return 0; }
运行结果如图:
上面获取的视频的完整信息,绝大部分情况下不需要活得这么详尽的信息,只关心自己想要的信息,在MFC下试了一下。
void CMediaInfo1Dlg::OnBnClickedRead() { // TODO: 在此添加控件通知处理程序代码 MediaInfo MI; CString width,height,count,rate,duration; MI.Open("D:\\picture\\video.avi"); width = MI.Get(stream_t::Stream_Video,0,"Width").c_str(); height = MI.Get(stream_t::Stream_Video,0,"Height").c_str(); count = MI.Get(stream_t::Stream_Video,0,"FrameCount").c_str(); rate = MI.Get(stream_t::Stream_Video,0,"FrameRate").c_str(); duration = MI.Get(stream_t::Stream_Video,0,"Duration").c_str(); MI.Close(); AfxMessageBox(width+height+count+rate+duration); }
依次为宽,高,帧数,帧频,时长。
时间: 2024-10-10 17:13:49