X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=avi2swf%2Fv2swf.c;h=0eb78f6e6b88db89834f72977d30a7e78707cd43;hb=3cd41fca50349a2e03d5bca74fc5b38d76a4238a;hp=db32c0c762aae0962ed7acdf4336a75c30bbc9df;hpb=5f258d914bd49400899ad22d4f043fb2de278b6b;p=swftools.git diff --git a/avi2swf/v2swf.c b/avi2swf/v2swf.c index db32c0c..0eb78f6 100644 --- a/avi2swf/v2swf.c +++ b/avi2swf/v2swf.c @@ -70,6 +70,8 @@ typedef struct _v2swf_internal_t int keyframe; int showframe; + int skipframes; + float samplepos; float framesamplepos; int samplewritepos; @@ -77,11 +79,15 @@ typedef struct _v2swf_internal_t int soundstreamhead; int seek; + int numframes; + double audio_fix; int fixheader; int prescale; int scale; + + int add_cut; int domotion; @@ -180,9 +186,10 @@ static int getSamples(videoreader_t*video, S16*data, int len, double speedup) int r = /*resampled len */ rlen * /* s16_le */ 2 * video->channels; - int l; + int l = 0; memset(tmp, 0, sizeof(tmp)); - l = videoreader_getsamples(video, tmp, r); + if(r>0) + l = videoreader_getsamples(video, tmp, r); if(l <= 0) { return 0; } @@ -414,8 +421,22 @@ static void finish(v2swf_internal_t*i) if(!i->finished) { msg("write endtag\n", i->finished); + if(i->add_cut) { + swf_ResetTag(i->tag, ST_SHOWFRAME); + i->filesize += swf_WriteTag2(&i->out, i->tag); + + swf_ResetTag(i->tag, ST_REMOVEOBJECT2); + swf_SetU16(i->tag, 1); //depth + i->filesize += swf_WriteTag2(&i->out, i->tag); + + swf_ResetTag(i->tag, ST_DOACTION); + swf_SetU16(i->tag, 0x0007); + i->filesize += swf_WriteTag2(&i->out, i->tag); + } + swf_ResetTag(i->tag, ST_END); i->filesize += swf_WriteTag2(&i->out, i->tag); + i->out.finish(&i->out); if(i->version>=6) { @@ -602,6 +623,21 @@ static int writeAudioOnly(v2swf_internal_t*i) return 1; } +static int getframe(v2swf_internal_t*i) +{ + if(!i->skipframes) + return videoreader_getimage(i->video, i->vrbuffer); + else { + int t; + for(t=0;tskipframes;t++) { + int ret = videoreader_getimage(i->video, i->vrbuffer); + if(!ret) + return 0; + } + return 1; + } +} + static int encodeoneframe(v2swf_internal_t*i) { videoreader_t*video = i->video; @@ -619,11 +655,11 @@ static int encodeoneframe(v2swf_internal_t*i) return writeAudioOnly(i); } - if(!videoreader_getimage(i->video, i->vrbuffer)) + if(!getframe(i) || (i->numframes && i->frames==i->numframes)) { i->video_eof = 1; msg("videoreader returned eof\n"); - if(i->audio_eof) { + if(i->audio_eof || (i->numframes && i->frames==i->numframes)) { finish(i); return 0; } else { @@ -814,6 +850,15 @@ static int encodeoneframe(v2swf_internal_t*i) return 1; } +static void init_fps(v2swf_internal_t*i) +{ + int oldframerate = i->framerate; + i->framerate = i->video->fps / i->skipframes; + i->video_fps = ((int)(i->framerate*256))/256.0; + if(oldframerate) + msg("setting new framerate to %f\n", i->framerate); +} + int v2swf_init(v2swf_t*v2swf, videoreader_t * video) { int ret = 0; @@ -827,21 +872,26 @@ int v2swf_init(v2swf_t*v2swf, videoreader_t * video) ringbuffer_init(&i->r); + i->skipframes = 1; + i->framerate = 0; + i->video = video; + init_fps(i); + msg("video: %dx%d, fps %f\n", video->width, video->height, video->fps); - i->video = video; - i->video_fps = ((int)(video->fps*256))/256.0; i->blockdiff = 64; i->keyframe_interval = 8; i->quality = 20; i->scale = 65536; + i->add_cut = 1; i->samplerate = 11025; i->prescale = 0; + i->numframes= 0; + i->skipframes = 0; i->head_done = 0; i->diffmode = DIFFMODE_QMEAN; i->audio_fix = 1.0; i->fixheader = 0; - i->framerate = i->video_fps; i->fpsratio = 1.00000000000; i->fpspos = 0.0; i->bitrate = 32; @@ -916,12 +966,19 @@ void v2swf_setparameter(v2swf_t*v2swf, char*name, char*value) i->version = atoi(value); } else if(!strcmp(name, "audiosync")) { i->audio_fix = (int)(atof(value)); + } else if(!strcmp(name, "addcut")) { + i->add_cut = atoi(value); } else if(!strcmp(name, "scale")) { i->scale = (int)(atof(value)*65536); } else if(!strcmp(name, "scale65536")) { i->scale = atoi(value); } else if(!strcmp(name, "quality")) { i->quality = atoi(value); + } else if(!strcmp(name, "skipframes")) { + i->skipframes = atoi(value); + init_fps(i); + } else if(!strcmp(name, "numframes")) { + i->numframes = atoi(value); } else if(!strcmp(name, "motioncompensation")) { i->domotion = atoi(value); } else if(!strcmp(name, "prescale")) {