bool UBWindowsMediaFile::close()
{
    bool result = true;

    if (mWMWriter)
    {
        if (FAILED(mWMWriter->EndWriting()))
        {
            result = false;
        }
    }

    if (mPushSink)
    {
        mPushSink->Disconnect();
        mPushSink->EndSession();
        mPushSink->Release();
    }

    if(mChapters.length() > 0)
    {
        IWMMetadataEditor *editor = 0;
        IWMHeaderInfo     *headerInfo = 0;

        WMCreateEditor(&editor);
        editor->Open((LPCTSTR) mVideoFileName.utf16());
        editor->QueryInterface(IID_IWMHeaderInfo, (void**)&headerInfo);

        foreach(MarkerInfo mi, mChapters)
        {
            headerInfo->AddMarker((LPWSTR)mi.label.utf16(),  msToSampleTime(mi.timestamp));
        }
void CVideoInstance::StartCruncher(CVideoInstance* aInstance)
{
    aInstance->myThreadIsDone = false;
    ::CoInitialize(nullptr);
    HRESULT hr;
    hr = WMCreateSyncReader(NULL, 0, &aInstance->mySyncReader);
    if (hr != S_OK)
    {
        INFO_PRINT("%s", "Error: Could not create WMCreateSyncReader, video can not be played!");
        return;
    }
    //Step 2: Open the file
    //note: When the synchronous reader opens the file, it assigns an output number to each stream

    hr = aInstance->mySyncReader->Open(aInstance->myFileName);
    if (hr != S_OK)
    {
        INFO_PRINT("%s%ls", "Error: Could not open file, video can not be played! ", aInstance->myFileName);
        return;
    }


    aInstance->mySyncReader->GetOutputCount(&aInstance->mytheOutputsCount);

    int videoIndex = 0;
    DWORD theSize;
    IWMOutputMediaProps* videoOutputProps = nullptr;
    for (unsigned int i = 0; i<aInstance->mytheOutputsCount; i++)
    {
        SAFE_ARRAYDELETE(aInstance->mytheMediaType);
        aInstance->mySyncReader->GetOutputProps(i, &videoOutputProps);
        hr = videoOutputProps->GetMediaType(NULL, &theSize);
        aInstance->mytheMediaType = (WM_MEDIA_TYPE*) new BYTE[theSize];
        hr = videoOutputProps->GetMediaType(aInstance->mytheMediaType, &theSize);

        if (FAILED(hr))
        {
            INFO_PRINT("%s%s", "Error: Could not query for the space needed for media type, video can not be played!", aInstance->myFileName);
            return;
            //_tcscpy( tszErrMsg, _T( "Could not query for the space needed for media type" ) );
            //break;
        }

        if (WMMEDIATYPE_Video == aInstance->mytheMediaType->majortype)//pMediaType->majortype )
        {
            videoIndex = i;
            aInstance->mySyncReader->GetStreamNumberForOutput(videoIndex, (WORD*)&aInstance->myVideoStreamNumber);

            if (aInstance->mytheMediaType->formattype == WMFORMAT_VideoInfo)
            {
                //setting the bitmapInfoHeader by reading the WmvInfoHeader
                memcpy(&aInstance->myTheVideoInfoHeader, aInstance->mytheMediaType->pbFormat, sizeof(WMVIDEOINFOHEADER));
                aInstance->myBitmapInfoHdr = aInstance->myTheVideoInfoHeader.bmiHeader;

                aInstance->myWidth = aInstance->myBitmapInfoHdr.biWidth;
                aInstance->myHeight = aInstance->myBitmapInfoHdr.biHeight;

                WORD bitCount = aInstance->myBitmapInfoHdr.biBitCount;
                aInstance->myBytes_per_pixel = bitCount / 8;


                unsigned int rowSize = (bitCount * aInstance->myBitmapInfoHdr.biWidth + 7) / 8; // +7 to round up
                if (rowSize % 4)
                    rowSize += (4 - (rowSize % 4)); // Pad to DWORD Boundary

                aInstance->myRow_increment = rowSize;// theInfoHeader.biWidth * bytes_per_pixel_;

            }


        }
        if (WMMEDIATYPE_Audio == aInstance->mytheMediaType->majortype)
        {
            aInstance->myAudioOutputNumber = i;
            aInstance->mySyncReader->GetStreamNumberForOutput(aInstance->myAudioOutputNumber, (WORD*)&aInstance->m_iAudioStreamNumber);
        }

    }
    //relesae the memory
    SAFE_RELEASE(videoOutputProps);
    videoOutputProps = nullptr;
    SAFE_ARRAYDELETE(aInstance->mytheMediaType);

    BYTE* pValue = new BYTE[5];
    strcpy((char*)pValue, "TRUE");
    hr = aInstance->mySyncReader->SetOutputSetting(videoIndex, g_wszVideoSampleDurations, WMT_TYPE_BOOL, pValue, sizeof(pValue));
    delete[]pValue;
    if (FAILED(hr))
    {
        INFO_PRINT("%s%s", "Error: Could not set Video Ouptut Sample durations, video can not be played!", aInstance->myFileName);
        return;
        //AfxMessageBox("could not set Video Ouptut Sample durations");
    }


    hr = aInstance->mySyncReader->SetReadStreamSamples(aInstance->myVideoStreamNumber, FALSE);
    if (FAILED(hr))
    {
        INFO_PRINT("%s%s", "Error: Could not set Video Stream to give Uncompressed Samples, video can not be played!", aInstance->myFileName);
        return;
        //AfxMessageBox("could not set Video Stream to give Uncompressed Samples");
    }

    IWMMetadataEditor *pEditor;

    hr = WMCreateEditor(&pEditor);
    if (hr == S_OK)
    {
        pEditor->Open(aInstance->myFileName);
        IWMHeaderInfo3* pHdrInfo;
        pHdrInfo = NULL;
        hr = pEditor->QueryInterface(IID_IWMHeaderInfo3, (void**)&pHdrInfo);
        WORD wStream = 0;
        WMT_ATTR_DATATYPE dType;
        QWORD dwDuration;
        WORD wSize = 0;
        hr = pHdrInfo->GetAttributeByName(&wStream, L"Duration", &dType, (BYTE*)NULL, &wSize);

        BYTE* pValue = nullptr;
        if (wSize > 0)
        {
            pValue = new BYTE[wSize];
            hr = pHdrInfo->GetAttributeByName(&wStream, L"Duration", &dType, pValue, &wSize);
            dwDuration = *((QWORD*)pValue);
            aInstance->m_qwTotalTimeInSeconds = (dwDuration * 100) / 1000000000;
            SAFE_ARRAYDELETE(pValue);
            SAFE_RELEASE(pHdrInfo);
            SAFE_RELEASE(pEditor);
        }

    }
    aInstance->myOpenSuccesfully = true;
    StartUpdateLoop(aInstance);
}
Beispiel #3
0
int tagwrite(const string fname,  struct fennec_audiotag *wtag)
{	

	HRESULT               hres;
	IWMHeaderInfo*        wminfo;
	WORD                  wmistream = 0;
	BOOL                  sdef = 1;
	IWMMetadataEditor    *pEdit = 0;
	IWMHeaderInfo        *pInfo = 0;
	int                   twrote = 1;

	if(!wtag)return 0;

	CoInitialize(0);

	hres = WMCreateEditor(&pEdit);
	hres = pEdit->Open(fname);

	pEdit->QueryInterface(IID_IWMHeaderInfo, (VOID **)(&wminfo));


	if(wtag->tag_title.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTitle          ,wtag->tag_title.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTitle          , 0); }

	if(wtag->tag_album.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAlbumTitle     ,wtag->tag_album.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAlbumTitle     , 0); }

	if(wtag->tag_artist.tsize        ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthor         ,wtag->tag_artist.tdata        ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthor         , 0); }
	
	if(wtag->tag_origartist.tsize    ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMOriginalArtist ,wtag->tag_origartist.tdata    ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMOriginalArtist , 0); }
	
	if(wtag->tag_composer.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMComposer       ,wtag->tag_composer.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMComposer       , 0); }
	
	if(wtag->tag_lyricist.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMLyrics         ,wtag->tag_lyricist.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMWriter         , 0); }
 
	/* band: not used */
	
	if(wtag->tag_copyright.tsize     ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMCopyright      ,wtag->tag_copyright.tdata     ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMCopyright      , 0); }
	
	if(wtag->tag_publish.tsize       ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMPublisher      ,wtag->tag_publish.tdata       ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMPublisher      , 0); }
	
	if(wtag->tag_encodedby.tsize     ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMEncodedBy      ,wtag->tag_encodedby.tdata     ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMEncodedBy      , 0); }
	
	if(wtag->tag_genre.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMGenre          ,wtag->tag_genre.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMGenre          , 0); }
	
	if(wtag->tag_year.tsize          ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMYear           ,wtag->tag_year.tdata          ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMYear           , 0); }
	
	if(wtag->tag_url.tsize           ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMUserWebURL     ,wtag->tag_url.tdata           ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMUserWebURL     , 0); }
	
	if(wtag->tag_offiartisturl.tsize ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthorURL      ,wtag->tag_offiartisturl.tdata ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMAuthorURL      , 0); }
	
	if(wtag->tag_comments.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMDescription    ,wtag->tag_comments.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMDescription    , 0); }
	
	if(wtag->tag_lyric.tsize         ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMLyrics         ,wtag->tag_lyric.tdata         ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMLyrics         , 0); }

	if(wtag->tag_bpm.tsize           ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMBeatsPerMinute ,wtag->tag_bpm.tdata           ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMBeatsPerMinute , 0); }

	if(wtag->tag_tracknum.tsize      ){ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTrack          ,wtag->tag_tracknum.tdata      ); }
	else{ twrote = WM_SetTagString(wminfo, &wmistream, g_wszWMTrack          , 0); }

	if(!twrote)
	{
		MessageBox(0, uni("Couldn't set tag(s), if you're setting tags on currently playing media, try stopping it."), uni("Error on tagging"), MB_ICONQUESTION);
	}

	pEdit->Flush();
	pEdit->Close();
	wminfo->Release();
	pEdit->Release();

	return 1;
}
Beispiel #4
0
HRESULT GetMediaMetadata(const TCHAR *szFileName,const TCHAR *szAttribute,BYTE **pszOutput)
{
    typedef HRESULT (WINAPI *WMCREATEEDITOR_PROC)(IWMMetadataEditor **);
    WMCREATEEDITOR_PROC pWMCreateEditor = NULL;
    HMODULE hWMVCore;
    IWMMetadataEditor *pEditor = NULL;
    IWMHeaderInfo *pWMHeaderInfo = NULL;
    HRESULT hr = E_FAIL;

    hWMVCore = LoadLibrary(_T("wmvcore.dll"));

    if(hWMVCore != NULL)
    {
        pWMCreateEditor = (WMCREATEEDITOR_PROC)GetProcAddress(hWMVCore,"WMCreateEditor");

        if(pWMCreateEditor != NULL)
        {
            hr = pWMCreateEditor(&pEditor);

            if(SUCCEEDED(hr))
            {
                hr = pEditor->Open(szFileName);

                if(SUCCEEDED(hr))
                {
                    hr = pEditor->QueryInterface(IID_PPV_ARGS(&pWMHeaderInfo));

                    if(SUCCEEDED(hr))
                    {
                        WORD wStreamNum;
                        WMT_ATTR_DATATYPE Type;
                        WORD cbLength;

                        /* Any stream. Should be zero for MP3 files. */
                        wStreamNum = 0;

                        hr = pWMHeaderInfo->GetAttributeByName(&wStreamNum,szAttribute,&Type,NULL,&cbLength);

                        if(SUCCEEDED(hr))
                        {
                            *pszOutput = (BYTE *)malloc(cbLength);

                            if(*pszOutput != NULL)
                            {
                                hr = pWMHeaderInfo->GetAttributeByName(&wStreamNum,szAttribute,&Type,
                                                                       *pszOutput,&cbLength);
                            }
                        }

                        pWMHeaderInfo->Release();
                    }
                }

                pEditor->Release();
            }
        }

        FreeLibrary(hWMVCore);
    }

    return hr;
}