|
-
May 2nd, 2005, 06:20 PM
#1
Thread Starter
Good Ol' Platypus
(curse words) AVI (curse words)
Code:
#include <windows.h>
#include <vfw.h>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
class Video {
public:
Video(string path, HDC hdc, int nw);
~Video();
void showFrame(long frame);
private:
PAVIFILE aviFile;
PAVISTREAM aviStream;
AVISTREAMINFO aviStreamInfo;
BITMAPINFOHEADER bmih;
LPBITMAPINFOHEADER lpbi;
PGETFRAME pgf;
unsigned char* pdata;
HDRAWDIB hdd;
HDC drawdc;
int width, height, newwidth, newheight;
double fps, duration;
int length;
};
Video::Video(string path, HDC hdc, int nw) {
ofstream fout("video.log");
// initialise the AVI file library
// and open the video file/stream
AVIFileInit();
AVIFileOpenA(&aviFile, path.c_str(), OF_READ, NULL);
AVIFileGetStream(aviFile, &aviStream, streamtypeVIDEO, 0);
AVIStreamInfo(aviStream, &aviStreamInfo, sizeof(aviStreamInfo));
// get video stream data
width = aviStreamInfo.rcFrame.right - aviStreamInfo.rcFrame.left;
height = aviStreamInfo.rcFrame.bottom - aviStreamInfo.rcFrame.top;
DWORD aa = aviStreamInfo.fccHandler;
fps = double(aviStreamInfo.dwRate) / double(aviStreamInfo.dwScale);
length = aviStreamInfo.dwLength;
duration = double(length) / fps;
// figure out the destination width/height
newwidth = nw;
newheight = int(nw * double(height / double(width)));
// set up the destination bitmap
bmih.biSize = sizeof(BITMAPINFOHEADER);
bmih.biPlanes = 1;
bmih.biBitCount = 24;
bmih.biWidth = newwidth;
bmih.biHeight = newheight;
bmih.biCompression = BI_RGB;
// debug
fout << "stream size: " << width << "x" << height << endl;
fout << "dest. size: " << newwidth << "x" << newheight << endl;
fout << "fourcc: " << (char)(aa & 0xff) << endl;
fout << "framerate: " << setprecision(3) << fps << endl;
fout << "length: " << setprecision(3) << fixed
<< duration << "s (" << length << " frames)" << endl;
// open the stream for reading
pgf = AVIStreamGetFrameOpen(aviStream, NULL);
// create the bitmap and attach it to the dc
//data = 0;
//cdc = CreateCompatibleDC(0);
//hBitmap = CreateDIBSection(cdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS,
// (void**)(&data), NULL, 0);
//hOld = (HBITMAP)SelectObject(cdc, hBitmap);
// create the "drawdib" and store the DC
hdd = DrawDibOpen();
drawdc = hdc;
}
Video::~Video() {
DrawDibClose(hdd);
// SelectObject(drawdc, hOld);
// DeleteObject(hBitmap);
AVIStreamGetFrameClose(pgf);
AVIFileRelease(aviFile);
AVIFileExit();
}
void Video::showFrame(long frame) {
lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame);
pdata = (unsigned char*) lpbi + sizeof(BITMAPINFOHEADER);
DrawDibDraw(hdd, drawdc, 0, 0, newwidth, newheight,
lpbi, pdata, 0, 0, width, height, 0);
//BitBlt(drawdc, 0, 0, newwidth, newheight, cdc, 0, 0, SRCCOPY);
}
Any thoughts on why using this class just refuses to blit anything?
You use it like:
Code:
Video a("my.avi", hDC, 500) // 500 is the width of the image
a.showFrame(50);
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|