2 Allows to extract parts of the swf into a new file.
4 Part of the swftools package.
6 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
8 This file is distributed under the GPL, see file COPYING for details */
12 #include "../lib/rfxswf.h"
13 #include "../lib/log.h"
14 #include "../lib/args.h"
18 char * outputname = "output.swf";
21 struct options_t options[] =
33 static int definesound = 0;
34 static int framerate = 0;
36 int args_callback_option(char*name,char*val)
38 if(!strcmp(name, "V")) {
39 printf("wav2swf - part of %s %s\n", PACKAGE, VERSION);
42 else if(!strcmp(name, "o")) {
46 else if(!strcmp(name, "d")) {
50 else if(!strcmp(name, "l")) {
54 else if(!strcmp(name, "v")) {
58 else if(!strcmp(name, "r")) {
60 sscanf(val, "%f", &f);
65 printf("Unknown option: -%s\n", name);
70 int args_callback_longoption(char*name,char*val)
72 return args_long2shortoption(options, name, val);
74 void args_callback_usage(char*name)
76 printf("Usage: %s [-o filename] file.wav\n", name);
77 printf("\t-v , --verbose\t\t\t Be more verbose\n");
78 printf("\t-d , --definesound\t\t\t Generate a DefineSound tag instead of streaming sound\n");
79 printf("\t-l , --loop n\t\t\t Loop sound n times (implies -d)\n");
80 printf("\t-r , --framerate fps\t\t\t Set framerate to fps frames per seond\n");
81 printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n");
82 printf("\t-V , --version\t\t\t Print program version and exit\n");
84 int args_callback_command(char*name,char*val)
87 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
94 int main (int argc,char ** argv)
99 S32 width=300,height = 300;
107 float blockspersecond;
108 float framespersecond;
109 float framesperblock;
114 processargs(argc, argv);
116 if(!definesound && framerate) {
117 printf("Warning! The -r option is experimental and won't work without -d\n");
121 blockspersecond = 11025.0/blocksize;
122 framespersecond = blockspersecond;
124 framespersecond = framerate/256.0;
125 framesperblock = framespersecond/blockspersecond;
127 initLog(0,-1,0,0,-1,verbose);
129 if(!readWAV(filename, &wav))
131 logf("<fatal> Error reading %s", filename);
134 convertWAV2mono(&wav,&wav2, 44100);
135 //printWAVInfo(&wav);
136 //printWAVInfo(&wav2);
137 samples = (U16*)wav2.data;
138 numsamples = wav2.size/2;
140 memset(&swf,0x00,sizeof(SWF));
143 swf.frameRate = (int)(framespersecond*256);
145 swf.movieSize.xmax = 20*width;
146 swf.movieSize.ymax = 20*height;
148 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
153 swf_SetRGB(tag,&rgb);
157 tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD);
158 swf_SetSoundStreamHead(tag, blocksize);
160 logf("<notice> %d blocks", numsamples/(blocksize*2));
161 for(t=0;t<numsamples/(blocksize*2);t++) {
163 int oldframe, newframe;
165 tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
166 logf("<notice> Writing block %d", t);
167 block1 = &samples[t*2*blocksize];
168 swf_SetSoundStreamBlock(tag, block1, 1);
170 oldframe = (int)framepos;
171 framepos += framesperblock;
172 newframe = (int)framepos;
173 for(s=oldframe;s<newframe;s++)
174 tag = swf_InsertTag(tag, ST_SHOWFRAME);
176 tag = swf_InsertTag(tag, ST_END);
179 tag = swf_InsertTag(tag, ST_DEFINESOUND);
180 swf_SetU16(tag, 24); //id
181 swf_SetSoundDefine(tag, samples, numsamples);
182 tag = swf_InsertTag(tag, ST_STARTSOUND);
183 swf_SetU16(tag, 24); //id
184 memset(&info, 0, sizeof(info));
186 swf_SetSoundInfo(tag, &info);
187 tag = swf_InsertTag(tag, ST_SHOWFRAME);
188 tag = swf_InsertTag(tag, ST_END);
191 f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
192 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");