directshow AVI 파일의 시간별 오디오 추출
void AudioExtraction(int Second)
{
IMediaControl *pControl = NULL;
ICaptureGraphBuilder2 *pBuilder = NULL;//
IGraphBuilder *pGraph = NULL; //
IAMTimeline *pTimeline = NULL; //
IAMTimelineObj *pAudioGroupObj = NULL; //
IRenderEngine *pRenderEngine = NULL; //
IMediaEvent *pEvent = NULL; //
IBaseFilter *pWaveDest = NULL; // WAV
IBaseFilter *pWriter = NULL; //
IFileSinkFilter *pSink = NULL;
IAMTimelineObj *pSource10bj = NULL;
IAMTimelineGroup *pAudioGroup = NULL;
IAMTimelineObj *pTrack10bj = NULL;
IAMTimelineSrc *pSource1Src = NULL;
IAMTimelineTrack *pTrack1 = NULL;
IAMTimelineComp *pRootComp = NULL;
IPin *pin = NULL;
IPin *pOut = NULL;
AM_MEDIA_TYPE mtGroup;
HRESULT hr;
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr)){MessageBox(NULL,TEXT("fail pGraph"),TEXT("f"),MB_OK);}
hr = CoCreateInstance(CLSID_AMTimeline, NULL, CLSCTX_INPROC_SERVER, IID_IAMTimeline, (void**)&pTimeline);
if (FAILED(hr)){MessageBox(NULL,TEXT("fail timeline"),TEXT("f"),MB_OK);}
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **)&pBuilder);
if (FAILED(hr)){MessageBox(NULL,TEXT("fail captureGraphBuilder"),TEXT("f"),MB_OK);}
hr = CoCreateInstance(CLSID_WavDest, NULL, CLSCTX_ALL, IID_IBaseFilter, (void **)&pWaveDest);
if (FAILED(hr)){MessageBox(NULL,TEXT("fail wavdest"),TEXT("f"),MB_OK);}
hr = CoCreateInstance(CLSID_FileWriter, NULL, CLSCTX_ALL, IID_IBaseFilter, (void **)&pWriter);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail writer"), TEXT("f"), MB_OK);}
hr = pTimeline->CreateEmptyNode(&pAudioGroupObj, TIMELINE_MAJOR_TYPE_GROUP);//
if (FAILED(hr)){MessageBox(NULL, TEXT("fail major type group"), TEXT("f") ,MB_OK);}
pAudioGroupObj->QueryInterface(IID_IAMTimelineGroup, (void**)&pAudioGroup);
ZeroMemory(&mtGroup, sizeof(AM_MEDIA_TYPE));
mtGroup.majortype = MEDIATYPE_Audio;
pAudioGroup->SetMediaType(&mtGroup);
hr = pTimeline->AddGroup(pAudioGroupObj);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail addGroup"), TEXT("f"), MB_OK);}
pTimeline->CreateEmptyNode(&pTrack10bj, TIMELINE_MAJOR_TYPE_TRACK);
pAudioGroup->QueryInterface(IID_IAMTimelineComp, (void**)&pRootComp);
pRootComp->VTrackInsBefore(pTrack10bj, -1);
pTimeline->CreateEmptyNode(&pSource10bj, TIMELINE_MAJOR_TYPE_SOURCE);
const LONGLONG NANOSECONDS = (1000000000); // 10 ^ 9
const LONGLONG UNITS = (NANOSECONDS / 100); // 10 ^ 7
REFERENCE_TIME TLStart = 0 * UNITS;
REFERENCE_TIME TLStop = 4 * UNITS;
pSource10bj->SetStartStop(TLStart, TLStop);
pSource10bj->QueryInterface(IID_IAMTimelineSrc, (void**)&pSource1Src);
//REFERENCE_TIME MediaStart=g_nNum * UNITS;
//REFERENCE_TIME MediaStop=(g_nNum+5) * UNITS;//
REFERENCE_TIME MediaStart;
REFERENCE_TIME MediaStop;
MediaStart = (Second-2) * UNITS;
MediaStop = (Second+2) * UNITS;
//else
//{
// MediaStart=5 * UNITS;
// MediaStop=11 * UNITS;
//}
pSource1Src->SetMediaTimes(MediaStart, MediaStop);
pSource1Src->SetMediaTimes(MediaStart, MediaStop);
BSTR bstrFile1 = SysAllocString(OLESTR("D:\\pictures\\SampleVideo.AVI"));
pSource1Src->SetMediaName(bstrFile1);
pTrack10bj->QueryInterface(IID_IAMTimelineTrack,(void**)&pTrack1);
pTrack1->SrcAdd(pSource10bj);
hr = pTimeline->ValidateSourceNames(SFN_VALIDATEF_CHECK | SFN_VALIDATEF_POPUP | SFN_VALIDATEF_REPLACE, NULL, 0 );
if (FAILED(hr)){MessageBox(NULL,TEXT("fail to add"),TEXT("f"),MB_OK);}
hr = CoCreateInstance(CLSID_RenderEngine,NULL,CLSCTX_INPROC_SERVER,IID_IRenderEngine,(void**)&pRenderEngine);
if (FAILED(hr)){MessageBox(NULL,TEXT("fail renderEngine"),TEXT("f"),MB_OK);}
pRenderEngine->SetTimelineObject(pTimeline);
hr = pRenderEngine->ConnectFrontEnd();
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to ConnectFrontEnd"), TEXT("f"), MB_OK);}
hr = pRenderEngine->GetFilterGraph(&pGraph);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to getFilterGraph"), TEXT("f"), MB_OK);}
hr = pGraph->QueryInterface( IID_IMediaEvent, (void**) &pEvent );
if (FAILED(hr)){printf("ERROR - failed to MediaEvent"); }
hr = pGraph->QueryInterface( IID_IMediaControl, (void**) &pControl );
if (FAILED(hr)){ printf("ERROR - failed to IID_IMediaControl"); }
pWriter->QueryInterface(IID_IFileSinkFilter, (void**)&pSink);
BSTR bstrFile2 = SysAllocString(OLESTR("C:\\1.wav"));
hr = pSink->SetFileName(bstrFile2,NULL);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to set filename"), TEXT("f"), MB_OK);}
pSink->Release();
hr=pGraph->AddFilter(pWaveDest,L"WavDest");
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to add WaveDest"), TEXT("f"), MB_OK);}
hr=pGraph->AddFilter(pWriter,L"FileWriter");
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to add FileWriter"), TEXT("f"), MB_OK);}
IPin *pPin;
hr = pRenderEngine->GetGroupOutputPin(0, &pPin);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to add GroupOut"), TEXT("f"), MB_OK);}
if(pWaveDest)
{
hr = pWaveDest->FindPin(L"In",&pin);
}
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to add wav"), TEXT("f"), MB_OK);}
hr = pGraph->Connect(pPin,pin);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to Add renderEngine->wavdest"), TEXT("f"), MB_OK);}
if(pWaveDest)
{
hr = pWaveDest->FindPin(L"Out", &pOut);
}
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to Add wavedest_out"),TEXT("f"), MB_OK);}
hr = pWriter->FindPin(L"in",&pin);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to Add Write in"),TEXT("f"), MB_OK);}
hr = pGraph->Connect(pOut,pin);
if (FAILED(hr)){MessageBox(NULL, TEXT("fail to Add wavdest->writer"),TEXT("f"), MB_OK);}
pControl->Run();
long EventCode = 0;
hr = pEvent->WaitForCompletion( INFINITE, &EventCode );
pControl->Stop();
pEvent->Release();
pControl->Release();
if(pWaveDest)
{
pWaveDest->Release();
}
pWriter->Release();
CoUninitialize();
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.