Original Post
Hi, I am running through a problem and thought you may help me out with this, sorry if i am bothering you. Here is my issue, I am trying to convert an AVI ( 8 bits per pixel ) file into a stream of bmp files, though i am able to convert them the bmp, images does not match the avi frames they are some what right shifted in a round robin way. Please let me know were i am going wrong. Please let me know were i can share the avi and generated bmp files. My Code System::Boolean Form1::createDicomFromAvi() { AVIFileInit(); PAVIFILE avi; const char* filePath = this->getSeriesPath(); int instNo = this->pImage->getInstanceNo(); String *aviFileName = String::Concat(filePath, "\\", instNo.ToString(), ".avi"); System::IntPtr aviPath = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(aviFileName); //int res=AVIFileOpen(&avi, (char *)aviPath.ToPointer(), OF_READ, NULL); int res=AVIFileOpen(&avi, "LOOP.AVI", OF_READ, NULL); if (res!=AVIERR_OK) { RAD_LOG_ERROR("Error While Opening a AVI file"); if (avi!=NULL) AVIFileRelease(avi); return FALSE; } AVIFILEINFO avi_info; AVIFileInfo(avi, &avi_info, sizeof(AVIFILEINFO)); RAD_LOG_INFO("Dimention: %dx%d\n" "Length: %d frames\n" "Max bytes per second: %d\n" "Samples per second: %d\n" "Streams: %d\n" "File Type: %d", avi_info.dwWidth, avi_info.dwHeight, avi_info.dwLength, avi_info.dwMaxBytesPerSec, (DWORD) (avi_info.dwRate / avi_info.dwScale), avi_info.dwStreams, avi_info.szFileType) PAVISTREAM pStream; res=AVIFileGetStream(avi, &pStream, streamtypeVIDEO /*video stream*/, 0 /*first stream*/); if (res!=AVIERR_OK) { RAD_LOG_ERROR("Error While Getting the stream from the avi file"); if (pStream!=NULL) AVIStreamRelease(pStream); AVIFileExit(); return FALSE; } //do task with the stream int iNumFrames; int iFirstFrame; iFirstFrame=AVIStreamStart(pStream); if (iFirstFrame==-1) { //Error getteing the frame inside the stream RAD_LOG_ERROR("Error Getting The Frame Inside The Stream"); if (pStream!=NULL) AVIStreamRelease(pStream); AVIFileExit(); return FALSE; } iNumFrames=AVIStreamLength(pStream); if (iNumFrames==-1) { //Error getteing the number of frames inside the stream RAD_LOG_ERROR("Error Getting The Number Of Frames Inside The Stream"); if (pStream!=NULL) AVIStreamRelease(pStream); AVIFileExit(); return FALSE; } AVISTREAMINFOA streamInfo; AVIStreamInfo(pStream,&streamInfo,sizeof(streamInfo)); //LONG lSize; //if(AVIStreamReadFormat(pStream, AVIStreamStart(pStream), NULL, &lSize)) // return false; //LPBYTE pChunk = new BYTE[lSize]; //if(!pChunk) // return false; //if(AVIStreamReadFormat(pStream, AVIStreamStart(pStream), pChunk, &lSize)) // return false; //LPBITMAPINFO m_pVideoFormats[5]; //m_pVideoFormats[1] = (LPBITMAPINFO)pChunk; //getting bitmap from frame LPBITMAPINFOHEADER bih = new BITMAPINFOHEADER; ZeroMemory(bih, sizeof(BITMAPINFOHEADER)); bih->biBitCount = 8; bih->biCompression = BI_RGB; //BI_RGB; bih->biHeight = streamInfo.rcFrame.bottom - streamInfo.rcFrame.top; bih->biWidth = streamInfo.rcFrame.right - streamInfo.rcFrame.left; bih->biPlanes = 1; bih->biSize = sizeof(bih); bih->biClrImportant = 256; PGETFRAME pFrame; //pFrame=AVIStreamGetFrameOpen(pStream, NULL/*(BITMAPINFOHEADER*) AVIGETFRAMEF_BESTDISPLAYFMT*/ /*&bih*/); //pFrame=AVIStreamGetFrameOpen(pStream,(BITMAPINFOHEADER*)AVIGETFRAMEF_BESTDISPLAYFMT); pFrame=AVIStreamGetFrameOpen(pStream,bih); //Get the first frame int index=0; for (int i=iFirstFrame; igetSeriesPath(); int instNo = this->pImage->getInstanceNo(); //String *bmpFileName1 = String::Concat(filePath, "\\", instNo.ToString()); String *bmpFileName = String::Concat(filePath, "\\", iFrame.ToString(), ".bmp"); System::IntPtr bmpPath = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(bmpFileName); FILE* fp=fopen((char *)bmpPath.ToPointer(), "wb"); if (fp!=NULL) { fwrite(&bfh, sizeof(bfh), 1, fp); fwrite(&memBitmapInfo, sizeof(memBitmapInfo), 1, fp); fwrite(Bits, bih.biSizeImage, 1, fp); fclose(fp); } else { RAD_LOG_ERROR("Error writing the bitmap file"); return FALSE; } delete [] Bits; return TRUE; }