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[] =
29 int args_callback_option(char*name,char*val)
31 if(!strcmp(name, "V")) {
32 printf("wav2swf - part of %s %s\n", PACKAGE, VERSION);
35 else if(!strcmp(name, "o")) {
39 else if(!strcmp(name, "v")) {
44 printf("Unknown option: -%s\n", name);
49 int args_callback_longoption(char*name,char*val)
51 return args_long2shortoption(options, name, val);
53 void args_callback_usage(char*name)
55 printf("Usage: %s [-o filename] file.wav\n", name);
56 printf("\t-v , --verbose\t\t\t Be more verbose\n");
57 printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n");
58 printf("\t-V , --version\t\t\t Print program version and exit\n");
60 int args_callback_command(char*name,char*val)
63 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
70 int main (int argc,char ** argv)
74 S32 width=300,height = 300;
85 processargs(argc, argv);
86 initLog(0,-1,0,0,-1,verbose);
88 if(!readWAV(filename, &wav))
90 logf("<fatal> Error reading %s", filename);
93 convertWAV2mono(&wav,&wav2, 44100);
95 //printWAVInfo(&wav2);
96 samples = (U16*)wav2.data;
97 numsamples = wav2.size/2;
99 memset(&swf,0x00,sizeof(SWF));
102 swf.frameRate = 11025*256/(blocksize);
104 swf.movieSize.xmax = 20*width;
105 swf.movieSize.ymax = 20*height;
107 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
112 swf_SetRGB(tag,&rgb);
114 tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD);
115 swf_SetSoundStreamHead(tag, blocksize);
117 logf("<notice> %d blocks", numsamples/(blocksize*2));
118 for(t=0;t<numsamples/(blocksize*2);t++) {
121 tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
122 logf("<notice> Writing block %d", t);
123 block1 = &samples[t*2*blocksize];
124 swf_SetSoundStreamBlock(tag, block1, 1);
125 tag = swf_InsertTag(tag, ST_SHOWFRAME);
128 f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
129 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");