1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
AVISTREAMINFO psi; // Pointer To A Structure Containing Stream Info
PAVISTREAM pavi; // Handle To An Open Stream
HIC hic;
LPBITMAPINFOHEADER m_outformat;// Contains decompressor output format
LPBITMAPINFOHEADER m_informat; // Contains decompressor input format
unsigned char * m_avidatac;
long lastframe; // Last Frame Of The Stream
int width; // Video Width
int height; // Video Height
int mpf; // Will Hold Rough Milliseconds Per Frame
AVIFileInit(); // Opens The AVIFile Library
// Opens The AVI Stream
if (AVIStreamOpenFromFile(&pavi, "test.avi", streamtypeVIDEO, 0, OF_READ, NULL) !=0)
{
// An Error Occurred Opening The Stream
MessageBox (HWND_DESKTOP, "Failed To Open The AVI Stream", "Error", MB_OK | MB_ICONEXCLAMATION);
}
AVIStreamInfo(pavi, &psi, sizeof(psi)); // Reads Information About The Stream Into psi
width=psi.rcFrame.right-psi.rcFrame.left; // Width Is Right Side Of Frame Minus Left
height=psi.rcFrame.bottom-psi.rcFrame.top; // Height Is Bottom Of Frame Minus Top
lastframe=AVIStreamLength(pavi); // The Last Frame Of The Stream
mpf=AVIStreamSampleToTime(pavi,lastframe)/lastframe; // Calculate Rough Milliseconds Per Frame
LONG size;
if (AVIStreamFormatSize(pavi, 0, &size)) {
//printf("[GLAvi::Init] AVIStreamFormatSize returned an error code\n");
return ;
}
// Setup our format structs
m_informat = (LPBITMAPINFOHEADER)new unsigned char[size];
m_outformat = (LPBITMAPINFOHEADER)new unsigned char[size];
if (!m_informat || !m_outformat) {
//printf("[GLAvi::Init] ERROR MEMALLOC m_format\n");
return ;
}
memset(m_outformat, 0, size);
memset(m_informat, 0, size);
// Read in our input format
if (AVIStreamReadFormat(pavi, 0, m_informat, &size)) {
//printf("[GLAvi::Init] AVIStreamReadFormat returned and error code\n");
return ;
}
// Since we dont want 2048x2048 textures we fail on large inputs
if (m_informat->biWidth > 1024) {
//printf("[GLAvi::Init] Input size to large\n");
return ;
}
// Setup our output format
m_outformat->biSize = size; // Sizof self (BITMAPINFOHEADER)
m_outformat->biWidth = m_informat->biWidth; // Set output size to input size for now
m_outformat->biHeight = m_informat->biHeight; // Set output size to input size for now
m_outformat->biPlanes = 1; // RGB 1 plane
m_outformat->biBitCount = 32; //4 bytes par pixel pour la trexture directx
// Now use ICLocate to find an appropriate decompressor
hic = ICLocate(ICTYPE_VIDEO, psi.fccHandler, m_informat, m_outformat, ICMODE_DECOMPRESS);
if (!hic) {
//printf("[GLAvi::Init] ICLocate did not return a decompressor\n");
return ;
}
// Determine if decompressor will work on AVI stream
if (ICDecompressQuery(hic, m_informat, m_outformat) != ICERR_OK) {
//printf("[GLAvi::Init] ICDecompressQuery failed cannot decompress format\n");
return ;
}
// Start our decompressor
if (ICDecompressBegin(hic, m_informat, m_outformat) != ICERR_OK) {
//printf("[GLAvi::Init] ICDecompressBegin failed");
return ;
}
m_avidatac = new unsigned char[512 * 512 * 3]; |
Partager