Click here to Skip to main content
15,919,479 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CWinThread use Pin
bob1697219-Apr-07 3:36
bob1697219-Apr-07 3:36 
GeneralRe: CWinThread use Pin
CDRAIN19-Apr-07 4:32
CDRAIN19-Apr-07 4:32 
GeneralRe: CWinThread use Pin
bob1697219-Apr-07 6:33
bob1697219-Apr-07 6:33 
QuestionHow to Change top menu font ? Pin
Atul2319-Apr-07 0:57
Atul2319-Apr-07 0:57 
AnswerRe: How to Change top menu font ? Pin
Hamid_RT19-Apr-07 1:13
Hamid_RT19-Apr-07 1:13 
Questionfile encoding problem Pin
amitmistry_petlad 19-Apr-07 0:28
amitmistry_petlad 19-Apr-07 0:28 
AnswerRe: file encoding problem Pin
Paresh Chitte19-Apr-07 2:14
Paresh Chitte19-Apr-07 2:14 
GeneralRe: file encoding problem Pin
amitmistry_petlad 19-Apr-07 2:45
amitmistry_petlad 19-Apr-07 2:45 
Encoding from any format to wmv/wma by encoder sdk by c++

please check the link

http://www.codeproject.com/Purgatory/ConvertVideoFileFormats.asp[^]

this in c# while i am in vc++



pEncoder->PrepareToEncode-failed most time


HRESULT Encoder :: convertintowma_wmv(WCHAR *source,WCHAR * destionation,WCHAR * w_encoderprofile,BOOL b_MultiPass,UINT top ,UINT bottom ,UINT left,UINT right,HACCEL hAccelTable)
 {

	HRESULT hr;
    IWMEncoder* pEncoder;
    IWMEncSourceGroupCollection* pSrcGrpColl=NULL;
    IWMEncSourceGroup* pSrcGrp=NULL;
    IWMEncSource* pSrc=NULL;
    IWMEncSource* pSrcAud=NULL;
    IWMEncVideoSource* pSrcVid=NULL;
    IWMEncProfileCollection* pProColl=NULL;
    IWMEncProfile* pPro=NULL;
    IWMEncFile* pFile=NULL;
    IWMEncAttributes* pAttr=NULL;
    IWMEncDisplayInfo* pDispInfo=NULL;
    CComBSTR bstrName = NULL;
	CComVariant varIndex;
	CCallBack EventSink; 
	WMENC_ENCODER_STATE enumCurState;
    WMENC_ENCODER_STATE enumPrvState;
	short iAudCount, iVidCount;
    long lCount=0;
    int i=0;
	
//	enumCurState=0;
//	enumPrvState=0;
    
	// Initialize the COM library and retrieve a pointer to an IWMEncoder interface.
    hr = CoInitialize(NULL);
    if ( SUCCEEDED( hr ) )
    {
        hr = CoCreateInstance(CLSID_WMEncoder,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IWMEncoder,
            (void**) &pEncoder);
    }else
	{
		MessageBox(0,L"FAIL CREATE instance",L"FAIL CREATE instance",0); 
	}

    // Retrieve the source group collection.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
		
    }else
	{
		MessageBox(0,L"pEncoder->get_SourceGroupCollection Fail",L"get_SourceGroupCollection",0); 
	}

    // Add a source group to the collection.
    if ( SUCCEEDED( hr ) )
    {
        hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
    }
	else
	{
		MessageBox(0,L"pSrcGrpColl->Add",L"pSrcGrpColl->Add",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pSrcGrp->AddSource(WMENC_AUDIO, &pSrcAud);
    }else
	{
		MessageBox(0,L"pSrcGrp->AddSource",L"pSrcGrp->AddSource",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrc);
    }else
	{
		MessageBox(0,L"pSrcGrp->AddSource(WMENC_VIDEO",L"pSrcGrp->AddSource(WMENC_VIDEO",0); 
	}

    // Retrieve an IWMEncVideoSource pointer.
    if ( SUCCEEDED( hr ) )
    {
        hr = pSrc->QueryInterface(IID_IWMEncVideoSource, (void**)&pSrcVid);
    }else
	{
		MessageBox(0,L"pSrc->QueryInterface",L"pSrc->QueryInterface",0); 
	}

    // Add a video and audio source to the source group.
    if ( SUCCEEDED( hr ) )
    {
        hr = pSrcAud->SetInput(source);
    }else
	{
		MessageBox(0,L"pSrcAud->SetInput",L"pSrcAud->SetInput",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pSrcVid->SetInput(source);
    }else
	{
		MessageBox(0,L"pSrcVid->SetInput(source);",L"pSrcVid->SetInput(source);",0); 
	}

    // Specify the cropping margins.
 //   /*if ( SUCCEEDED( hr ) )
 //   {
 //       hr = pSrcVid->put_CroppingBottomMargin(0);
 //   }else
	//{
	//	MessageBox(0,L"pSrcVid->put_CroppingBottomMargin",L"source group ",0); 
	//}

 //   if ( SUCCEEDED( hr ) )
 //   {
 //       hr = pSrcVid->put_CroppingTopMargin(0);
 //   }else
	//{
	//	MessageBox(0,L"source group",L"source group ",0); 
	//}


 //   if ( SUCCEEDED( hr ) )
 //   {
 //       hr = pSrcVid->put_CroppingLeftMargin(0);
 //   }else
	//{
	//	MessageBox(0,L"source group",L"source group ",0); 
	//}

 //   if ( SUCCEEDED( hr ) )
 //   {
 //       hr = pSrcVid->put_CroppingRightMargin(0);
 //   }else
	//{
	//	MessageBox(0,L"source group",L"source group ",0); 
	//}*/



    // Fill in the description object members.

    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->get_DisplayInfo(&pDispInfo);
    }else
	{
		MessageBox(0,L"pEncoder->get_DisplayInfo",L"pEncoder->get_DisplayInfo",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pDispInfo->put_Author(CComBSTR("Author Name"));
    }else
	{
		MessageBox(0,L"pDispInfo->put_Author",L"pDispInfo->put_Author",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pDispInfo->put_Copyright(CComBSTR("Copyright"));
    }else
	{
		MessageBox(0,L"pDispInfo->put_Copyright",L"pDispInfo->put_Copyright",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pDispInfo->put_Description(CComBSTR("A description"));
    }else
	{
		MessageBox(0,L"pDispInfo->put_Description",L"pDispInfo->put_Description",0); 
	}


    if ( SUCCEEDED( hr ) )
    {
        hr = pDispInfo->put_Rating(CComBSTR("Rating"));
    }else
	{
		MessageBox(0,L"pDispInfo->put_Rating",L"pDispInfo->put_Rating",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pDispInfo->put_Title(CComBSTR("The Title"));
    }else
	{
		MessageBox(0,L"pDispInfo->put_Title",L"pDispInfo->put_Title",0); 
	}



    // Add an attribute to the collection.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->get_Attributes(&pAttr);
    }else
	{
		MessageBox(0,L"source group",L"source group ",0); 
	}


    if ( SUCCEEDED( hr ) )
    {
        hr =  pAttr->Add(CComBSTR("URL"), CComVariant("IP Address"));
    }else
	{
		MessageBox(0,L"pAttr->Add",L"pAttr->Add",0); 
	}


    // Specify a file object in which to save encoded content.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->get_File(&pFile);
    }else
	{
		MessageBox(0,L"pEncoder->get_File",L"pEncoder->get_File",0); 
	}

    if ( SUCCEEDED( hr ) )
    {
        hr = pFile->put_LocalFileName(destionation);
    }else
	{
		MessageBox(0,L"pFile->put_LocalFileName",L"pFile->put_LocalFileName",0); 
	}



    // Choose a profile from the collection.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->get_ProfileCollection(&pProColl);
    }else
	{
		MessageBox(0,L"pEncoder->get_ProfileCollection",L"pEncoder->get_ProfileCollection",0); 
	}


    if ( SUCCEEDED( hr ) ) 
    {
        hr = pProColl->get_Count(&lCount);
    }else
	{
		MessageBox(0,L"pProColl->get_Count",L"pProColl->get_Count",0); 
	}


    for (i=0; i<lCount; i++)
    {
        if ( SUCCEEDED( hr ) )
        {
            hr = pProColl->Item(i, &pPro);
        }
        if ( SUCCEEDED( hr ) )
        {
            hr = pPro->get_Name(&bstrName);
        }
        if (_wcsicmp(bstrName,w_encoderprofile/*CComBSTR("Windows Media Video 8 for Local Area Network (384 Kbps)")*/)==0)
        {
            // Set the profile in the source group.			
            if ( SUCCEEDED( hr ) )
            {
                hr = pSrcGrp->put_Profile(CComVariant(pPro));
            }else
			{
				MessageBox(0,L"pSrcGrp->put_Profile(CComVariant(pPro)",L"source group ",0); 
			}
            break;
        }
    }


	if ( SUCCEEDED( hr ) )
	{
		hr = pEncoder->PrepareToEncode(VARIANT_FALSE);
	}else
	{
		MessageBox(0,L"pEncoder->PrepareToEncode",L"pEncoder->PrepareToEncode",0); 
	}

    // Start the encoding process.
    <code>if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
    }else
	{
		MessageBox(0,L"PrepareToEncode fail",L"PrepareToEncode fail",0); 
	}</code>    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->Start();
        
		// Keep the console window open.
        // printf("When encoding stops, press a key to close the console window.");		
        // Stop the encoding process.

        if ( SUCCEEDED( hr ) )
        {
            // Wait for a key press.
            
			/*while(!kbhit())
               _asm nop;
			*/
			
			//MSG stMsg ={0} ;	
			//while (!GetMessage(&msg, NULL, 0, 0))
			//{
			//	if (!TranslateAccelerator(
			//		msg.hwnd,hAccelTable, &msg))
			//	{
			//		//Put your PreTranslateMessage stuff here
			//		TranslateMessage(&msg);
			//		DispatchMessage(&msg);
			//	}
			//}	

			
	// Wait until the encoding process
    // stops before exiting the application.

		bool glbboolStartNext=false;
		bool b_forfirsttime=false;
		MSG msg;
		while(!glbboolStartNext)
		{
			// In order for the events to be triggered correctly,
        // the windows message queue needs to be processed.

        while(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

		if(b_forfirsttime)
		{
        enumPrvState = enumCurState;		
		}
		b_forfirsttime=true;
        enumCurState = EventSink.State();
        if( EventSink.SrcState() == WMENC_SOURCE_STOP )
            enumCurState = WMENC_ENCODER_STOPPED;

       // if( enumCurState != enumPrvState )
        {
            switch ( enumCurState )
            {
            case WMENC_ENCODER_STARTING:
                // TODO: Handle encoder starting state.
                break;

            case WMENC_ENCODER_RUNNING:
                // TODO: Handle encoder running state.
                break;

            case WMENC_ENCODER_PAUSING:
                // TODO: Handle encoder pausing state.
                break;

            case WMENC_ENCODER_PAUSED:
                // TODO: Handle encoder paused state.
                break;

            case WMENC_ENCODER_STOPPING:
                // TODO: Handle encoder stopping state.
                break;

            case WMENC_ENCODER_STOPPED:
                // TODO: Handle encoder stopped state.
				glbboolStartNext=true;
                goto EXIT;

            case WMENC_ENCODER_END_PREPROCESS:
                // TODO: Handle encoder end preprocess state.
                break;
            }
        }
    }

	
	EXIT:     
	  hr = pEncoder->Stop();	
	  hr = EventSink.Shutdown( pEncoder );		
			
        }
    }	

	//hr= pSrcGrpColl->Remove(VARIANT_FALSE);
	varIndex.vt = VT_I2;

	if ( SUCCEEDED( hr ) )
	{
		hr = pSrcGrpColl->get_Count(&lCount);
	}

	for (i=0; i<lCount; i++)
	{
	varIndex.iVal = i;		
    hr = pSrcGrpColl->Remove(varIndex);
	}
	

	//if ( SUCCEEDED( hr ) )
	{
    hr = pSrcGrp->get_SourceCount(WMENC_AUDIO, &iAudCount);
	}

   //if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->get_SourceCount(WMENC_VIDEO, &iVidCount);
}

// Remove the video stream.
// You must verify that the count is not zero before deleting
// the source stream.

//CComVariant varIndex;

varIndex.vt = VT_I2;
varIndex.iVal = 0;
if (iVidCount != 0)
{
    //if ( SUCCEEDED( hr ) )
    {
        hr = pSrcGrp->RemoveSource(WMENC_VIDEO, varIndex);
    }
}


if(iAudCount!=0)
  {
        hr = pSrcGrp->RemoveSource(WMENC_AUDIO, varIndex);
   }

	//if ( SUCCEEDED( hr ) )
	{
		hr = pEncoder->PrepareToEncode(VARIANT_FALSE);
	}

    // Release pointers.
    if ( pSrcGrpColl )
    {
        pSrcGrpColl->Release();
        pSrcGrpColl = NULL;
    }
    if ( pSrcGrp )
    {
        pSrcGrp->Release();
        pSrcGrp = NULL;
    }
    if ( pProColl )
    {
        pProColl->Release();
        pProColl = NULL;
    }
    if ( pPro )
    {
        pPro->Release();
        pPro = NULL;
    }
    if ( pFile )
    {
        pFile->Release();
        pFile = NULL;
    }
    if ( pSrcAud )
    {
        pSrcAud->Release();
        pSrcAud = NULL;
    }
    if ( pSrcVid )
    {
        pSrcVid->Release();
        pSrcVid = NULL;
    }
    if ( pSrc )
    {
        pSrc->Release();
        pSrc = NULL;
    }
    if ( pAttr )
    {
        pAttr->Release();
        pAttr = NULL;
    }
    if ( pDispInfo )
    {
        pDispInfo->Release();
        pDispInfo = NULL;
    }
    if ( pEncoder )
    {
        pEncoder->Release();
        pEncoder = NULL;
    }

	CoUninitialize();

	return(hr);
 }


"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India

GeneralRe: file encoding problem Pin
Mark Salsbery19-Apr-07 9:33
Mark Salsbery19-Apr-07 9:33 
GeneralRe: file encoding problem Pin
amitmistry_petlad 22-Apr-07 20:31
amitmistry_petlad 22-Apr-07 20:31 
GeneralRe: file encoding problem Pin
Mark Salsbery23-Apr-07 5:12
Mark Salsbery23-Apr-07 5:12 
GeneralRe: file encoding problem Pin
amitmistry_petlad 23-Apr-07 17:30
amitmistry_petlad 23-Apr-07 17:30 
QuestionVC++/MFC Pin
SumitMandal19-Apr-07 0:10
SumitMandal19-Apr-07 0:10 
QuestionRe: VC++/MFC Pin
toxcct19-Apr-07 0:19
toxcct19-Apr-07 0:19 
QuestionVC++/MFC Pin
SumitMandal19-Apr-07 0:08
SumitMandal19-Apr-07 0:08 
AnswerRe: VC++/MFC Pin
Hamid_RT19-Apr-07 1:14
Hamid_RT19-Apr-07 1:14 
AnswerRe: VC++/MFC Pin
Hamid_RT19-Apr-07 1:21
Hamid_RT19-Apr-07 1:21 
QuestionScale control Pin
kasturi_haribabu18-Apr-07 23:48
kasturi_haribabu18-Apr-07 23:48 
QuestionBinary file format? Pin
$uresh $hanmugam18-Apr-07 23:13
$uresh $hanmugam18-Apr-07 23:13 
AnswerRe: Binary file format? Pin
toxcct18-Apr-07 23:14
toxcct18-Apr-07 23:14 
GeneralRe: Binary file format? Pin
$uresh $hanmugam19-Apr-07 1:45
$uresh $hanmugam19-Apr-07 1:45 
QuestionINI file Pin
josip cagalj18-Apr-07 23:03
josip cagalj18-Apr-07 23:03 
AnswerRe: INI file Pin
toxcct18-Apr-07 23:13
toxcct18-Apr-07 23:13 
GeneralRe: INI file Pin
josip cagalj18-Apr-07 23:21
josip cagalj18-Apr-07 23:21 
GeneralRe: INI file Pin
toxcct18-Apr-07 23:27
toxcct18-Apr-07 23:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.