along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+#include "videoreader.h"
#ifdef WIN32
#include <windows.h>
#include <vfw.h>
#include <stdlib.h>
#include <stdio.h>
-#include "videoreader.h"
typedef struct _videoreader_vfw_internal {
//video:
} videoreader_vfw_internal_t;
+static int avifile_initialized = 0;
+
+#define _TRACE_ {printf("%s: %d (%s)\n",__FILE__,__LINE__,__func__);fflush(stdout);}
+
bool videoreader_vfw_eof(videoreader_t* vr)
{
videoreader_vfw_internal_t* i = (videoreader_vfw_internal_t*)vr->internal;
bi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(i->getframe, i->video_pos);
i->video_pos++;
+ vr->frame++;
if(!bi) {
fprintf(stderr, "AVIStreamGetFrame failed\n");
return 0;
}
- printf("%dx%d:%d\n", bi->biWidth, bi->biHeight, bi->biBitCount);
if(!bitmap_to_rgba(bi, buffer, i->width, i->height)) {
fprintf(stderr, "couldn't convert bitmap to RGBA.\n");
AVIStreamRelease(i->as); i->vs = 0;
}
AVIFileRelease(i->avifile); i->avifile = 0;
- AVIFileExit();
+
+ AVIFileExit(); avifile_initialized=0;
free(vr->internal); vr->internal = 0;
}
vr->close = videoreader_vfw_close;
vr->setparameter = videoreader_vfw_setparameter;
- AVIFileInit();
+ if(!avifile_initialized) {
+ AVIFileInit();
+ }
if(AVIFileOpen(&i->avifile, filename, OF_SHARE_DENY_WRITE, 0)) {
fprintf(stderr, "Couldn't open %s\n", filename);
return -1;
/* calculate framerate */
i->fps = (double)info.dwRate/(double)info.dwScale;
- unsigned int t;
+ unsigned int t=0;
while(t<info.dwStreams) {
PAVISTREAM stream;
if(AVIFileGetStream(i->avifile, &stream, streamtypeANY, t) != AVIERR_OK || !stream)
/* video stream */
BITMAPINFOHEADER bitmap;
- LONG size = sizeof(i->bitmap);
- AVIStreamReadFormat(i->vs, 0, &bitmap, &size);
+ LONG size = sizeof(bitmap);
+ AVIStreamReadFormat(stream, 0, &bitmap, &size);
- if(i->bitmap.biCompression == 0/*RGB*/) {
+ if(1) {
i->bitmap = bitmap;
i->vs = stream;
i->width = bitmap.biWidth;
i->height = bitmap.biHeight;
+ } else {
+ fprintf(stderr, "Ignoring video stream: %dx%d compression=%d planes=%d\n",
+ bitmap.biWidth, bitmap.biHeight,
+ bitmap.biCompression,bitmap.biPlanes);
}
}
else if (streaminfo.fccType == streamtypeAUDIO) {
/* audio stream */
WAVEFORMATEX waveformat;
- LONG size = sizeof(i->waveformat);
- AVIStreamReadFormat(i->as, 0, &waveformat, &size);
+ LONG size = sizeof(waveformat);
+ AVIStreamReadFormat(stream, 0, &waveformat, &size);
- if(i->waveformat.wBitsPerSample == 16 || i->waveformat.wBitsPerSample == 8) {
+ if(waveformat.wBitsPerSample == 16 ||
+ waveformat.wBitsPerSample == 8 ||
+ waveformat.wBitsPerSample == 1
+ ) {
i->waveformat = waveformat;
i->as = stream;
- i->channels = i->waveformat.nChannels;
- i->samplerate = i->waveformat.nSamplesPerSec;
+ i->channels = waveformat.nChannels;
+ i->samplerate = waveformat.nSamplesPerSec;
+ } else {
+ fprintf(stderr, "Ignoring audio stream: bitspersample=%d\n", waveformat.wBitsPerSample);
}
}
+ t++;
}
if(i->vs) {
i->getframe = AVIStreamGetFrameOpen(i->vs, 0);
if(!i->getframe) {
+ fprintf(stderr, "Couldn't initialize AVIStream for %s- codec missing?\n", filename);
return -1;
}