獲得媒體檔案“位元速率”的一個方法!

來源:互聯網
上載者:User

http://blog.sina.com.cn/u/4841fc61010004bk

bitrate——“位元速率”是媒體檔案的一個屬性,通常一個媒體檔案會有幾個Stream——“流”,如音頻流、視頻流等,此處的“位元速率”是指音頻流和視頻流的位元速率的疊加。

  環境:VC 標頭檔:  #include "wmsdk.h"  在VC的“工具-〉選項(options)”中相應地設定安裝WMFSDK9的路徑: 如:C:/WMSDK/WMFSDK9/Include, C:/WMSDK/WMFSDK9/lib (利用windows media Format SDK 9 的相關函數) 更完整的設定,可以參照: http://lenux.blogchina.com/3936516.html (協助很大,呵呵,贊以下:)  HRESULT hr = CoInitialize(0);
 IWMSyncReader *m_pSynReader;
 IWMProfile *ppProfile;
 DWORD dwCount = 0;
 DWORD totalBitrate = 0; hr = WMCreateSyncReader(NULL,WMT_RIGHT_PLAYBACK,&m_pSynReader);
 hr = m_pSynReader->Open(L"C://2.WMV"); m_pSynReader->QueryInterface(IID_IWMProfile, (void **)&ppProfile);
 hr = ppProfile->GetStreamCount(&dwCount);
 if(SUCCEEDED(hr))
 {
    for(WORD w=0;w<=dwCount;w++)
    {
        IWMStreamConfig* pStrmConf = NULL;
        hr = ppProfile->GetStream(w,&pStrmConf);
        if(SUCCEEDED(hr))
        {
            GUID guidST;
            hr = pStrmConf->GetStreamType(&guidST);
            if(SUCCEEDED(hr))
            {
                if(guidST==WMMEDIATYPE_Video)
                {
                      DWORD videoBitrate;
                      hr = pStrmConf->GetBitrate(&videoBitrate);
                      totalBitrate = totalBitrate + videoBitrate;
                }
                if(guidST==WMMEDIATYPE_Audio)
                {
                      DWORD audioBitrate;
                      hr = pStrmConf->GetBitrate(&audioBitrate);
                      totalBitrate = totalBitrate + audioBitrate;
                }
            }
            pStrmConf->Release();
        }
     }
 } 幾個說明:1.hr = m_pSynReader->Open(L"C://2.WMV");  看一下WMFSDK9的文檔說明:  HRESULT Open(
      const WCHAR*  pwszFilename
  );   所以,如果不是在Unicode格式下編譯,需要先將ANSI轉換成Unicode,   例如:將CString str 轉換為  LPCWSTR pcwStr         CString str=_T("TestStr");
      USES_CONVERSION;
      LPWCSTR pwcStr = A2CW((LPCSTR)str);2.HRESULT hr = CoInitialize(0);  COM的使用,需要有CoInitialize過程,如果使用前已經初始化了,則可省去 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.