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/args.h"
17 char * outputname = "output.swf";
20 struct options_t options[] =
28 int args_callback_option(char*name,char*val)
30 if(!strcmp(name, "V")) {
31 printf("wav2swf - part of %s %s\n", PACKAGE, VERSION);
34 else if(!strcmp(name, "o")) {
38 else if(!strcmp(name, "v")) {
43 printf("Unknown option: -%s\n", name);
48 int args_callback_longoption(char*name,char*val)
50 return args_long2shortoption(options, name, val);
52 void args_callback_usage(char*name)
54 printf("Usage: %s [-o filename] file.wav\n", name);
55 printf("\t-v , --verbose\t\t\t Be more verbose\n");
56 printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n");
57 printf("\t-V , --version\t\t Print program version and exit\n");
59 int args_callback_command(char*name,char*val)
62 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
69 int main (int argc,char ** argv)
73 S32 width=300,height = 300;
84 processargs(argc, argv);
85 initLog(0,-1,0,0,-1,verbose);
87 if(!readWAV(filename, &wav))
89 logf("<fatal> Error reading %s", filename);
92 convertWAV2mono(&wav,&wav2, 44100);
95 samples = (U16*)wav2.data;
96 numsamples = wav2.size/2;
98 /* the following is a big hack to prevent against
99 periods of total silence- these get written as
100 blocks of length 0 by bladeenc, which causes
101 the flashplayer to crash */
103 for(t=0;t<wav2.size/2;t+=2)
104 wav2.data[t]^=(t&2)<<1;
106 memset(&swf,0x00,sizeof(SWF));
109 swf.frameRate = 44100*256/(blocksize*2);
111 swf.movieSize.xmax = 20*width;
112 swf.movieSize.ymax = 20*height;
114 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
119 swf_SetRGB(tag,&rgb);
121 tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD);
122 swf_SetSoundStreamHead(tag, blocksize);
124 logf("<notice> %d blocks", numsamples/(blocksize*2));
125 for(t=0;t<numsamples/(blocksize*2);t++) {
129 tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
130 logf("<notice> Writing block %d", t);
131 block1 = &samples[(t*2+0)*blocksize];
132 block2 = &samples[(t*2+1)*blocksize];
133 swf_SetSoundStreamBlock(tag, block1, blocksize,1);
134 swf_SetSoundStreamBlock(tag, block2, blocksize,0);
135 tag = swf_InsertTag(tag, ST_SHOWFRAME);
138 f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
139 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");