ラベル Window Media SDK の投稿を表示しています。 すべての投稿を表示
ラベル Window Media SDK の投稿を表示しています。 すべての投稿を表示

2013年6月26日水曜日

ストリーム数を調べる:IWMProfile::GetStreamCount

未整理


/*
空のCLRプロジェクト
*/

#include <stdio.h>  //printf とかで必要
#include <wmsdk.h>  //HRESULT とかで必要

#pragma comment(lib, "wmvcore.lib")   //IWMMetadataEditor とかで必要
#pragma comment ( lib, "ole32.lib" )//CoInitialize で必要

using namespace System;//Console::ReadLine()で必要

#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) \
 if(x != NULL)        \
{                    \
 x->Release();     \
 x = NULL;         \
}
#endif

int main(void)
{

 HRESULT hr = S_OK;

 IWMProfile * pProfile= NULL;; // 
 IWMSyncReader * mSyncReader;

 hr = WMCreateSyncReader(NULL, 0, &mSyncReader);
 // Create a profile manager object.
 // プロファイルマネージャオブジェクトを作成します。

 hr = mSyncReader->Open(L"G:\\sampleMovie\\sample.mp3");

 if (FAILED(hr))
 {
  printf("-------------失敗----------------");
  return E_FAIL;
 }

 hr = mSyncReader->QueryInterface(IID_IWMProfile,(void**)&pProfile);

 DWORD dwStreamCount = 0;
 hr = pProfile->GetStreamCount(&dwStreamCount);

 for (DWORD dwIndex = 0; dwIndex < dwStreamCount; dwIndex++)
 {
  printf("%d-------------\r\n",dwIndex);
  IWMStreamConfig *pConfig = NULL;
  hr = pProfile->GetStream(dwIndex, &pConfig);
  if (FAILED(hr))
  {
   printf("%d------失敗-------");
   printf("Could not get the stream: (hr=0x%08x)\n", hr);
   return hr;
  }

  GUID guid = GUID_NULL;
  hr = pConfig->GetStreamType(&guid);
  if (FAILED(hr))
  {
   printf("------失敗1-------");
   printf("Could not get the stream type: (hr=0x%08x)\n", hr);
   return hr;
  }
  else
  {
   if (WMMEDIATYPE_Video == guid) 
   {
    printf("WMMEDIATYPE_Video\r\n");
   }
   else if (WMMEDIATYPE_Audio == guid) 
   {
    printf("WMMEDIATYPE_Audioo\r\n");
   }
   else if (WMMEDIATYPE_Script == guid) 
   {
    printf("WMMEDIATYPE_Script\r\n");
   }
   else{
    printf("その他\r\n");
   }
  }
 }

 printf("-------------プログラム終了----------------");

 Console::ReadLine();//入力待-ウインドウ維持
}


システムプロファイルの言語を取得:IWMProfileManagerLanguage::GetUserLanguageID

To Load a System Profile

/*
空のCLRプロジェクト
*/

#include <stdio.h>  //printf とかで必要
#include <wmsdk.h>  //HRESULT とかで必要

#pragma comment(lib, "wmvcore.lib")   //IWMMetadataEditor とかで必要
#pragma comment ( lib, "ole32.lib" )//CoInitialize で必要

using namespace System;//Console::ReadLine()で必要

#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) \
 if(x != NULL)        \
{                    \
 x->Release();     \
 x = NULL;         \
}
#endif

int main(void)
{

 HRESULT hr = S_OK;

 IWMProfileManager*  pProfileMgr  = NULL;

 IWMProfileManagerLanguage* pProfileMgrLang = NULL;

 // Create a profile manager object.
 // プロファイルマネージャオブジェクトを作成します。
 hr = WMCreateProfileManager(&pProfileMgr);
 if(FAILED(hr))
 {
  printf("Could not create a profile manager object.");
  return 0;
 }

 // Get the profile manager language interface.
 // 言語インターフェイスプロファイルマネージャーの取得
 pProfileMgr->QueryInterface(IID_IWMProfileManagerLanguage, (void**)&pProfileMgrLang);

 if(FAILED(hr))
 {
  printf("Couldn't get IWMProfileManagerLanguage.\n");
  SAFE_RELEASE(pProfileMgrLang);
  return hr;
 }

 // Retrieve the current language (as a LANGID value)
 // 現在の言語を取得
 WORD wLangID = 0;
 hr = pProfileMgrLang->GetUserLanguageID(&wLangID);
 if(FAILED(hr))
 {
  printf("Could not get the current language.\n");
  SAFE_RELEASE(pProfileMgrLang);
  return hr;
 }

 printf("The current language ID is 0x%X\n", wLangID);//English – United States (0x0409)


 SAFE_RELEASE(pProfileMgrLang);

 printf("-------------プログラム終了----------------");

 Console::ReadLine();//入力待-ウインドウ維持
}


システムプロファイルの数を取得:IWMProfileManager::GetSystemProfileCount


/*
空のCLRプロジェクト
*/

#include <stdio.h>  //printf とかで必要
#include <wmsdk.h>  //HRESULT とかで必要

#pragma comment(lib, "wmvcore.lib")   //IWMMetadataEditor とかで必要
#pragma comment ( lib, "ole32.lib" )//CoInitialize で必要

using namespace System;//Console::ReadLine()で必要

#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) \
 if(x != NULL)        \
{                    \
 x->Release();     \
 x = NULL;         \
}
#endif

int main(void)
{

 HRESULT hr = S_OK;

 IWMProfileManager*  pProfileMgr  = NULL;
 IWMProfileManager2* pProfileMgr2 = NULL;

 WMT_VERSION         profileVersion;


 // Create a profile manager object.
 // プロファイルマネージャオブジェクトを作成します。
 hr = WMCreateProfileManager(&pProfileMgr);
 if(FAILED(hr))
 {
  printf("Could not create a profile manager object.");
  return 0;
 }

 // Get the IWMProfileManager2 interface.
 // IWMProfileManager2インタフェースを取得します。
 hr = pProfileMgr->QueryInterface(IID_IWMProfileManager2, 
  (void**) &pProfileMgr2);
 if(FAILED(hr))
 {
  printf("Could not get the IWMProfileManager2 interface.");
  SAFE_RELEASE(pProfileMgr);
  return 0;
 }

 // Release the old interface.
 // 古いインターフェースを解放します。
 SAFE_RELEASE(pProfileMgr);


 // Set the system profile version to 8.
 // システムプロファイルをバージョン8に設定
 profileVersion = WMT_VER_8_0;

 hr = pProfileMgr2->SetSystemProfileVersion(profileVersion);
 if(FAILED(hr))
 {
  printf("Could not change profile version.");
  printf("\nError code: 0x%X\n", hr);
  SAFE_RELEASE(pProfileMgr2);
  return 0;
 }

 //------------------------------------------------------------------------------
 DWORD profileCount = 0;
 DWORD length = 0;
// char szName[256];
// char szDesc[256];
 // システムプロファイルの数を取得
 hr = pProfileMgr2->GetSystemProfileCount(&profileCount);
 printf("*** Total Count: %d ***\n", profileCount);

 for (int i = 0; i < (int)profileCount; ++i)
 {
  printf(" --------- No: %d -----------------\r\n", i);
  IWMProfile * pProfile = NULL;
  hr = pProfileMgr2->LoadSystemProfile(i, &pProfile);
  if (FAILED(hr))
  {
   printf("%2d: Failed to Load System Profile!hr=0x%x\n", i, hr);
   return FALSE;
  }
  hr = pProfile->GetName(NULL, &length);
  WCHAR *wszName = new WCHAR[length + 1];
  hr = pProfile->GetName(wszName, &length);
  //WideCharToMultiByte(CP_ACP, 0, wszName, -1, szName,256, NULL, NULL);
  printf("neme:%S\r\n", wszName);

  // Profile 
  hr = pProfile->GetDescription(NULL, &length);
  WCHAR *wszDesc = new WCHAR[length + 1];
  hr = pProfile->GetDescription(wszDesc, &length);
  printf("Profile:%S\r\n", wszDesc);
  //WideCharToMultiByte(CP_ACP, 0, wszDesc, -1, szDesc, 256,NULL, NULL);

 }

 printf("-------------プログラム終了----------------");


 Console::ReadLine();//入力待-ウインドウ維持
}


システムプロファイルバージョンの変更:

To Change System Profile Versions
/*
空のCLRプロジェクト
*/

#include <stdio.h>  //printf とかで必要
#include <wmsdk.h>  //HRESULT とかで必要

#pragma comment(lib, "wmvcore.lib")   //IWMMetadataEditor とかで必要
#pragma comment ( lib, "ole32.lib" )//CoInitialize で必要

using namespace System;//Console::ReadLine()で必要

#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) \
 if(x != NULL)        \
{                    \
 x->Release();     \
 x = NULL;         \
}
#endif

int main(void)
{

 HRESULT hr = S_OK;

 IWMProfileManager*  pProfileMgr  = NULL;
 IWMProfileManager2* pProfileMgr2 = NULL;

 WMT_VERSION         profileVersion;

 // Initialize COM.
 //hr = CoInitialize(NULL);
 /*if(FAILED(hr))
 {
 printf("Could not initialize COM.");
 return 0;
 }*/

 // Create a profile manager object.
 // プロファイルマネージャオブジェクトを作成します。
 hr = WMCreateProfileManager(&pProfileMgr);
 if(FAILED(hr))
 {
  printf("Could not create a profile manager object.");
  return 0;
 }

 // Get the IWMProfileManager2 interface.
 // IWMProfileManager2インタフェースを取得します。
 hr = pProfileMgr->QueryInterface(IID_IWMProfileManager2, 
  (void**) &pProfileMgr2);
 if(FAILED(hr))
 {
  printf("Could not get the IWMProfileManager2 interface.");
  SAFE_RELEASE(pProfileMgr);
  return 0;
 }

 // Release the old interface.
 // 古いインターフェースを解放します。
 SAFE_RELEASE(pProfileMgr);

 // Get the current system profile version.
 // 現在のシステムプロファイルバージョンを取得
 hr = pProfileMgr2->GetSystemProfileVersion(&profileVersion);
 if(FAILED(hr))
 {
  printf("Could not retrieve profile version.");
  printf("\nError code: 0x%X\n", hr);
  SAFE_RELEASE(pProfileMgr2);
  return 0;
 }

 // Display the current version.
 // 現在のバージョンを表示します。
 printf("Current version: ");
 switch(profileVersion)
 {
 case WMT_VER_4_0:
  printf("WMT_VER_4_0\n");
  break;
 case WMT_VER_7_0:
  printf("WMT_VER_7_0\n");
  break;
 case WMT_VER_8_0:
  printf("WMT_VER_8_0\n");
  break;
 case WMT_VER_9_0:
  printf("WMT_VER_9_0\n");
  break;
 }

 // Set the system profile version to 8.
 // システムプロファイルをバージョン8に設定
 profileVersion = WMT_VER_8_0;

 hr = pProfileMgr2->SetSystemProfileVersion(profileVersion);
 if(FAILED(hr))
 {
  printf("Could not change profile version.");
  printf("\nError code: 0x%X\n", hr);
  SAFE_RELEASE(pProfileMgr2);
  return 0;
 }

 // Print verification.
 printf("Successfully set version to ");
 switch(profileVersion)
 {
 case WMT_VER_4_0:
  printf("WMT_VER_4_0\n");
  break;
 case WMT_VER_7_0:
  printf("WMT_VER_7_0\n");
  break;
 case WMT_VER_8_0:
  printf("WMT_VER_8_0\n");
  break;
 case WMT_VER_9_0:
  printf("WMT_VER_9_0\n");
  break;
 }

 printf("-------------プログラム終了----------------");
 Console::ReadLine();//入力待-ウインドウ維持
}


2013年6月24日月曜日

音楽ファイルの属性の長さを取得:IWMHeaderInfo::GetAttributeByName


#include <stdio.h>  //printf とかで必要
#include <wmsdk.h>  //HRESULT とかで必要

using namespace System;//Console::ReadLine()で必要

#pragma comment(lib, "wmvcore.lib")   //IWMMetadataEditor とかで必要

void main(){

 HRESULT hr          = S_OK;

 IWMMetadataEditor * pEditor = NULL;
 IWMHeaderInfo3 * pHeaderInfo = NULL;

 WORD stream = 0;
 WMT_ATTR_DATATYPE enumType;
 QWORD duration;
 WORD cbLength = sizeof( duration );

 hr = WMCreateEditor(&pEditor);
 hr = pEditor->Open(L"G:\\sampleMovie\\Amanda.wma");
 hr = pEditor->QueryInterface(IID_IWMHeaderInfo, (void**) &pHeaderInfo);

 hr = pHeaderInfo->GetAttributeByName( &stream, 
  g_wszWMDuration, &enumType,(BYTE *)&duration, &cbLength );

 printf("%d ミリ秒\r\n", (long) (duration / 10000) );

 Console::ReadLine();//入力待-ウインドウ維持

}



4分6秒は246秒

2013年6月22日土曜日

オーディオコーデックの数を取得:Window Media SDK


#include <stdio.h>//printf とかで必要
#include<windows.h>//MessageBox とかで必要

#include <wmsdk.h>
#pragma comment(lib, "wmvcore.lib")

void main(void)
{
 printf("コンソール表示開始\n");

 HRESULT GetCodecNames(IWMCodecInfo3* pCodecInfo);

 IWMCodecInfo3* pCodecInfo = NULL;
 IWMProfileManager* pProfileManager = NULL;
 HRESULT hr = S_FALSE;
 DWORD   cCodecs  = 0;

 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

 hr = WMCreateProfileManager(&pProfileManager);

 hr = pProfileManager->QueryInterface(IID_IWMCodecInfo3, (void**)(&pCodecInfo));\

 //システム上でサポートされているオーディオコーデックの数を取得します。
 hr = pCodecInfo->GetCodecInfoCount(WMMEDIATYPE_Audio, &cCodecs);

 if(SUCCEEDED(hr))
  printf("オーディオコーデックの数: %d\n\n", cCodecs);
 else
 {
  printf("オーディオコーデックの数を取得できませんでした。\n");
  return;
 }

 MessageBox(0,0,TEXT("OK"),0);
}

コーデックの数が正しいか調べてみたがよく分からない。

Windows Media Player のヘルプ-バージョン情報-テクニカルサポート情報
でコーデックを確認してみた。

コーデック名の取得
参考:http://msdn.microsoft.com/ja-jp/library/windows/desktop/dd743771(v=vs.85).aspx
#include <stdio.h>//printf とかで必要
#include<windows.h>//MessageBox とかで必要

#include <wmsdk.h>
#pragma comment(lib, "wmvcore.lib")

void main(void)
{
 printf("コンソール表示開始\n");

 HRESULT GetCodecNames(IWMCodecInfo3* pCodecInfo);

 IWMCodecInfo3* pCodecInfo = NULL;
 IWMProfileManager* pProfileManager = NULL;
 HRESULT hr = S_FALSE;
 DWORD   cCodecs  = 0;
 WCHAR*  pwszCodecName  = NULL;
 DWORD   cchCodecName     = 0;

 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

 hr = WMCreateProfileManager(&pProfileManager);

 hr = pProfileManager->QueryInterface(IID_IWMCodecInfo3, (void**)(&pCodecInfo));\

  //システム上でサポートされているオーディオコーデックの数を取得します。
  hr = pCodecInfo->GetCodecInfoCount(WMMEDIATYPE_Audio, &cCodecs);

 if(SUCCEEDED(hr))
  printf("オーディオコーデックの数: %d\n\n", cCodecs);
 else
 {
  printf("オーディオコーデックの数を取得できませんでした。\n");
  return;
 }

 /* ----------- オーディオコーデックの名前を取得 ----------- */
 //すべてのオーディオコーデックをループ。
 for(DWORD dwCodecIndex = 0; dwCodecIndex < cCodecs; dwCodecIndex++)
 {
  //まず、名前のサイズを取得する。
  hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Audio, dwCodecIndex, NULL, &cchCodecName);

  if(FAILED(hr))
  {
   printf("コーデック名のサイズを取得できませんでした。\n");
   return;
  }

  //適切なサイズの文字列を割り当てます。
  pwszCodecName = new WCHAR[cchCodecName];
  if(pwszCodecName == NULL)
  {
   printf("メモリを割り当てられませんでした\n");
   return;
  }

  // コーデック名を取得します。
  hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Audio,dwCodecIndex,pwszCodecName,&cchCodecName);
  if(FAILED(hr))
  {
   delete[] pwszCodecName;
   printf("コーデック名を取得できませんでした。\n");
   return;
  }

  // コーデック名を出力する。
  printf("%d %S\n", dwCodecIndex, pwszCodecName);

  // 次の繰り返しのためにクリーンアップします。
  delete[] pwszCodecName;
  pwszCodecName = NULL;
  cchCodecName  = 0;
 }

 MessageBox(0,0,TEXT("OK"),0);
}


よくわからないな・・・・・