X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=avi2swf%2Fvideoreader_vfw.cc;h=a5d2483322ebb7f6d140746ac46157986a086cf4;hb=f6a3cc71c731c0144b1e137d1bdbe24afdc1c755;hp=2da5acdb239e3b64b8828c75e3ef1e460da7d19d;hpb=359c111aa91dbbe9245a1bba2413692c63afdf73;p=swftools.git diff --git a/avi2swf/videoreader_vfw.cc b/avi2swf/videoreader_vfw.cc index 2da5acd..a5d2483 100644 --- a/avi2swf/videoreader_vfw.cc +++ b/avi2swf/videoreader_vfw.cc @@ -19,12 +19,12 @@ 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 #include #include #include -#include "videoreader.h" typedef struct _videoreader_vfw_internal { //video: @@ -49,15 +49,21 @@ typedef struct _videoreader_vfw_internal { int samplerate; int channels; + int flip; } videoreader_vfw_internal_t; -bool videoreader_vfw_eof(videoreader_t* vr) +static int avifile_initialized = 0; +static int verbose; + +#define _TRACE_ {printf("vfw: %s: %d (%s)\n",__FILE__,__LINE__,__func__);fflush(stdout);} + +static bool videoreader_vfw_eof(videoreader_t* vr) { videoreader_vfw_internal_t* i = (videoreader_vfw_internal_t*)vr->internal; return (i->video_pos >= i->video_end); } -static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width, const int dest_height) +static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width, const int dest_height, int flip) { UCHAR*data = (UCHAR*)(bi+1); // actual bitmap data starts after the header @@ -83,10 +89,19 @@ static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width int bytesperpixel = ((bi->biWidth*bi->biBitCount)+7)&~7; int linex = ((bytesperpixel/8)+3)&~3; memset(dest, 255, dest_width*dest_height*4);//pre-fill alpha channel + + const int starty = flip? 0 : dest_height-1; + const int endy = flip? dest_height : -1; + const int yinc = flip? 1 : -1; + + if(verbose) { + printf("vfw: Convering scanlines %d to %d from bpp %d, %d stepping, flip=%d\n", starty, endy, bi->biBitCount, yinc, flip); + } + if(bi->biBitCount==1) { - int y; UCHAR*img = data; - for(y=0;ybiBitCount==4) { - int y; UCHAR*img = &data[bi->biClrUsed*4]; UCHAR*pal = data; - for(y=0;ybiBitCount==8) { - int y; UCHAR*img = &data[bi->biClrUsed*4]; UCHAR*pal = data; - for(y=0;ybiBitCount==24) { UCHAR*img = data; int y; - for(y=0;ybiBitCount==32) { UCHAR*img = data; int y; - for(y=0;yinternal; @@ -158,14 +173,14 @@ int videoreader_vfw_getimage(videoreader_t* vr, void*buffer) 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)) { + if(!bitmap_to_rgba(bi, buffer, i->width, i->height, i->flip)) { fprintf(stderr, "couldn't convert bitmap to RGBA.\n"); return 0; } @@ -181,7 +196,7 @@ static int readAudioBlock(videoreader_vfw_internal_t* i, void*buf, int len) return bytes; } -int videoreader_vfw_getsamples(videoreader_t* vr, void*buf, int num) +static int videoreader_vfw_getsamples(videoreader_t* vr, void*buf, int num) { videoreader_vfw_internal_t* i = (videoreader_vfw_internal_t*)vr->internal; @@ -211,7 +226,7 @@ int videoreader_vfw_getsamples(videoreader_t* vr, void*buf, int num) } } -void videoreader_vfw_close(videoreader_t* vr) +static void videoreader_vfw_close(videoreader_t* vr) { videoreader_vfw_internal_t* i = (videoreader_vfw_internal_t*)vr->internal; @@ -229,9 +244,15 @@ void videoreader_vfw_close(videoreader_t* vr) free(vr->internal); vr->internal = 0; } -void videoreader_vfw_setparameter(videoreader_t* vr, char*name, char*value) {} - -static int avifile_initialized = 0; +static void videoreader_vfw_setparameter(videoreader_t*vr, char*name, char*value) +{ + videoreader_vfw_internal_t* i = (videoreader_vfw_internal_t*)vr->internal; + if(!strcmp(name, "flip")) { + i->flip = atoi(value); + } else if(!strcmp(name, "verbose")) { + verbose = atoi(value); + } +} int videoreader_vfw_open(videoreader_t* vr, char* filename) { @@ -264,7 +285,11 @@ int videoreader_vfw_open(videoreader_t* vr, char* filename) /* calculate framerate */ i->fps = (double)info.dwRate/(double)info.dwScale; - unsigned int t; + if(verbose) { + printf("vfw: file %s has %f fps, and %d streams\n", i->fps, info.dwStreams); + } + + unsigned int t=0; while(tavifile, &stream, streamtypeANY, t) != AVIERR_OK || !stream) @@ -277,33 +302,46 @@ int videoreader_vfw_open(videoreader_t* vr, char* filename) /* 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) { + if(verbose) { + printf("vfw: video stream: %dx%d, %.2f\n", i->width, i->height, i->fps); + } vr->width = i->width; vr->height = i->height; vr->fps = i->fps; @@ -311,6 +349,9 @@ int videoreader_vfw_open(videoreader_t* vr, char* filename) fprintf(stderr, "AVIReader: Warning: No video stream\n"); } if(i->as) { + if(verbose) { + printf("vfw: audio stream: %d channels, %d samples/sec", i->channels, i->samplerate); + } vr->channels = i->channels; vr->samplerate = i->samplerate; } else { @@ -319,6 +360,7 @@ int videoreader_vfw_open(videoreader_t* vr, char* filename) i->getframe = AVIStreamGetFrameOpen(i->vs, 0); if(!i->getframe) { + fprintf(stderr, "Couldn't initialize AVIStream for %s- codec missing?\n", filename); return -1; }