Showing posts with label Windows Media Format SDK. Show all posts
Showing posts with label Windows Media Format SDK. Show all posts

May 20, 2009

Windows Media ASF Viewer

Windows Media® ASF Viewer 9 Series is a tool for inspecting the contents of files (such as .asf. .wma, and .wmv file) to make sure they meet the requirements of the Advanced Systems Format (ASF) specification. -- Microsoft


Brief Introduction
This tool is very helpful for analyzing the contents of ASF files, it helps us to know the media structure and content easily. I was trying to encode WMV using Windows Media Format SDK, and this tool really helped me to verify the output content.

Download from Microsoft

May 14, 2009

How To: Extracting the embedded album art from a MP3 / WMA

I'm using Windows Media Sync Reader in Windows Media Format SDK to get the album art from id3 tag of a MP3, it can also get from a WMA.

Code Snippet:

#include <windows.h>
#include <wmsdk.h>
#include <atlbase.h>

#pragma comment(lib, "wmvcore.lib")

bool ExtractEmbeddedAlbumArt(LPCWSTR wszAudioFile)
{
  bool bOK = false;

  WM_PICTURE* pPicture = NULL;;

  do {

    CComPtr<IWMSyncReader> pIWMSyncReader;
    if(FAILED(WMCreateSyncReader(NULL, 0, &pIWMSyncReader))) break;

    if(FAILED(pIWMSyncReader->Open(wszAudioFile))) break;

    CComPtr<IWMHeaderInfo3> pIWMHeaderInfo3;
    if(FAILED(pIWMSyncReader->QueryInterface(&pIWMHeaderInfo3))) break;

    WMT_ATTR_DATATYPE wmtDataType = WMT_TYPE_BINARY;
    WORD wStreamNum = 0;
    WORD wLength = 0;
    if(FAILED(pIWMHeaderInfo3->GetAttributeByName(
      &wStreamNum, g_wszWMPicture, &wmtDataType, NULL, &wLength))) break;

    pPicture = (WM_PICTURE*)new BYTE[wLength];

    if(FAILED(pIWMHeaderInfo3->GetAttributeByName(
      &wStreamNum, g_wszWMPicture, &wmtDataType, (BYTE*)pPicture, &wLength))) break;

    bOK = true;

  } while(false);

  if(pPicture)
  {
    //
    // TODO: Save the picture or do something with it
    //

    delete [] (BYTE*)pPicture;
    pPicture = NULL;
  }

  return bOK;
}

February 23, 2008

Sample code for IWMMediaProps::GetMediaType()

// Get the required buffer size
DWORD cbType = 0;
pWMMediaProps->GetMediaType(NULL, &cbType);

// Get media type
WM_MEDIA_TYPE* pType = (WM_MEDIA_TYPE*)new BYTE[cbType];
if(SUCCEEDED(pWMMediaProps->GetMediaType(pType, &cbType)))
{
  // Use media type here
  // ...
}

// Free buffer
// Should not use "delete [] pType", we have to cast it to (BYTE*) before delete it.
delete [] (BYTE*)pType;