added support for video compression (no support for YUV color space)
git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@214 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
547772d1f6
commit
2289d47912
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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." );
|
||||
|
|
|
@ -1262,7 +1262,7 @@ void systemWriteDataToSoundBuffer()
|
|||
}
|
||||
}
|
||||
|
||||
if( theApp.aviRecording && theApp.aviRecorder ) {
|
||||
if( theApp.aviRecording && theApp.aviRecorder && !soundOffFlag ) {
|
||||
if( theApp.skipAudioFrames ) {
|
||||
theApp.skipAudioFrames--;
|
||||
} else {
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Reference in New Issue