X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=avi2swf%2Fv2swf.c;h=312fcf7b728c2e2a859d0866f6011fcfae07ce60;hp=c56ff4b6237219b12badb7b92e35453ff83c68ef;hb=26af26a251a58f33b295a0ae36ebd27ec167dc88;hpb=e5b314a4315a7d7e0b7bda60102c50ad277c2f68 diff --git a/avi2swf/v2swf.c b/avi2swf/v2swf.c index c56ff4b..312fcf7 100644 --- a/avi2swf/v2swf.c +++ b/avi2swf/v2swf.c @@ -60,6 +60,7 @@ typedef struct _v2swf_internal_t float fpspos; int bitrate; + int samplerate; int finished; int keyframe; @@ -118,6 +119,12 @@ static void msg(char*format, ...) fflush(stdout); } +extern int swf_mp3_in_samplerate; +extern int swf_mp3_out_samplerate; +extern int swf_mp3_channels; +extern int swf_mp3_bitrate; + + static void writeShape(v2swf_internal_t*i, int id, int gfxid, int width, int height) { RGBA rgb; @@ -161,7 +168,7 @@ static void writeShape(v2swf_internal_t*i, int id, int gfxid, int width, int hei static int getSamples(videoreader_t*video, S16*data, int len, double speedup) { double pos = 0; - double ratio = video->rate * speedup / 44100.0; + double ratio = (double) video->rate * speedup / swf_mp3_in_samplerate; int rlen = (int)(len * ratio); int t; S16 tmp[576*32]; @@ -180,7 +187,7 @@ static int getSamples(videoreader_t*video, S16*data, int len, double speedup) tmp[t] = a/video->channels; } - /* down/up-sample to 44khz */ + /* down/up-sample to the desired input samplerate (swf_mp3_in_samplerate) */ for(t=0;tvideo->channels<=0 || i->video->rate<=0) return; /* no sound in video */ - blocksize = 576; /* 11khz samples per mp3 block */ - blockspersecond = 11025.0/blocksize; + blocksize = (i->samplerate > 22050) ? 1152 : 576; + blockspersecond = ((double)i->samplerate)/blocksize; /* notice: for framerates greater than about 35, audio starts getting choppy. */ framespersecond = i->framerate; @@ -221,6 +225,12 @@ static void writeAudioForOneFrame(v2swf_internal_t* i) msg("samplesperblock: %f", samplesperblock); if(!i->soundstreamhead) { + swf_mp3_out_samplerate = i->samplerate; + /* The pre-processing of sound samples in getSamples(..) above + re-samples the sound to swf_mp3_in_samplerate. It is best to + simply make it the original samplerate: */ + swf_mp3_in_samplerate = i->video->rate; + /* first run - initialize */ swf_mp3_channels = 1;//i->video->channels; swf_mp3_bitrate = i->bitrate; @@ -257,7 +267,7 @@ static void writeAudioForOneFrame(v2swf_internal_t* i) /* write num frames, max 1 block */ for(pos=0;posvideo, block1, 576*4, speedup)) { /* 4 = 44100/11025 */ + if(!getSamples(i->video, block1, blocksize * (double)swf_mp3_in_samplerate/swf_mp3_out_samplerate, speedup)) { i->video->rate = i->video->channels = 0; //end of soundtrack return; } @@ -781,6 +791,7 @@ int v2swf_init(v2swf_t*v2swf, videoreader_t * video) i->keyframe_interval = 8; i->quality = 20; i->scale = 65536; + i->samplerate = 11025; i->prescale = 0; i->head_done = 0; i->diffmode = DIFFMODE_QMEAN; @@ -875,6 +886,8 @@ void v2swf_setparameter(v2swf_t*v2swf, char*name, char*value) i->blockdiff = atoi(value); } else if(!strcmp(name, "fixheader")) { i->fixheader = atoi(value); + } else if(!strcmp(name, "samplerate")) { + i->samplerate = atoi(value); } else if(!strcmp(name, "framerate")) { i->framerate = atof(value); i->fpsratio = i->framerate / i->video->fps;