2 Convert avi movie files into swf.
3 As soon as there's an algorithm implemented for writing the
4 data directly to disk, this file should maybe go to ../src.
6 Part of the swftools package.
8 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
10 This file is distributed under the GPL, see file COPYING for details */
15 #include "../rfxswf.h"
22 char * outputfilename = "output.swf";
24 struct options_t options[] =
32 int args_callback_option(char*name,char*val)
34 if(!strcmp(name, "V")) {
35 printf("avi2swf - part of %s %s\n", PACKAGE, VERSION);
38 if(!strcmp(name, "o")) {
43 int args_callback_longoption(char*name,char*val)
45 return args_long2shortoption(options, name, val);
47 void args_callback_usage(char*name)
49 printf("\nUsage: %s file.swf\n", name);
50 printf("\t-h , --help\t\t Print help and exit\n");
51 printf("\t-o , --output=filename\t Specify output filename\n");
52 printf("\t-V , --version\t\t Print program version and exit\n");
55 int args_callback_command(char*name,char*val)
58 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
68 int main (int argc,char ** argv)
71 IAviReadStream* astream;
72 IAviReadStream* vstream;
75 memset(&swf, 0, sizeof(swf));
77 processargs(argc, argv);
81 player = CreateIAviReadFile(filename);
82 player->GetFileHeader(&head);
83 printf("fps: %d\n", 1000000/head.dwMicroSecPerFrame);
84 printf("frames: %d\n", head.dwTotalFrames);
85 printf("streams: %d\n", head.dwStreams);
86 printf("streams: %d\n", player->StreamCount());
87 printf("width: %d\n", head.dwWidth);
88 printf("height: %d\n", head.dwHeight);
90 astream = player->GetStream(0, AviStream::Audio);
91 vstream = player->GetStream(0, AviStream::Video);
93 vstream -> StartStreaming();
95 swf.frameRate = (int)(1000000.0/head.dwMicroSecPerFrame*256);
99 r.xmax = head.dwWidth*20;
100 r.ymax = head.dwHeight*20;
102 tag = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);
104 swf_SetU8(tag,0); //black
108 U8*newdata = (U8*)malloc((head.dwWidth+3) * head.dwHeight * 4);
113 if(vstream->ReadFrame()<0) {
117 printf("\rconvert frame %d",frame);
119 CImage*img = vstream->GetFrame();
121 U8* data = img->data();
122 int width = img->width();
123 int bpp = img->bpp();
124 int width4 = width*4;
125 int height = img->height();
134 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
135 swf_SetU16(tag, 1); //depth
138 /* todo: dynamically decide whether to generate jpeg/lossless
139 bitmaps, (using transparency to modify the previous
140 picture), and which jpeg compression depth to use.
141 (btw: Are there video frame transitions which can
142 reasonably approximated by shapes?)
147 tag = swf_InsertTag(tag, ST_DEFINEBITSLOSSLESS);
148 swf_SetU16(tag, frame*2);
149 for(y=0;y<height;y++) {
150 U8*nd = &newdata[width4*y];
152 for(x=0;x<width;x++) {
161 swf_SetLosslessBits(tag,width,height,newdata,BMF_32BIT);
164 tag = swf_InsertTag(tag, ST_DEFINEBITSJPEG2);
165 swf_SetU16(tag, frame*2);
166 JPEGBITS * jb = swf_SetJPEGBitsStart(tag,width,height,10);
167 for(y=0;y<height;y++) {
170 for(x=0;x<width;x++) {
177 swf_SetJPEGBitsLine(jb,newdata);
179 swf_SetJPEGBitsFinish(jb);
182 tag = swf_InsertTag(tag, ST_DEFINESHAPE);
184 rgb.b = rgb.g = rgb.r = 0xff;
185 ls = swf_ShapeAddLineStyle(s,20,&rgb);
186 swf_GetMatrix(NULL,&m);
190 fs = swf_ShapeAddBitmapFillStyle(s,&m,frame*2,0);
191 swf_SetU16(tag ,frame*2+1); // ID
198 swf_SetShapeStyles(tag,s);
199 swf_ShapeCountBits(s,NULL,NULL);
200 swf_SetShapeBits(tag,s);
202 swf_ShapeSetAll(tag,s,0,0,ls,fs,0);
204 swf_ShapeSetLine(tag,s,width*20,0);
205 swf_ShapeSetLine(tag,s,0,height*20);
206 swf_ShapeSetLine(tag,s,-width*20,0);
207 swf_ShapeSetLine(tag,s,0,-height*20);
208 swf_ShapeSetEnd(tag);
210 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
211 swf_ObjectPlace(tag,frame*2+1,1,0,0,0);
213 tag = swf_InsertTag(tag, ST_SHOWFRAME);
221 tag = swf_InsertTag(tag, ST_END);
223 f = open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC, 0644);
224 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
227 swf_FreeTags(&swf); // cleanup