I wrote a program to trim a segment mpeg file to avi file, the video in the avi file is ok, but I can't output the audio into it. when I try to find out the output pin of the audio group, it returns error code:"the group does not has output pin", should I exract audio from mpeg file to a new file then add it to Timeline? please give any suggestion. my code is following: //Video hr = pTL->CreateEmptyNode(&pVideoGroupObj, TIMELINE_MAJOR_TYPE_GROUP); hr = pVideoGroupObj->QueryInterface(IID_IAMTimelineGroup, (void **)&pVideoGroup); AM_MEDIA_TYPE mtVideo; ZeroMemory(&mtVideo, sizeof(AM_MEDIA_TYPE)); mtVideo.majortype = MEDIATYPE_Video; mtVideo.subtype = MEDIASUBTYPE_RGB555; mtVideo.pbFormat = (BYTE*)CoTaskMemAlloc(sizeof(VIDEOINFOHEADER)); VIDEOINFOHEADER *pVideoHeader = (VIDEOINFOHEADER*)mtVideo.pbFormat; ZeroMemory(pVideoHeader, sizeof(VIDEOINFOHEADER)); //the m_mtSrcVideo is AM_MEDIA_TYPE info. gotten from mpeg file. VIDEOINFOHEADER *pVideoHeader0 = (VIDEOINFOHEADER*)m_mtSrcVideo.pbFormat; pVideoHeader->bmiHeader.biBitCount = pVideoHeader0->bmiHeader.biBitCount; pVideoHeader->bmiHeader.biWidth = pVideoHeader0->bmiHeader.biWidth; pVideoHeader->bmiHeader.biHeight = pVideoHeader0->bmiHeader.biHeight; pVideoHeader->bmiHeader.biPlanes = pVideoHeader0->bmiHeader.biPlanes; pVideoHeader->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pVideoHeader->bmiHeader.biSizeImage = DIBSIZE(pVideoHeader->bmiHeader); mtVideo.formattype = FORMAT_VideoInfo; mtVideo.cbFormat = sizeof(VIDEOINFOHEADER); mtVideo.bFixedSizeSamples = TRUE; mtVideo.lSampleSize = DIBSIZE(pVideoHeader->bmiHeader); hr = pVideoGroup->SetMediaType(&mtVideo); hr = pTL->AddGroup(pVideoGroupObj); hr = pTL->CreateEmptyNode(&pVideoTrackObj, TIMELINE_MAJOR_TYPE_TRACK); hr = pVideoGroup->QueryInterface(IID_IAMTimelineComp, (void **)&pVideoComp); hr = pVideoComp->VTrackInsBefore(pVideoTrackObj, 0); hr = pVideoTrackObj->QueryInterface(IID_IAMTimelineTrack, (void **)&pVideoTrack); hr = pTL->CreateEmptyNode(&pVideoSourceObj, TIMELINE_MAJOR_TYPE_SOURCE); hr = pVideoSourceObj->QueryInterface(IID_IAMTimelineSrc, (void **)&pVideoSource); //Audio hr = pTL->CreateEmptyNode(&pAudioGroupObj, TIMELINE_MAJOR_TYPE_GROUP); hr = pAudioGroupObj->QueryInterface(IID_IAMTimelineGroup, (void **)&pAudioGroup); AM_MEDIA_TYPE mtAudio; ZeroMemory(&mtAudio, sizeof(AM_MEDIA_TYPE)); mtVideo.majortype = MEDIATYPE_Audio; mtAudio.subtype = MEDIASUBTYPE_PCM; mtAudio.bFixedSizeSamples = m_mtSrcAudio.bFixedSizeSamples; //the m_mtSrcAudio is AM_MEDIA_TYP
liur17
Posts
-
help: no audio in directshow DES -
IAMStreamControl StartAt() doesn't work [modified]I want to control the avi write action by query the IAMStreamControl interface of input pin in pAviMux, see below: IAMStreamControl *pSC = NULL; hr = pMuxPin01->QueryInterface(IID_IAMStreamControl, (void **)&pSC); hr = pSC->StartAt(&rtStart, 0); //rtStart = 3 seconds hr = pSC->StopAt(&rtStop, FALSE, 0); //rtStop = 9 seconds hr = pMediaControl->Run(); when I set the parameter of StartAt() as NULL, it works OK, the pMuxAvi stop the writing at rtStop time. however, when I give a rtStart parameter to StartAt() function, the pMuxAvi write a corrupt avi file which is only 127kb in size. what's wrong with the StartAt() function? please help. -- modified at 6:02 Saturday 14th July, 2007
-
I am getting 'ICaptureGraphBuilder2' : missing storage-class or type specifiersI wrote below function in VC6 one year ago, maybe it can give you some hints. BOOL CMyClass::CaptureImage(LPCSTR szFileName) { if (pVMRWindowlessControl== NULL) return FALSE; BYTE* lpImage = NULL; if (pVMRWindowlessControl->GetCurrentImage(&lpImage) == S_OK) { BITMAPFILEHEADER hdr; DWORD dwSize, dwWritten; LPBITMAPINFOHEADER pDib = (LPBITMAPINFOHEADER)lpImage; //创建文件供写入 HANDLE hFile = CreateFile(szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) return FALSE; //初始化BITMAP文件头 dwSize = DibSizeImage(pDib); hdr.bfType = BFT_BITMAP; hdr.bfSize = dwSize + sizeof(BITMAPFILEHEADER); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; hdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + pDib->biSize + DibPaletteSize(pDib); //写入文件头及内容 WriteFile(hFile, (LPCVOID)&hdr, sizeof(BITMAPFILEHEADER), &dwWritten, 0); WriteFile(hFile, (LPCVOID)pDib, dwSize, &dwWritten, 0); CloseHandle(hFile); CoTaskMemFree(lpImage); } return TRUE; }
-
I am getting 'ICaptureGraphBuilder2' : missing storage-class or type specifiersthe Class ICaptureGraphBuilder2 is defined in strmif.h; and the CLSID_CaptureGraphBuilder2 is defined in uuids.h
-
can't get pin category propertyI can't get the pin category property in my directshow program, I try all pins in all filters(pSrcFilter, pMux, pMpeg2Splitter, pDecoder, etc), but every pin can't query the IKsPropertySet, it alawys return fail, so i can't know that the pin category is PIN_CATEGORY_CAPTURE or PIN_CATEGORY_PREVIEW, why? please give me some suggestion. IKsPropertySet *pKs; hr = pPin->QueryInterface(IID_IKsPropertySet, (void **)&pKs); if (FAILED(hr)) { return FALSE; }
-
Help: Media seek in directshowThank you very much. I checked my mailbox and not found your mail.(maybe the antivirus software ate it:(,), however after I follow your instruction to read the "Seeking the Filter Graph" in MSDN, I still can't find out the answer, It only tell me how to seek the media for rendering the media on screen, I also use pMediaSeeking->GetCapabilities(...) to check if it supports seeking, it return S_OK.
-
fatal error C1083: Cannot open include file: 'dshow.h': No such file or directorygo to menu Tools->options, click "Directories" tab in option dialog, input "c:\dxsdk\include" (your directx installation directory), then move it to top.
-
Help: Media seek in directshowI wrote a program to convert mpeg file to avi in directshow, now the conversion is OK, but I can't find out a method to seek the source media, I want to seek to a given point in source media before the conversion begin. In other words, I want to convert a segment of mpeg file to avi file. The structure of my program is following: 1. Read source mpeg file by using pGraph->AddSourceFilter(...); 2. Init IMediaSeeking, IMediaControl, etc by query pGraph; 3. Setup output avi file and init pMux by using pBuilder->SetOutputFileName(...); 4. Create Mpeg splitter and Mpeg Decoder then add them to pGraph; 5. Connect all filters by using pBuilder->RenderStream(....); 6. Start conversion by using pMediaControl->run(). now the conversion of whole mpeg file is OK, but I can't seek the source media, the pMediaSeeking->SetPositions(...) and GetDuration() function always return fail. I also tried to seek media by pMux but failed. someone can give me instruction to resolve it? thanks in advance.
-
convert mpg to avi in directshowI got it. Thank you for your kind reply.
-
convert mpg to avi in directshowThanks you very much! I get the root of problem by using graphedit.exe: the input mpg file is a mpeg-1 file, so the file source filer outputs mpeg1-stream, but mpeg2demultiplexer requires mpeg2-stream, when it's running, it popup many DCDSPFilter.ax window and show a error message: These filters cannot agree on a connection, verify type compatibility of input pin and output pin. after I change the mpeg2demultiplexer to mpeg1streamsplitter and add the mpeg1 decoder, it runs OK. But this remains a problem: how can I get the type of mpeg file? I have to identify the file type(mpeg1 or mpeg2) programmly so that I can add the according filter. ???
-
convert mpg to avi in directshowRecently I try to convert mpg file to avi programmly, but it doesn't work , i am a beginner:) ,the code list below, anyone can give me suggestion? thanks. hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); IBaseFilter *pSrcFilter = NULL; hr = pGraph->AddSourceFilter(lpMpgFile, L"Source Filter", &pSrcFilter); hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **)&pBuilder); pBuilder->SetFiltergraph(pGraph); hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, lpOutputAviFile, &pMux, NULL); hr = pGraph->AddFilter(pMux, L"Mux Filter"); IBaseFilter *pMpeg2Splitter= NULL; hr = CoCreateInstance(CLSID_MPEG2Demultiplexer, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pMpeg2Splitter); hr = pGraph->AddFilter(pMpeg2Splitter, L"Mpeg2 Splitter"); IMpeg2Demultiplexer *pDemux = NULL; hr = pMpeg2Splitter->QueryInterface(IID_IMpeg2Demultiplexer, (void**)&pDemux); AM_MEDIA_TYPE pMediaType; memset(&pMediaType, 0x0, sizeof(pMediaType)); pMediaType.majortype = MEDIATYPE_Video; pMediaType.subtype = MEDIASUBTYPE_MPEG2_VIDEO; pMediaType.formattype = FORMAT_MPEG2Video; pMediaType.bFixedSizeSamples = FALSE; pMediaType.bTemporalCompression = TRUE; pMediaType.lSampleSize = 0; MPEG2VIDEOINFO video_info; memset(&video_info, 0x0, sizeof(MPEG2VIDEOINFO)); pMediaType.cbFormat = sizeof(MPEG2VIDEOINFO); pMediaType.pbFormat = (BYTE *)&video_info; AM_MEDIA_TYPE pMediaAudioType; memset(&pMediaAudioType, 0x0, sizeof(pMediaAudioType)); pMediaAudioType.majortype = MEDIATYPE_Audio; pMediaAudioType.subtype = MEDIASUBTYPE_MPEG1Payload; pMediaAudioType.formattype = FORMAT_WaveFormatEx; pMediaAudioType.bFixedSizeSamples = FALSE; pMediaAudioType.bTemporalCompression = FALSE; pMediaAudioType.lSampleSize = 0; MPEG1WAVEFORMAT audio_info; memset(&audio_info, 0x0, sizeof(MPEG1WAVEFORMAT)); pMediaAudioType.cbFormat = sizeof(MPEG1WAVEFORMAT); pMediaAudioType.pbFormat = (BYTE *)&audio_info; IPin *pPin0 = NULL; hr = pDemux->CreateOutputPin(&pMediaType, L"Video Output", &pPin0); IMPEG2StreamIdMap *pStreamIdMap = NULL; hr = pPin0->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap); hr = pStreamIdMap->MapStreamId(0xC0, MPEG2_PROGRAM_ELEMENTARY_STREAM, 0, 0); IPin *pPin1 = NULL; hr = pDemux->CreateOutputPin(&pMediaAudioType, L"Audio Output", &pPin1); IMPEG2StreamIdMap *pStreamIdMap1 = NULL; hr = pPin1->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap1); hr = pStreamIdMap1->MapStre
-
True DBGrid in VC++Thanks for your reply. I use True OLE DataGrid 7, using bound mode. Looking forward to your instruction, Thank you in advance.
-
True DBGrid in VC++Hi, I try to translate text to text in True DBGrid control, but it seems not work in VC++, my code list below: .... CValueItems oValueItems; oValueItems = m_CtrlTDBG.GetColumns().GetItem(&index).GetValueItems(); CValueItemDisp* pValueItemDisp = new CValueItemDisp(); pValueItemDisp->SetValue(old_value); pValueItemDisp->SetDisplayValue(new_value); oValueItems.Add((LPDISPATCH)pValueItemDisp); oValueItems.SetTranslate(TRUE); .... I don't know how to use the function CValueItems.Add(LPDISPATCH vItem), someone can give me any suggestion? Thanks!
-
Retrieving VARCHAR out of MSSQL with ADOHi, It's very strange, i use mssql2000+sp4 and not found this trouble. why didn't you using strValue.trimRight() to trim the space off?
-
Retrieving VARCHAR out of MSSQL with ADOHi, I use _variant_t to get the value _variant_t tValue = pRS->GetFields()->GetItem(_T("YouFieldName"))->GetValue(); it works well, if you want to get CString type data, then: tValue.ChangeType(VT_BSTR);CString strValue = tValue.bstrVal;
-
How to SetEvenRowStyle in truedbgrid control in run time?Hi, I use truedbgrid control to show the table in vc++, but i don't know how to use the function SetEvenRowStyle(LPDISPATCH) and SetOddRowStyle(LPDISPATCH), anyone can tell me how to pass the LPDISPATCH parameter? Thanks!
-
Look for a powerful datagrid control for VC++TrueDB is a good grid control, Thanks.
-
Look for a powerful datagrid control for VC++Hi, is there a free powerful datagrid control for VC++? its color could be changed, and also can add droplist in its field. Thanks.
-
How to put a dll to remote XP and run it?Thanks, my mean is how to put the dll into remote XP and loading it by rundll32 command. could you give me any suggestion? liur
-
How to connect toan ORACLE DB Using VC++6?to access oracle db using vc++, you can use ADO: #define INITGUID #import "c:\program files\common files\system\ado\msado15.dll" rename_namespace("ADO_RWXLS") rename("EOF","EndOfFile") using namespace ADO_RWXLS; #include "icrsint.h" _ConnectionPtr pConn; ::CoInitialize(NULL); pConn.CreateInstance(__uuidof(Connection)); CString strConn; strConn.Format(_T("Provider=MSDAORA.1;Data Source=%s;Database=%s;User ID=yourname;Password=yourpasswd"),strServerName,strServerName); pConn->Open(str_Connection, "", "", adOpenUnspecified); liur -- modified at 2:22 Sunday 14th January, 2007