怎么用VC实现逐帧处理视频图像文件

如何用VC实现逐帧处理视频图像文件
如何用VC实现逐帧处理视频图像文件

小弟初学VC++,很多东西都不知道,向问问那位大哥大姐,忙帮解决这个问题,是用一个函数呢还是怎么办,期待您的帮助!有没有程序源码啊?
可直接回复,也可发到我邮箱里:leozhang81@163.com
先谢谢啦!


------解决方案--------------------
看DShow的SDK吧,基本上就是写一个transform filter,在它的transform函数中处理。
------解决方案--------------------
2楼说得没错,你应该研究一下DirectShow. 不过刚学VC就做这个事情,还是困难了点。
一般地说,微软提供了一个框架,你只要实现框架中的一部分就行了。

下面是我前年做的一个filter的例子(删除了大部分),请注意:函数ProcessFrame(),每一桢图像都是在这里面处理的。
这个是基于MS的一个例子做的,你可以查一查。


//----------------------------------------
// File: YuvGray.cpp
//
// Description: 
// YuvGray is a DirectShow transform filter that converts UYVY color images
// to grayscale.
//-----------------------------------------


#ifdef _DEBUG
#ifndef DEBUG
#define DEBUG
#endif
#endif

#include <streams.h> // DirectShow base class library

#include <aviriff.h> // defines 'FCC' macro


// Forward declares
void GetVideoInfoParameters(
const VIDEOINFOHEADER *pvih, // Pointer to the format header.
BYTE * const pbData, // Pointer to the first address in the buffer.
DWORD *pdwWidth, // Returns the width in pixels.
DWORD *pdwHeight, // Returns the height in pixels.
LONG *plStrideInBytes, // Add this to a row to get the new row down
BYTE **ppbTop, // Returns pointer to the first byte in the top row of pixels.
bool bYuv
);


bool IsValidUYVY(const CMediaType *pmt);


// Define the filter's CLSID

// {A6512C9F-A47B-45ba-A054-0DB0D4BB87F7}
static const GUID CLSID_YuvGray = 
//{ 0xa6512c9f, 0xa47b, 0x45ba, { 0xa0, 0x54, 0xd, 0xb0, 0xd4, 0xbb, 0x87, 0xf7 } };
// {41A6188E-8892-48f1-93EF-78A5E47BD842}
{ 0x41a6188e, 0x8892, 0x48f1, { 0x93, 0xef, 0x78, 0xa5, 0xe4, 0x7b, 0xd8, 0x42 } };


static const WCHAR g_wszName[] = L"YUV Filter"; // A name for the filter 



//----------------------------------------
// CYuvGray Class
//
// This class defines the filter. It inherits CTransformFilter, which is a 
// base class for copy-transform filters. 
//-----------------------------------------

class CYuvGray : public CTransformFilter
{
public:

// ctor
CYuvGray(LPUNKNOWN pUnk, HRESULT *phr) :
CTransformFilter(NAME("YUV Transform Filter"), pUnk, CLSID_YuvGray)
{}

// Overridden CTransformFilter methods
HRESULT CheckInputType(const CMediaType *mtIn);
HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut);
HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pProp);
HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
HRESULT Transform(IMediaSample *pIn, IMediaSample *pOut);

// Override this so we can grab the video format
HRESULT SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt);

// Static object-creation method (for the class factory)
static CUnknown * WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr); 

private:
HRESULT ProcessFrame(BYTE *pbInput, BYTE *pbOutput, long *pcbByte);

VIDEOINFOHEADER m_VihIn; // Holds the current video format (input)
VIDEOINFOHEADER m_VihOut; // Holds the current video format (output)

};




HRESULT CYuvGray::ProcessFrame(BYTE *pbInput, BYTE *pbOutput, long *pcbByte)
{

DWORD dwWidth, dwHeight; // Width and height in pixels
LONG lStrideIn, lStrideOut; // Stride in bytes