Changing video rate

This page shows you how to change the video playback rate (speed). Please note that error handling codes are omitted to keep the sample code simple.

Sample code

The following sample code shows how to change the video rate. This sample plays video in 1/2 speed.


#include <stdio.h>

#include <dshow.h>

// change here
#define	FILENAME L"c:\\DXSDK\\Samples\\Media\\butterfly.mpg"

int
main()
{
 IGraphBuilder *pGraphBuilder;
 IMediaControl *pMediaControl;
 IMediaPosition *pMediaPosition;

 CoInitialize(NULL);

 CoCreateInstance(CLSID_FilterGraph,
	NULL,
	CLSCTX_INPROC,
	IID_IGraphBuilder,
	(LPVOID *)&pGraphBuilder);

 pGraphBuilder->QueryInterface(IID_IMediaControl,
	(LPVOID *)&pMediaControl);

 pGraphBuilder->QueryInterface(IID_IMediaPosition,
	(LPVOID *)&pMediaPosition);

 pMediaControl->RenderFile(FILENAME);

 // Slow playback (1.0 will be normal rate)
 // If you change 0.5 into 2.0, it will be
 // 2 times faster than normal rate.
 pMediaPosition->put_Rate(0.5);

 pMediaControl->Run();

 MessageBox(NULL,
	"Block Execution",
	"Block",
	MB_OK);

 pMediaPosition->Release();
 pMediaControl->Release();
 pGraphBuilder->Release();

 CoUninitialize();

 return 0;
}


This sample uses 0.5, and does slow playback. If you change the argument value used for put_Rate(), you can change the rate as you like.

  

Copyright (C) GeekPage.JP. All rights reserved.