基于DirectShow非线性编辑DES
2006-07-23 11:33:03 来源:WEB开发网我提供了一个把两个.wmv文件进行编辑的源代码,有两个Track,为了简便,只是提供了视频的Transition,音频的Transition也是同样的道理,只不过需要多建一个Audio Group。程序编译需要安装DX9 SDK。目前上载系统有问题,无法上传源代码,以后补上。以下只主要源代码。
链接需要strmiids.lib库;
void CDesTestDlg::OnStart()
最后,希望认识一些对MPEG-4感兴趣的同仁,互相学习和交流。
{
// 创建空时间线.
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();
}
Tags:基于 DirectShow 非线性
编辑录入:爽爽 [复制链接] [打 印]- ››基于IP地址的vsftp服务器
- ››基于MySQL 水平分区的优化示例
- ››基于CentOS5的Linux下pptp和openvpn的搭建及配置
- ››基于JavaScript的网页版塔防游戏
- ››基于Android平台 QQ大战360手机游戏爆红
- ››基于Windows Azure的云计算应用设计
- ››基于AES算法实现对数据的加密
- ››基于SoPC目标板Flash编程设计的创建及应用
- ››基于SolidWarks齿轮机构的运动分析与仿真
- ››基于Windwos Server 2008故障转移群
- ››基于JavaScript的REST客户端框架
- ››基于JavaScript和CSS的Web图表框架横向对比
更多精彩
赞助商链接