WEB开发网
开发学院软件开发VC 基于DirectShow非线性编辑DES 阅读

基于DirectShow非线性编辑DES

 2006-07-23 11:33:03 来源:WEB开发网   
核心提示: 我提供了一个把两个.wmv文件进行编辑的源代码,有两个Track,基于DirectShow非线性编辑DES(4),为了简便,只是提供了视频的Transition,链接需要strmiids.lib库;void CDesTestDlg::OnStart(){// 创建空时间线.IAMTimel

我提供了一个把两个.wmv文件进行编辑的源代码,有两个Track,为了简便,只是提供了视频的Transition,音频的Transition也是同样的道理,只不过需要多建一个Audio Group。程序编译需要安装DX9 SDK。目前上载系统有问题,无法上传源代码,以后补上。以下只主要源代码。

链接需要strmiids.lib库;

void CDesTestDlg::OnStart()
{
  // 创建空时间线.
  IAMTimeline  *pTL = NULL;
  CoInitialize(NULL);
  CoCreateInstance(CLSID_AMTimeline, NULL, CLSCTX_INPROC_SERVER, IID_IAMTimeline, (void**)&pTL);
  // GROUP: Add a video group to the timeline.
  IAMTimelineGroup  *pGroup = NULL;
  IAMTimelineObj   *pGroupObj = NULL;
  pTL->CreateEmptyNode(&pGroupObj, TIMELINE_MAJOR_TYPE_GROUP);
  pGroupObj->QueryInterface(IID_IAMTimelineGroup, (void **)&pGroup);
  // Set the group media type. This example sets the type to "video" and
  // lets DES pick the default settings. For a more detailed example,
  // see "Setting the Group Media Type."
  AM_MEDIA_TYPE mtGroup; 
  ZeroMemory(&mtGroup, sizeof(AM_MEDIA_TYPE));
  mtGroup.majortype = MEDIATYPE_Video;
  pGroup->SetMediaType(&mtGroup);
  pTL->AddGroup(pGroupObj);
  pGroupObj->Release();
  // TRACK: Add two track to the group.
  IAMTimelineObj   *pTrackObj1,*pTrackObj2;
  IAMTimelineTrack  *pTrack1,*pTrack2;
  IAMTimelineComp   *pComp1 = NULL;//,*pComp2 = NULL;
  pTL->CreateEmptyNode(&pTrackObj1, TIMELINE_MAJOR_TYPE_TRACK);
  pGroup->QueryInterface(IID_IAMTimelineComp, (void **)&pComp1);
  pComp1->VTrackInsBefore(pTrackObj1, -1);
  pTrackObj1->QueryInterface(IID_IAMTimelineTrack, (void **)&pTrack1);
  pTL->CreateEmptyNode(&pTrackObj2, TIMELINE_MAJOR_TYPE_TRACK);
  pGroup->QueryInterface(IID_IAMTimelineComp, (void **)&pComp1);
  pComp1->VTrackInsBefore(pTrackObj2, -1);
  pTrackObj2->QueryInterface(IID_IAMTimelineTrack, (void **)&pTrack2);
  pTrackObj1->Release();
  pTrackObj2->Release();
  pComp1->Release(); 
  pGroup->Release();
  // SOURCE: Add two source to the track.
  IAMTimelineSrc *pSource1 = NULL,*pSource2 = NULL;
  IAMTimelineObj *pSourceObj1,*pSourceObj2;
  pTL->CreateEmptyNode(&pSourceObj1, TIMELINE_MAJOR_TYPE_SOURCE);
  pSourceObj1->QueryInterface(IID_IAMTimelineSrc, (void **)&pSource1);
  pTL->CreateEmptyNode(&pSourceObj2, TIMELINE_MAJOR_TYPE_SOURCE);
  pSourceObj2->QueryInterface(IID_IAMTimelineSrc, (void **)&pSource2);
  // Set the times and the file name.
  pSourceObj1->SetStartStop(0, 100000000);
  pSourceObj2->SetStartStop(50000000, 100000000);
  BSTR bstrFile1 = SysAllocString(OLESTR("news.WMV"));
  BSTR bstrFile2 = SysAllocString(OLESTR("vos.wmv"));
  pSource1->SetMediaName(bstrFile1);
  pSource2->SetMediaName(bstrFile2);
  SysFreeString(bstrFile1);
  SysFreeString(bstrFile2);
  //设置基于媒体本身的开始和结束时间
  pSource1->SetMediaTimes(00000000, 100000000);
  pSource2->SetMediaTimes(50000000, 100000000);
  pTrack1->SrcAdd(pSourceObj1);
  pTrack2->SrcAdd(pSourceObj2);
  pSourceObj1->Release();
  pSourceObj2->Release();
  pSource1->Release();
  pSource2->Release();
  pTrack1->Release();
  pTrack2->Release();
  
  // Create the transition object.
  IAMTimelineObj *pTransObj = NULL;
  HRESULT hr = pTL->CreateEmptyNode(&pTransObj, TIMELINE_MAJOR_TYPE_TRANSITION);
  
  // Set the subobject.
  hr = pTransObj->SetSubObjectGUID(CLSID_DxtJpeg); // SMPTE Wipe
  
  // Set the start and stop times.
  hr = pTransObj->SetStartStop(50000000, 100000000);
  
  // Insert the transition object into the timeline.
  IAMTimelineTransable *pTransable = NULL;
  hr = pTrack2->QueryInterface(IID_IAMTimelineTransable, (void **)&pTransable);
  hr = pTransable->TransAdd(pTransObj);
  
  IPropertySetter   *pProp;  // Property setter
  
  hr = CoCreateInstance(CLSID_PropertySetter, NULL, CLSCTX_INPROC_SERVER,
    IID_IPropertySetter, (void**) &pProp);
  
  // Error checking is omitted for clarity...
  
  DEXTER_PARAM param;
  DEXTER_VALUE *pValue = (DEXTER_VALUE*)CoTaskMemAlloc(sizeof(DEXTER_VALUE));
  
  // Initialize the parameter.
  param.Name = SysAllocString(L"MaskNum");
  param.dispID = 0;
  param.nValues = 1;
  
  
  // Initialize the value.
  pValue->v.vt = VT_BSTR;
  pValue->v.bstrVal =SysAllocString(L"129"); //六角星
  pValue->rt = 0;
  pValue->dwInterp = DEXTERF_JUMP;
  
  pProp->AddProp(param, pValue);
  
  // Free allocated resources.
  SysFreeString(param.Name);
  VariantClear(&(pValue->v));
  CoTaskMemFree(pValue);
  
  // Set the property on the transition.
  pTransObj->SetPropertySetter(pProp);
  pProp->Release();
  
  pTransable->Release();
  pTransObj->Release();
  
  // Preview the timeline.
  IRenderEngine *pRenderEngine = NULL;
  CoCreateInstance(CLSID_RenderEngine, NULL, CLSCTX_INPROC_SERVER,
    IID_IRenderEngine, (void**) &pRenderEngine);
  PreviewTL(pTL, pRenderEngine);
  
  // Clean up.
  pRenderEngine->ScrapIt();
  pRenderEngine->Release();
  pTL->Release();
  CoUninitialize();    
}
// 预览时间线.
void PreviewTL(IAMTimeline *pTL, IRenderEngine *pRender)
{
  IGraphBuilder  *pGraph = NULL;
  IMediaControl  *pControl = NULL;
  IMediaEvent   *pEvent = NULL;
  // Build the graph.
  pRender->SetTimelineObject(pTL);
  pRender->ConnectFrontEnd( );
  pRender->RenderOutputPins( );
  // Run the graph.
  pRender->GetFilterGraph(&pGraph);
  pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
  pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
  pControl->Run();
  long evCode;
  pEvent->WaitForCompletion(INFINITE, &evCode);
  pControl->Stop();
  // Clean up.
  pEvent->Release();
  pControl->Release();
  pGraph->Release();
}    
最后,希望认识一些对MPEG-4感兴趣的同仁,互相学习和交流。

上一页  1 2 3 4 

Tags:基于 DirectShow 非线性

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接