已经实现了
使用VFW.H里的
AVIFileOpen
AVIFileInfo
...
这些函数把非压缩AVI专成一张一张的BMP.但现在的问题时,抓出来的BMP图片失真比较严重,最右边的图象跑到了最左边
,并且上边有很多的条纹.这个是什么原因呢?程序如下:int main()
{
wchar_t aviFilename[256],bmpFilePath[256];
wcin >> aviFilename >> bmpFilePath; wcout << aviFilename << endl;
AVIFileInit();
PAVIFILE pAvi;
int result = AVIFileOpen( &pAvi , aviFilename , OF_READ , NULL );
if ( result != AVIERR_OK )
{
wcout << " can't open file" << endl;
if ( pAvi != NULL )
AVIFileRelease( pAvi );
return 0;
}
AVIFILEINFO avi_info;
AVIFileInfo( pAvi , &avi_info ,sizeof( AVIFILEINFO )) ;
PAVISTREAM pStream;
result = AVIFileGetStream( pAvi , &pStream , streamtypeVIDEO , 0L ); if ( result != AVIERR_OK )
{
wcout << "can't get stream " << endl;
if ( pStream != NULL )
{
AVIStreamRelease( pStream );
}
AVIFileExit();
return 0;
}
int iNumFrames;
int iFirstFrame;
iFirstFrame = AVIStreamStart( pStream );
if ( iFirstFrame == -1 )
{
wcout << " the first frame is -1" << endl;
if ( pStream != NULL )
{
AVIStreamRelease( pStream );
}
AVIFileExit();
return 0;
} iNumFrames = AVIStreamLength( pStream );
if ( iFirstFrame == -1 )
{
wcout << " the frame length is -1 " << endl;
if ( pStream != NULL )
{
AVIStreamRelease( pStream );
}
AVIFileExit();
return 0;
} BITMAPINFOHEADER bmpheader;
ZeroMemory( &bmpheader , sizeof( BITMAPINFOHEADER ) ); bmpheader.biBitCount = 24;
bmpheader.biClrImportant = 0;
bmpheader.biClrUsed = 0;
bmpheader.biCompression = BI_RGB;
bmpheader.biPlanes = 1;
bmpheader.biSize = 40;
bmpheader.biXPelsPerMeter = 0;
bmpheader.biYPelsPerMeter = 0;
bmpheader.biSizeImage = ((( bmpheader.biWidth * 3 ) + 3 ) &0xFFFC ) * bmpheader.biHeight ; PGETFRAME pFrame;
pFrame = AVIStreamGetFrameOpen( pStream , NULL ); AVISTREAMINFO streaminfo;
AVIStreamInfo( pStream , &streaminfo , sizeof( AVISTREAMINFO )); BITMAPINFOHEADER bmpheader1;
long lsize = sizeof( BITMAPINFOHEADER );
int index = 0 ;
for ( int i = iFirstFrame ; i < iNumFrames ; ++i )
{
index = i - iFirstFrame;
if ( index > 100 )
{
break;
}
BYTE *pDIB = (BYTE*) AVIStreamGetFrame( pFrame , index );
AVIStreamReadFormat( pStream , index , &bmpheader1 , &lsize );
BITMAPFILEHEADER stFileHdr; BYTE* bits = new BYTE[bmpheader1.biSizeImage];
AVIStreamRead(pStream,index,1,bits,bmpheader1.biSizeImage,NULL,NULL); bmpheader1.biClrUsed = 0;
stFileHdr.bfOffBits = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER );
stFileHdr.bfSize = sizeof( BITMAPFILEHEADER );
stFileHdr.bfType = 0x4d42;
ostringstream filepath;
filepath << bmpFilePath << "_" << i << ".bmp" ;
ofstream outfile( filepath.str().c_str() );
outfile.write( (const char *)&stFileHdr , sizeof( BITMAPFILEHEADER ) );
outfile.write( (const char *)&bmpheader1 , sizeof( BITMAPINFOHEADER ) );
outfile.write( (const char *)bits , bmpheader1.biSizeImage );
outfile.close();
delete bits;
}
AVIStreamGetFrameClose( pFrame );
if ( pStream != NULL )
AVIStreamRelease( pStream );
AVIFileExit(); return 0;}
使用VFW.H里的
AVIFileOpen
AVIFileInfo
...
这些函数把非压缩AVI专成一张一张的BMP.但现在的问题时,抓出来的BMP图片失真比较严重,最右边的图象跑到了最左边
,并且上边有很多的条纹.这个是什么原因呢?程序如下:int main()
{
wchar_t aviFilename[256],bmpFilePath[256];
wcin >> aviFilename >> bmpFilePath; wcout << aviFilename << endl;
AVIFileInit();
PAVIFILE pAvi;
int result = AVIFileOpen( &pAvi , aviFilename , OF_READ , NULL );
if ( result != AVIERR_OK )
{
wcout << " can't open file" << endl;
if ( pAvi != NULL )
AVIFileRelease( pAvi );
return 0;
}
AVIFILEINFO avi_info;
AVIFileInfo( pAvi , &avi_info ,sizeof( AVIFILEINFO )) ;
PAVISTREAM pStream;
result = AVIFileGetStream( pAvi , &pStream , streamtypeVIDEO , 0L ); if ( result != AVIERR_OK )
{
wcout << "can't get stream " << endl;
if ( pStream != NULL )
{
AVIStreamRelease( pStream );
}
AVIFileExit();
return 0;
}
int iNumFrames;
int iFirstFrame;
iFirstFrame = AVIStreamStart( pStream );
if ( iFirstFrame == -1 )
{
wcout << " the first frame is -1" << endl;
if ( pStream != NULL )
{
AVIStreamRelease( pStream );
}
AVIFileExit();
return 0;
} iNumFrames = AVIStreamLength( pStream );
if ( iFirstFrame == -1 )
{
wcout << " the frame length is -1 " << endl;
if ( pStream != NULL )
{
AVIStreamRelease( pStream );
}
AVIFileExit();
return 0;
} BITMAPINFOHEADER bmpheader;
ZeroMemory( &bmpheader , sizeof( BITMAPINFOHEADER ) ); bmpheader.biBitCount = 24;
bmpheader.biClrImportant = 0;
bmpheader.biClrUsed = 0;
bmpheader.biCompression = BI_RGB;
bmpheader.biPlanes = 1;
bmpheader.biSize = 40;
bmpheader.biXPelsPerMeter = 0;
bmpheader.biYPelsPerMeter = 0;
bmpheader.biSizeImage = ((( bmpheader.biWidth * 3 ) + 3 ) &0xFFFC ) * bmpheader.biHeight ; PGETFRAME pFrame;
pFrame = AVIStreamGetFrameOpen( pStream , NULL ); AVISTREAMINFO streaminfo;
AVIStreamInfo( pStream , &streaminfo , sizeof( AVISTREAMINFO )); BITMAPINFOHEADER bmpheader1;
long lsize = sizeof( BITMAPINFOHEADER );
int index = 0 ;
for ( int i = iFirstFrame ; i < iNumFrames ; ++i )
{
index = i - iFirstFrame;
if ( index > 100 )
{
break;
}
BYTE *pDIB = (BYTE*) AVIStreamGetFrame( pFrame , index );
AVIStreamReadFormat( pStream , index , &bmpheader1 , &lsize );
BITMAPFILEHEADER stFileHdr; BYTE* bits = new BYTE[bmpheader1.biSizeImage];
AVIStreamRead(pStream,index,1,bits,bmpheader1.biSizeImage,NULL,NULL); bmpheader1.biClrUsed = 0;
stFileHdr.bfOffBits = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER );
stFileHdr.bfSize = sizeof( BITMAPFILEHEADER );
stFileHdr.bfType = 0x4d42;
ostringstream filepath;
filepath << bmpFilePath << "_" << i << ".bmp" ;
ofstream outfile( filepath.str().c_str() );
outfile.write( (const char *)&stFileHdr , sizeof( BITMAPFILEHEADER ) );
outfile.write( (const char *)&bmpheader1 , sizeof( BITMAPINFOHEADER ) );
outfile.write( (const char *)bits , bmpheader1.biSizeImage );
outfile.close();
delete bits;
}
AVIStreamGetFrameClose( pFrame );
if ( pStream != NULL )
AVIStreamRelease( pStream );
AVIFileExit(); return 0;}
for ( int l = 0 ; l < bmpheader1.biHeight ; ++l )
{
outfile.write( (const char *) &bits[l*bmpheader1.biWidth*3],bmpheader1.biWidth*3);
int k = bmpheader1.biWidth * 3 % 4;
if ( k != 0 )
{
while ( k-- != 0 )
outfile.put( '0x00' );
}
}
还是不行,好象和这个没有关系,我怀疑是从流中取的桢就有问题
(不知道可以怎么测试一下,数据太多了,对比不过来)
另外从流中取得的数据,我感觉,就已经填充了0,和按照逆序存储了.
[email protected]