added support for video compression (no support for YUV color space)

This commit is contained in:
spacy51 2007-12-17 17:42:56 +00:00
parent 396170e506
commit 0f73f98815
5 changed files with 63 additions and 12 deletions

View File

@ -26,11 +26,16 @@ AVIWrite::AVIWrite()
m_file = NULL;
m_videoStream = NULL;
m_audioStream = NULL;
ZeroMemory( &m_videoCompSettings, sizeof( m_videoCompSettings ) );
ZeroMemory( &m_audioCompSettings, sizeof( m_audioCompSettings ) );
m_videoCompressed = NULL;
m_audioCompressed = NULL;
m_frameRate = 0;
m_frameCounter = 0;
m_sampleCounter = 0;
m_videoFrameSize = 0;
m_audioFrameSize = 0;
m_audioBlockAlign = 0;
AVIFileInit();
}
@ -38,10 +43,18 @@ AVIWrite::AVIWrite()
AVIWrite::~AVIWrite()
{
if( m_audioCompressed ) {
AVIStreamRelease( m_audioCompressed );
}
if( m_audioStream ) {
AVIStreamRelease( m_audioStream );
}
if( m_videoCompressed ) {
AVIStreamRelease( m_videoCompressed );
}
if( m_videoStream ) {
AVIStreamRelease( m_videoStream );
}
@ -78,18 +91,21 @@ bool AVIWrite::CreateAVIFile( LPCTSTR filename )
// colorBits: 16, 24 or 32
bool AVIWrite::CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorBits, DWORD framesPerSecond )
bool AVIWrite::CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorBits, DWORD framesPerSecond, HWND parentWnd )
{
if( m_videoStream || m_failed ) return false;
HRESULT err = 0;
AVISTREAMINFO videoInfo;
BITMAPINFOHEADER bitmapInfo;
AVICOMPRESSOPTIONS *settings[1];
ZeroMemory( &videoInfo, sizeof( videoInfo ) );
ZeroMemory( &bitmapInfo, sizeof( bitmapInfo ) );
settings[0] = &m_videoCompSettings;
// -- initialize the video stream information --
videoInfo.fccType = streamtypeVIDEO;
videoInfo.fccHandler = 0;
videoInfo.dwScale = 1;
videoInfo.dwRate = framesPerSecond;
videoInfo.dwSuggestedBufferSize = imageWidth * imageHeight * ( colorBits >> 3 );
@ -107,6 +123,33 @@ bool AVIWrite::CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorB
}
// -- ask for compression settings --
if( AVISaveOptions(
parentWnd,
0,
1,
&m_videoStream,
settings ) )
{
err = AVIMakeCompressedStream(
&m_videoCompressed,
m_videoStream,
settings[0],
NULL
);
AVISaveOptionsFree( 1, settings );
if( FAILED( err ) ) {
m_failed = true;
return false;
}
} else {
AVISaveOptionsFree( 1, settings );
m_failed = true;
return false;
}
// -- initialize the video stream format --
bitmapInfo.biSize = sizeof( bitmapInfo );
bitmapInfo.biWidth = imageWidth;
@ -118,10 +161,10 @@ bool AVIWrite::CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorB
// -- set the video stream format --
err = AVIStreamSetFormat(
m_videoStream,
m_videoCompressed,
0,
&bitmapInfo,
sizeof( bitmapInfo )
bitmapInfo.biSize + ( bitmapInfo.biClrUsed * sizeof( RGBQUAD ) )
);
if( FAILED( err ) ) {
@ -129,6 +172,7 @@ bool AVIWrite::CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorB
return false;
}
m_frameRate = framesPerSecond;
m_videoFrameSize = imageWidth * imageHeight * ( colorBits >> 3 );
@ -139,7 +183,7 @@ bool AVIWrite::CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorB
// call AddVideoStream() first
// channelCount: max. 2
// sampleBits: max. 16
bool AVIWrite::CreateAudioStream( WORD channelCount, DWORD sampleRate, WORD sampleBits )
bool AVIWrite::CreateAudioStream( WORD channelCount, DWORD sampleRate, WORD sampleBits, HWND parentWnd )
{
if( m_audioStream || m_failed ) return false;
@ -207,7 +251,7 @@ bool AVIWrite::AddVideoFrame( LPVOID imageData )
HRESULT err = 0;
err = AVIStreamWrite(
m_videoStream,
m_videoCompressed,
m_frameCounter,
1,
imageData,

View File

@ -28,8 +28,8 @@ public:
virtual ~AVIWrite();
bool CreateAVIFile( LPCTSTR filename );
bool CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorBits, DWORD framesPerSecond );
bool CreateAudioStream( WORD channelCount, DWORD sampleRate, WORD sampleBits );
bool CreateVideoStream( LONG imageWidth, LONG imageHeight, WORD colorBits, DWORD framesPerSecond, HWND parentWnd );
bool CreateAudioStream( WORD channelCount, DWORD sampleRate, WORD sampleBits, HWND parentWnd );
bool AddVideoFrame( LPVOID imageData );
bool AddAudioFrame( LPVOID soundData );
@ -38,6 +38,10 @@ private:
PAVIFILE m_file;
PAVISTREAM m_videoStream;
PAVISTREAM m_audioStream;
AVICOMPRESSOPTIONS m_videoCompSettings;
AVICOMPRESSOPTIONS m_audioCompSettings;
PAVISTREAM m_videoCompressed;
PAVISTREAM m_audioCompressed;
DWORD m_frameRate;
LONG m_frameCounter;
LONG m_sampleCounter;

View File

@ -406,10 +406,11 @@ void MainWnd::OnToolsRecordStartavirecording()
theApp.sizeX,
theApp.sizeY,
( systemColorDepth == 32 ) ? 24 : 16,
60
60,
this->GetSafeHwnd()
);
if( !ret ) {
systemMessage( IDS_AVI_CANNOT_CREATE_VIDEO, "Cannot create video stream in AVI file." );
systemMessage( IDS_AVI_CANNOT_CREATE_VIDEO, "Cannot create video stream in AVI file. Make sure the selected codec supports input in RGB24 color space!" );
delete theApp.aviRecorder;
theApp.aviRecorder = NULL;
theApp.aviRecording = false;
@ -421,7 +422,8 @@ void MainWnd::OnToolsRecordStartavirecording()
ret = theApp.aviRecorder->CreateAudioStream(
2,
44100 / soundQuality,
16
16,
this->GetSafeHwnd()
);
if( !ret ) {
systemMessage( IDS_AVI_CANNOT_CREATE_AUDIO, "Cannot create audio stream in AVI file." );

View File

@ -1262,7 +1262,7 @@ void systemWriteDataToSoundBuffer()
}
}
if( theApp.aviRecording && theApp.aviRecorder ) {
if( theApp.aviRecording && theApp.aviRecorder && !soundOffFlag ) {
if( theApp.skipAudioFrames ) {
theApp.skipAudioFrames--;
} else {

View File

@ -2210,7 +2210,8 @@ BEGIN
IDS_OAL_NODEVICE "There are no sound devices present on this system."
IDS_OAL_NODLL "OpenAL32.dll could not be found on your system. Please install the runtime from http://openal.org"
IDS_AVI_CANNOT_CREATE_AVI "Cannot create AVI file."
IDS_AVI_CANNOT_CREATE_VIDEO "Cannot create video stream in AVI file."
IDS_AVI_CANNOT_CREATE_VIDEO
"Cannot create video stream in AVI file. Make sure the selected codec supports input in RGB24 color space!"
IDS_AVI_CANNOT_CREATE_AUDIO "Cannot create audio stream in AVI file."
IDS_AVI_CANNOT_WRITE_VIDEO "Cannot write video frame to AVI file."
IDS_AVI_CANNOT_WRITE_AUDIO "Cannot write audio frame to AVI file."