X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fexample%2Favi2swf.cc;h=a4912f6327977d646b6c14cfb0791b546d665c2f;hb=47df0688e74d14cb1aaff3fca3ac51356d632dd2;hp=11d812b23f5f8123a6ac7d4e7d493f4746e7d192;hpb=74e953401e1f5b89e3fa355413f0ec92744d78c6;p=swftools.git diff --git a/lib/example/avi2swf.cc b/lib/example/avi2swf.cc index 11d812b..a4912f6 100644 --- a/lib/example/avi2swf.cc +++ b/lib/example/avi2swf.cc @@ -20,11 +20,15 @@ extern "C" { char * filename = 0; char * outputfilename = "output.swf"; +unsigned int lastframe = 0xffffffff; + +int jpeg_quality = 40; struct options_t options[] = { {"v","verbose"}, {"o","output"}, + {"e","end"}, {"V","version"}, {0,0} }; @@ -34,11 +38,15 @@ int args_callback_option(char*name,char*val) if(!strcmp(name, "V")) { printf("avi2swf - part of %s %s\n", PACKAGE, VERSION); exit(0); - } else - if(!strcmp(name, "o")) { + } + else if(!strcmp(name, "o")) { outputfilename = val; return 1; } + else if(!strcmp(name, "e")) { + lastframe = atoi(val); + return 1; + } } int args_callback_longoption(char*name,char*val) { @@ -49,6 +57,7 @@ void args_callback_usage(char*name) printf("\nUsage: %s file.swf\n", name); printf("\t-h , --help\t\t Print help and exit\n"); printf("\t-o , --output=filename\t Specify output filename\n"); + printf("\t-e , --end=frame\t\t Last frame to encode\n"); printf("\t-V , --version\t\t Print program version and exit\n"); exit(0); } @@ -66,13 +75,12 @@ SWF swf; TAG*tag; int main (int argc,char ** argv) -{ int f; +{ int file; IAviReadFile* player; IAviReadStream* astream; IAviReadStream* vstream; MainAVIHeader head; SRECT r; - memset(&swf, 0, sizeof(swf)); processargs(argc, argv); if(!filename) @@ -92,23 +100,36 @@ int main (int argc,char ** argv) vstream -> StartStreaming(); + file = open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC, 0644); + + memset(&swf, 0, sizeof(swf)); swf.frameRate = (int)(1000000.0/head.dwMicroSecPerFrame*256); swf.fileVersion = 4; + swf.fileSize = 0x0fffffff; r.xmin = 0; r.ymin = 0; r.xmax = head.dwWidth*20; r.ymax = head.dwHeight*20; swf.movieSize = r; + + swf_WriteHeader(file, &swf); + tag = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR); - swf.firstTag = tag; swf_SetU8(tag,0); //black swf_SetU8(tag,0); swf_SetU8(tag,0); + swf_WriteTag(file, tag); + swf_DeleteTag(tag); U8*newdata = (U8*)malloc((head.dwWidth+3) * head.dwHeight * 4); int frame = 0; + int lastsize = (head.dwWidth+3) * head.dwHeight * 4; + U8* lastdata = (U8*)malloc(lastsize); + U8* data; + memset(lastdata,0, lastsize); + while(1) { if(vstream->ReadFrame()<0) { printf("\n"); @@ -118,7 +139,7 @@ int main (int argc,char ** argv) fflush(stdout); CImage*img = vstream->GetFrame(); img->ToRGB(); - U8* data = img->data(); + data = img->data(); int width = img->width(); int bpp = img->bpp(); int width4 = width*4; @@ -131,100 +152,151 @@ int main (int argc,char ** argv) RGBA rgb; if(frame!=0) { - tag = swf_InsertTag(tag, ST_REMOVEOBJECT2); + tag = swf_InsertTag(NULL, ST_REMOVEOBJECT2); swf_SetU16(tag, 1); //depth + swf_WriteTag(file, tag); + swf_DeleteTag(tag); } /* todo: dynamically decide whether to generate jpeg/lossless bitmaps, (using transparency to modify the previous picture), and which jpeg compression depth to use. (btw: Are there video frame transitions which can - reasonably approximated by shapes?) + reasonably be approximated by shapes?) */ int type = 1; + int rel = 0; if(type == 0) { - tag = swf_InsertTag(tag, ST_DEFINEBITSLOSSLESS); + tag = swf_InsertTag(NULL, ST_DEFINEBITSLOSSLESS); swf_SetU16(tag, frame*2); + U8*mylastdata = lastdata; for(y=0;yat(y); + U8*mydata = img->at(y); + if(!rel) for(x=0;x64) + { + nd[3]=mydata[0]; + nd[2]=mydata[1]; + nd[1]=mydata[2]; + nd[0]=255; + } else { + nd[3]=0; + nd[2]=0; + nd[1]=0; + nd[0]=0; + } + mylastdata[2] = mydata[2]; + mylastdata[1] = mydata[1]; + mylastdata[0] = mydata[0]; + nd+=4; + mydata+=3; + mylastdata+=3; } } swf_SetLosslessBits(tag,width,height,newdata,BMF_32BIT); + swf_WriteTag(file, tag); + swf_DeleteTag(tag); } else if(type == 1) { - tag = swf_InsertTag(tag, ST_DEFINEBITSJPEG2); + tag = swf_InsertTag(NULL, ST_DEFINEBITSJPEG2); swf_SetU16(tag, frame*2); - JPEGBITS * jb = swf_SetJPEGBitsStart(tag,width,height,10); + JPEGBITS * jb = swf_SetJPEGBitsStart(tag,width,height,jpeg_quality); + U8*mylastdata = lastdata; for(y=0;yat(y); + U8*mydata = img->at(y); for(x=0;x