|
Recently 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->MapStreamId(0xE0, MPEG2_PROGRAM_ELEMENTARY_STREAM, 0, 0);
//error occurs in below code
hr = pBuilder->RenderStream(NULL, NULL, pSrcFilter, NULL, pMpeg2Splitter);
hr = pBuilder->RenderStream(NULL, NULL, pMpeg2Splitter, NULL, pMux);
hr = pBuilder->RenderStream(NULL, NULL, pMpeg2Splitter, NULL, pMux);
.......
|
|
|
|
|
why doen't it work ?
what error do you get ?
|
|
|
|
|
A few potential problems...
SetOutputFileName() adds the AVI mux filter to the graph - you don't need to add it manually.
I'm not sure why you're using the MPEG2 splitter AND muxer.
Regardless, you'll need an mpeg2 decoder for it to work (I don't think there's one included with
Windows).
I would try simplifying your graph building first. Compare your method to the method shown here:
Building the Recompression Graph[^]
Also testing it in graphedit.exe can help to make sure you're using the correct filters.
MArk
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
Thanks 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. ???
|
|
|
|
|
liur17 wrote: 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. ???
2 possible ways I can think of:
1) After the successful AddSourceFilter() call, obtain a IFileSourceFilter interface from the
source filter and use the IFileSourceFilter::GetCurFile() method to get the media type (looking
for MPEG subtypes).
2) Let intelligent connect insert the necessary filters for you.
Use AddSourceFilter() and SetOutputFileName() like you're doing, add the compressor filter you
want for the destination AVI file, and use RenderStream() to connect the filters added by
AddSourceFilter() and SetOutputFileName(), with the intermediate compressor filter.
If you have suitable MPEG filters installed, intelligent connect will insert them for you.
If not, RenderStream() will fail.
A second call to RenderStream() will connect an audio stream to the AVI muxer if it's available
(again, see here[^] for an example.
You can try this in graphedit by manually adding a filesource async filter, setting the input
filename, add a filewriter filter, set the output filename, add an AVI Mux filter, and connect
the filesource to the filewriter filter.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
I got it. Thank you for your kind reply.
|
|
|
|
|
|
1. For UI Localization: Is is possible to have VC++.Net 2003 application with resources in .rc file for one language (English) and resouce only dll for another language (Japanese)?
2. What modification in code required to handle the switching between .rc and dll resources @ runtime to display the appropriate UI resources in the corresponding language? (either after changing the locale of the English OS or running the application on Japanese OS)?
Thanks & Regards,
Neeraj
|
|
|
|
|
Hi all,
Part of the app I'm developing downloads fairly large files via HTTP. Everything works great, except for when the clients network connection is dropped. I have tried using WSAGetLastError, but it always returns 0. The thread just keeps pulling mystical data, then it just stops after about 300 or so KB. No crash or anything.
do
{
len = recv( Socket, buffer, sizeof( buffer ), 0 );
if( ( pos + len ) > contentLength )
return 0;
memcpy( body + pos, buffer, len );
pos += len;
int error = WSAGetLastError( );
if( error )
return 0;
} while( len > 0 );
To simulate a network drop I am turning my modem off.
Has anyone got a solution to this?
|
|
|
|
|
Silly me. I just realised that the socket was blocking.
I set it to non-blocking and it works fine.
|
|
|
|
|
<br />
class Foo<br />
{<br />
private:<br />
int (*pf)(int);<br />
<br />
public:<br />
Foo()<br />
{<br />
this->pf = &Foo::cube;
}<br />
<br />
private:<br />
int cube(int n) {return n*n*n;}<br />
<br />
};<br />
how do i get that statement in the constructor working? any help is greatly appreciated.
|
|
|
|
|
eirche wrote: int (*pf)(int);
Should make this a member function pointer. So it should be...
int (<code>Foo::</code>*pf)(int);
|
|
|
|
|
thank you for the quick response. it's working like a charm.
|
|
|
|
|
set the cube() member function either static or global...
|
|
|
|
|
hi all
I use in my program WaitForMultipleObjects function for chake if some process that I use stop or not, but If some ot the programs made mistake this funtion dont returns.
how I can chake my programs are runing or thay stoped?
|
|
|
|
|
can you please write a proper english ?
i can't get a word of what you're saying...
|
|
|
|
|
|
david bagaturia wrote: how I can chake my programs are runing or thay stoped?
Programatically:
When you create the process, store the handler. You can then later check handler after handler if the process is still running.
Physically:
Hit Ctrl+Shift+Esc, go to process tab, and check if your processes are still alive.
|
|
|
|
|
Perhaps something like this:
bool HasProcessExited(HANDLE hProcess)
{
return WaitForSingleObject(hProcess, 0)==WAIT_OBJECT_0;
}
Steve
|
|
|
|
|
Could you please tell , what type of handles are you using for WaitForMultipleObject()?
AJay
|
|
|
|
|
ok.
I create come process and if it status is Not Responding... WaitForMultipleObjects(...) function dont returns and sow my program wait and it is tsoped too.
I whont to know my process whorks or not?
or it have "Not Responding..." status.
|
|
|
|
|
I am not totally clear on what you are experiencing. But here's some thoughts.
1. Don't wait inside a windows message handler. If you block for an extended period inside the message handling thread -- you could be seen as "not responding".
2. Use a reasonably short timeout on your wait. You can always wait twice.
3. Make sure you are using the correct handle in your Wait() call. How are you getting this process handle?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
"How are you getting this process handle?"
CreateProcessA(NULL, CmdLine, NULL, NULL,<br />
FALSE, dwCreationFlags, NULL,<br />
NULL, &si, &pi)
sow I get this handle 'pi.hProcess'.
thanks.
|
|
|
|
|
Hello,
I'm trying to catch mouse buttons (5) via the XBUTTONS and would like to do this in an MFC environment. I have seen some examples in Win32, but not MFC.
I have declared the following in the CMainFrame message map
ON_MESSAGE(WM_APPCOMMAND, OnAppCommand)
then try to process it within the function...
LRESULT CMainFrame::OnAppCommand(WPARAM wParam, LPARAM lParam),
...but this function never gets called.
Any help greatly appreciated.
Cheers,
Grant.
|
|
|
|
|
Maybe you need to put it into the CView class instead.
Maybe the message does not make it to the mainframe.
|
|
|
|
|