동영상을 저장할 때

2008. 11. 21. 14:35
동영상을 저장할 때 
//////////////////////////////////////////////////////////////////
    HRESULT hr = S_OK;
    hr = pRenderEngine.CoCreateInstance(CLSID_RenderEngine);
    IGraphBuilder   *pGraph = NULL;
    ICaptureGraphBuilder2 *pBuilder = NULL;
    IMediaControl   *pControl = NULL;
    IMediaEvent     *pEvent = NULL;

    // Build the graph.
    hr = pRenderEngine->SetTimelineObject(pMainTL);
    hr = pRenderEngine->ConnectFrontEnd( );
    hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, 
        IID_ICaptureGraphBuilder2, (void **)&pBuilder);

    // Get a pointer to the graph front end.
    hr = pRenderEngine->GetFilterGraph(&pGraph);
    hr = pBuilder->SetFiltergraph(pGraph);

    // Create the file-writing section.
    WCHAR wstring[1024];
    ZeroMemory(wstring, sizeof(wstring));
    mbstowcs(wstring, (LPCTSTR)createFileName, createFileName.GetLength());

    IBaseFilter *pMux;
    hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, wstring, &pMux, NULL);
    long NumGroups;
    hr = pMainTL->GetGroupCount(&NumGroups);



    // Loop through the groups and get the output pins.
    for (int i = 0; i < NumGroups; i++)
    {
        IPin *pPin;
        if (pRenderEngine->GetGroupOutputPin(i, &pPin) == S_OK) 
        {
            hr = pBuilder->RenderStream(NULL, NULL, pPin, NULL, pMux);
            pPin->Release();
        }
    }

    // Run the graph.
    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
    hr = pControl->Run();

    long evCode;
    hr = pEvent->WaitForCompletion(INFINITE, &evCode);
    hr = pControl->Stop();

    // Clean up.
    if (pMux)
    {
        pMux->Release();
    }

    pEvent->Release();
    pControl->Release();
    pGraph->Release();
    pBuilder->Release();
Posted by 바람도리
:

statics

2008. 11. 21. 14:22
<< 다음은, 제가 Timeline에 Group, Composition, Track, Source를 추가하기 위해서, 만들어놓은 static 함수입니다. 읽어보시고 도움이 되시는 분이 있으면 좋겠습니다.>>

//---------------------------------------------------------------------------------------------------------------------
//----- Static Function -----------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------

HRESULT CTimelineMgr::CreateTimelineGroup(IAMTimeline* pTimeline, IAMTimelineObj** ppGroupObj, IAMTimelineGroup** ppGroup)
{
        HRESULT hResult = S_OK;

        if (pTimeline == NULL) return E_INVALIDARG;
        if (ppGroup == NULL) return E_POINTER;

        hResult = pTimeline->CreateEmptyNode(&(*ppGroupObj), TIMELINE_MAJOR_TYPE_GROUP);
        if (SUCCEEDED(hResult))
        {
                hResult = (*ppGroupObj)->QueryInterface(IID_IAMTimelineGroup, (void**)ppGroup);
        }

        return hResult;
}

HRESULT CTimelineMgr::CreateTimelineComposition(IAMTimeline* pTimeline, IAMTimelineGroup* pGroup, IAMTimelineComp** ppComposition)
{
        HRESULT hResult = S_OK;

        if (pTimeline == NULL) return E_INVALIDARG;
        if (pGroup == NULL) return E_INVALIDARG;
        if (ppComposition == NULL) return E_POINTER;

        CComPtr<IAMTimelineObj>        pComposition;

        hResult = pTimeline->CreateEmptyNode(&pComposition, TIMELINE_MAJOR_TYPE_COMPOSITE);
        if (SUCCEEDED(hResult))
        {
                CComQIPtr<IAMTimelineComp>        pGroupComp(pGroup);
                hResult = pGroupComp->VTrackInsBefore(pComposition, -1);
                if (SUCCEEDED(hResult))
                {
                        hResult = pComposition->QueryInterface(IID_IAMTimelineComp, (void**)ppComposition);
                }
        }

        return hResult;
}

HRESULT CTimelineMgr::CreateTimelineTrack(IAMTimeline* pTimeline, IAMTimelineComp* pComposition, IAMTimelineTrack** ppTrack)
{
        HRESULT hResult = S_OK;

        if (pTimeline == NULL) return E_INVALIDARG;
        if (pComposition == NULL) return E_INVALIDARG;
        if (ppTrack == NULL) return E_POINTER;

        CComPtr<IAMTimelineObj>        pTrack;

        hResult = pTimeline->CreateEmptyNode(&pTrack, TIMELINE_MAJOR_TYPE_TRACK);
        if (SUCCEEDED(hResult))
        {
                hResult = pComposition->VTrackInsBefore(pTrack, -1);
                if (SUCCEEDED(hResult))
                {
                        hResult = pTrack->QueryInterface(IID_IAMTimelineTrack, (void**)ppTrack);
                }
        }

        return hResult;
}

HRESULT CTimelineMgr::CreateTimelineSource(IAMTimeline* pTimeline, IAMTimelineTrack* pTrack, IAMTimelineObj** ppSource, REFERENCE_TIME rtClipStart, REFERENCE_TIME rtClipStop, int nStretchMode)
{
        HRESULT hResult = S_OK;

        if (pTimeline == NULL) return E_INVALIDARG;
        if (pTrack == NULL) return E_INVALIDARG;
        if (ppSource == NULL) return E_POINTER;

        hResult = pTimeline->CreateEmptyNode(ppSource, TIMELINE_MAJOR_TYPE_SOURCE);
        if (SUCCEEDED(hResult))
        {
                (*ppSource)->SetStartStop(rtClipStart, rtClipStop);
                CComQIPtr<IAMTimelineSrc> pSource(*ppSource);
                if (pSource == NULL) return E_FAIL;

                hResult = pSource->SetStretchMode(nStretchMode);
                if (SUCCEEDED(hResult))
                {
                        hResult = pTrack->SrcAdd(*ppSource);
                }
        }

        return hResult;
}

Posted by 바람도리
:

des

2008. 11. 19. 19:22
jotacu...@gmail.com  
프로필 보기
 추가 옵션 11월19일, 오전6시07분
On 18 nov, 09:56, Rangaswamy <Rangasw...@discussions.microsoft.com> 
wrote: 
> Dear sir, 
> I am working on the Directshow Editing Services I have added the video clip 
> to a time line and I can save it as a  asf file but by default its resolution 
> is 320*240 but i need to change it to a higher resolution like 1024*768 . 
> Thanking you. 
> yours sincerely, 
> Rangaswamy 

Try this: (no error check for clarity) 
HRESULT hr; 
//Add a Video Group to the time line 
IAMTimelineGroup *pGroup=NULL; 
IAMTimelineObj *pGroupObj=NULL; 
hr=pTL->CreateEmptyNode(&pGroupObj,TIMELINE_MAJOR_TYPE_GROUP); 
hr=pGroupObj->QueryInterface(IID_IAMTimelineGroup,(void**)&pGroup); 
//set the media type to Video. 
AM_MEDIA_TYPE mtGroup; 
ZeroMemory(&mtGroup, sizeof(AM_MEDIA_TYPE)); 
mtGroup.majortype=MEDIATYPE_Video; 
mtGroup.subtype=MEDIASUBTYPE_RGB24;//Deppends on the media sub type 
you decide 
// 
mtGroup.pbFormat=(BYTE*)CoTaskMemAlloc(sizeof(VIDEOINFOHEADER)); 
if(mtGroup.pbFormat==NULL) 
   return E_OUTOFMEMORY; 

VIDEOINFOHEADER *pVideoInfoHeader=(VIDEOINFOHEADER*)mtGroup.pbFormat; 
ZeroMemory(pVideoInfoHeader,sizeof(VIDEOINFOHEADER)); 
pVideoInfoHeader->bmiHeader.biBitCount=24;//for RGB 24 
pVideoInfoHeader->bmiHeader.biWidth=1024;//The resolution you want 
pVideoInfoHeader->bmiHeader.biHeight=768;//Same as before 
pVideoInfoHeader->bmiHeader.biPlanes=1; 
pVideoInfoHeader->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 
pVideoInfoHeader->bmiHeader.biSizeImage=DIBSIZE(pVideoInfoHeader- 
>bmiHeader); 

//set the format´s type and size 
mtGroup.formattype=FORMAT_VideoInfo; 
mtGroup.cbFormat=sizeof(VIDEOINFOHEADER); 
//Set the sample size 
mtGroup.bFixedSizeSamples=TRUE; 
mtGroup.lSampleSize=DIBSIZE(pVideoInfoHeader->bmiHeader); 
hr=pGroup->SetMediaType(&mtGroup); 
//Release 
CoTaskMemFree(mtGroup.pbFormat); 
hr=pTL->AddGroup(pGroupObj); 
pGroupObj->Release(); 
//From here you would have to add a track, a clip...whatever. 
Hope it helps... 
Posted by 바람도리
:

BLOG main image
by 바람도리

공지사항

카테고리

분류 전체보기 (38)
Video Coding (0)
폰트 (1)
DX9 (1)
OpenGL (0)
Lua (0)
회사자료 (13)
스크랩 (7)
장비 (1)
des (3)
서버 (1)
ati (1)

최근에 올라온 글

최근에 달린 댓글

태그목록

글 보관함

달력

«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Total :
Today : Yesterday :