Advertisement

Playing MPEG-1 video

Started by January 15, 2000 09:03 AM
0 comments, last by Starfall 25 years, 1 month ago
I''m looking to play an MPEG-1 video using DirectX in a fullscreen application. I assume ActiveMovie is the easiest (and best?) way to do it with a minimum of hassle. For those of you who have experience with this, are there any potential pitfalls? Any advice you''d like to offer, or source code you have to share? I''d be interested in hearing any information that you have about this, and how it should be done. Thanks! Starfall
You should use DirectShow (this is included in the DirectX Media SDK) to play back any video files like avi, mpg, mov...
Please look in the documentation under Multimedia Streaming for details and sample code. If you don't have this SDK here is some sample code from the documentation (so that you have a starting point):

#include (stdio.h)
#include (ddraw.h) // DirectDraw interfaces
#include (mmstream.h) // multimedia stream interfaces
#include (amstream.h) // DirectShow multimedia stream interfaces
#include (ddstream.h) // DirectDraw multimedia stream interfaces



void RenderStreamToSurface(IDirectDrawSurface *pSurface,
IMultiMediaStream *pMMStream)
{
IMediaStream *pPrimaryVidStream;
IDirectDrawMediaStream *pDDStream;
IDirectDrawStreamSample *pSample;
RECT rect;
DDSURFACEDESC ddsd;

pMMStream->GetMediaStream(MSPID_PrimaryVideo, &pPrimaryVidStream);
pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&pDDStream);
ddsd.dwSize = sizeof(ddsd);
pDDStream->GetFormat(&ddsd, NULL, NULL, NULL);
rect.top = rect.left = 0;
rect.bottom = ddsd.dwHeight;
rect.right = ddsd.dwWidth;
pDDStream->CreateSample(pSurface, ▭, 0, &pSample);

pMMStream->SetState(STREAMSTATE_RUN);
while (pSample->Update(0, NULL, NULL, NULL) == S_OK);
pMMStream->SetState(STREAMSTATE_STOP);

pSample->Release();
pDDStream->Release();
pPrimaryVidStream->Release();
}

void RenderFileToMMStream(const char * szFileName,
IMultiMediaStream **ppMMStream,
IDirectDraw *pDD)
{
IAMMultiMediaStream *pAMStream;
CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER,
IID_IAMMultiMediaStream, (void **)&pAMStream);
WCHAR wPath[MAX_PATH]; // wide (32-bit) string name
MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wPath,
sizeof(wPath)/sizeof(wPath[0]));

pAMStream->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, NULL);
pAMStream->AddMediaStream(pDD, &MSPID_PrimaryVideo, 0, NULL);
pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
pAMStream->OpenFile(wPath, 0);
*ppMMStream = pAMStream;
}

int main(int argc, char *argv[])
{
if (argc < 2) {
printf("Usage : showstrm movie.ext\n");
exit(0);}

DDSURFACEDESC ddsd;
IDirectDraw *pDD;
IDirectDrawSurface *pPrimarySurface;
IMultiMediaStream *pMMStream;

CoInitialize(NULL);

DirectDrawCreate(NULL, &pDD, NULL);
pDD->SetCooperativeLevel(GetDesktopWindow(), DDSCL_NORMAL);
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
pDD->CreateSurface(&ddsd, &pPrimarySurface, NULL);
RenderFileToMMStream(argv[1], &pMMStream, pDD);
RenderStreamToSurface(pPrimarySurface, pMMStream);
pMMStream->Release();
pPrimarySurface->Release();
pDD->Release();

CoUninitialize();
return 0;
}

Edited by - VirtualNext on 1/17/00 3:56:54 AM

Edited by - VirtualNext on 1/17/00 3:58:39 AM

This topic is closed to new replies.

Advertisement