Discussion:
DES, Sound lost while Editing AVI
(too old to reply)
davidb
2006-05-09 13:49:57 UTC
Permalink
Hi,
i wrote a app to trim AVIs. Works very Well but the sound is missing.
Do i have to extract the sound from the avi and add it extra to the
timeline ? Is there a more easy way, or is it typical possible to edit
sound within the avi video ?
best regards, David

here's my Code (mostly like in the doku):


void trimVideo(const char* srcFilename, const char* dstFilename,double
startTime, double stopTime){
// check if dest file exist to avoid overwriting;
if(FileExist(dstFilename)){
remove(dstFilename);
}
// Start by making an empty timeline.

WCHAR *srcName;
AnsiToWide(srcFilename,strlen(srcFilename)+1,&srcName);

WCHAR *dstName;
AnsiToWide(dstFilename,strlen(dstFilename)+1,&dstName);

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 a track to the group.

IAMTimelineObj *pTrackObj;
IAMTimelineTrack *pTrack;
IAMTimelineComp *pComp = NULL;

pTL->CreateEmptyNode(&pTrackObj, TIMELINE_MAJOR_TYPE_TRACK);
pGroup->QueryInterface(IID_IAMTimelineComp, (void **)&pComp);
pComp->VTrackInsBefore(pTrackObj, 0);
pTrackObj->QueryInterface(IID_IAMTimelineTrack, (void **)&pTrack);

pTrackObj->Release();
pComp->Release();

// SOURCE: Add a source to the track.

IAMTimelineSrc *pSource = NULL;
IAMTimelineObj *pSourceObj;
pTL->CreateEmptyNode(&pSourceObj, TIMELINE_MAJOR_TYPE_SOURCE);
pSourceObj->QueryInterface(IID_IAMTimelineSrc, (void **)&pSource);

// Set the times and the file name.

REFERENCE_TIME staTm = startTime;
REFERENCE_TIME stoTm = stopTime;
pSourceObj->SetStartStop(0, (stoTm-staTm)); // Length of new Video
BSTR bstrFile = SysAllocString(srcName);
pSource->SetMediaName(bstrFile);
SysFreeString(bstrFile);
pSource->SetMediaTimes(staTm, stoTm); // Clip in SRC Video
pTrack->SrcAdd(pSourceObj);

pGroup->SetRecompFormatFromSource(pSource);

pSourceObj->Release();
pSource->Release();
pTrack->Release();
pGroup->Release();
// Preview the timeline.
IRenderEngine *pRenderEngine = NULL;
CoCreateInstance(CLSID_RenderEngine, NULL, CLSCTX_INPROC_SERVER,
IID_IRenderEngine, (void**) &pRenderEngine);
PreviewTL(pTL, pRenderEngine,dstName);

// Clean up.
pRenderEngine->ScrapIt();
pRenderEngine->Release();
pTL->Release();
CoUninitialize();
}


void PreviewTL(IAMTimeline *pTL, IRenderEngine *pRender,WCHAR *dstName)

{
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;

ICaptureGraphBuilder2* pCaptureGraphBuilder = NULL;
IBaseFilter* pMux = NULL;
IFileSinkFilter* pWrite = NULL;

// Build the graph.
pRender->SetTimelineObject(pTL);
pRender->ConnectFrontEnd( );
//pRender->RenderOutputPins( );

// Run the graph.
pRender->GetFilterGraph(&pGraph);

//--------------------------------------------
// Create the file-writing section.
//--------------------------------------------

CoCreateInstance(CLSID_CaptureGraphBuilder2,NULL,
CLSCTX_INPROC_SERVER,
IID_ICaptureGraphBuilder2,
(void**)&pCaptureGraphBuilder);

pCaptureGraphBuilder->SetFiltergraph(pGraph);
pCaptureGraphBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, dstName,
&pMux, &pWrite);

//--------------------------------------------
// Loop through the groups and get the output pins.
//--------------------------------------------

long numGroups,i;
IPin *pPin;

pTL->GetGroupCount(&numGroups);
for (i=0;i<numGroups;i++)
{
if (pRender->GetGroupOutputPin(i, &pPin) == S_OK)
{
// Connect the pin.

pCaptureGraphBuilder->RenderStream(NULL,NULL,pPin,NULL,pMux);
pPin->Release();
}
}

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();
}
The March Hare [MVP]
2006-05-09 14:00:49 UTC
Permalink
Post by davidb
Hi,
i wrote a app to trim AVIs.
...

This newsgroup is no longer active. Please see

http://tmhare.mvps.org/help.htm#where

to find the active dshow newsgroups and post in the most appropriate one.

In the future, I recommend you look at a few posts in a newsgroup before
posting in it.

060509.1
--
Microsoft MVPs: http://www.microsoft.com/mvp and
MVPs.org site http://www.mvps.org
My dshow site: http://tmhare.mvps.org
davidb
2006-05-09 14:49:01 UTC
Permalink
Ok,
i will look there.
Post by The March Hare [MVP]
In the future, I recommend you look at a few posts in a newsgroup before
posting in it.
Ok, so you have a answer to me? ;)

best regards, David

Loading...