Skip to content

Commit

Permalink
Merge pull request #249 from szlldm/resample_fps
Browse files Browse the repository at this point in the history
[resampleFps] add frame blending option
  • Loading branch information
eumagga0x2a authored Mar 9, 2021
2 parents 6bef0be + e8ff4f9 commit 485cdac
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ bool resampleFps::updateIncrement(void)
*/
const char *resampleFps::getConfiguration( void )
{
static char buf[100];
snprintf(buf,99," Resample to %2.2f fps",(double)configuration.newFpsNum/configuration.newFpsDen);
static char buf[256];
snprintf(buf,255," Resample %sto %2.2f fps",(configuration.blend ? "with blending ":""),(double)configuration.newFpsNum/configuration.newFpsDen);
return buf;
}
/**
Expand All @@ -123,6 +123,7 @@ resampleFps::resampleFps( ADM_coreVideoFilter *previous,CONFcouple *setup) :
configuration.mode=0;
configuration.newFpsNum=ADM_Fps1000FromUs(previous->getInfo()->frameIncrement);
configuration.newFpsDen=1000;
configuration.blend=false;
}
if(!frames[0]) frames[0]=new ADMImageDefault(info.width,info.height);
if(!frames[1]) frames[1]=new ADMImageDefault(info.width,info.height);
Expand Down Expand Up @@ -217,15 +218,56 @@ void resampleFps::setCoupledConf(CONFcouple *couples)
*fn=nextFrame++;
return true;
}
if (configuration.blend)
{
double diff1=(double)thisTime-double(frame1Dts);
double diff2=(double)thisTime-double(frame2Dts);
if(diff1<0) diff1=-diff1;
if(diff2<0) diff2=-diff2;
int bl1,bl2;
bl1 = round((diff2/(diff1+diff2)) * 256.0);
bl2 = round((diff1/(diff1+diff2)) * 256.0);
if (bl1==0)
image->duplicate(frames[1]);
else
if (bl2==0)
image->duplicate(frames[0]);
else
{
image->duplicate(frames[0]);
for (int p=0; p<3; p++)
{
int width=image->GetWidth((ADM_PLANE)p);
int height=image->GetHeight((ADM_PLANE)p);
int ipixel, bpixel;
int istride = image->GetPitch((ADM_PLANE)p);
int bstride = frames[1]->GetPitch((ADM_PLANE)p);
uint8_t * iptr = image->GetWritePtr((ADM_PLANE)p);
uint8_t * bptr = frames[1]->GetWritePtr((ADM_PLANE)p);
for (int y=0; y<height; y++)
{
for(int x=0; x<width; x++)
{
ipixel = iptr[x];
bpixel = bptr[x];
iptr[x] = (ipixel*bl1 + bpixel*bl2) >> 8;
}
iptr += istride;
bptr += bstride;
}
}
}
} else {
// In between, take closer
double diff1=(double)thisTime-double(frame1Dts);
double diff2=(double)thisTime-double(frame2Dts);
if(diff1<0) diff1=-diff1;
if(diff2<0) diff2=-diff2;
int index=1;
if(diff1<diff2) index=0;

image->duplicate(frames[index]);
double diff1=(double)thisTime-double(frame1Dts);
double diff2=(double)thisTime-double(frame2Dts);
if(diff1<0) diff1=-diff1;
if(diff2<0) diff2=-diff2;
int index=1;
if(diff1<diff2) index=0;

image->duplicate(frames[index]);
}
image->Pts=thisTime;
*fn=nextFrame++;
return true;
Expand Down Expand Up @@ -364,12 +406,13 @@ ADM_assert(nbPredefined == 6);

diaElemMenu mFps(&(configuration.mode), QT_TRANSLATE_NOOP("resampleFps","_Mode:"), 6,tFps);
diaElemFloat fps(&f,QT_TRANSLATE_NOOP("resampleFps","_New frame rate:"),1,200.);
diaElemToggle blendEn(&(configuration.blend),QT_TRANSLATE_NOOP("resampleFps","Blend frames"));

mFps.link(tFps+0,1,&fps); // only activate entry in custom mode

diaElem *elems[2]={&mFps,&fps};
diaElem *elems[3]={&mFps,&fps,&blendEn};

if( diaFactoryRun(QT_TRANSLATE_NOOP("resampleFps","Resample fps"),2,elems))
if( diaFactoryRun(QT_TRANSLATE_NOOP("resampleFps","Resample fps"),3,elems))
{
if(!configuration.mode) // Custom mode
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resampleFps{
confResampleFps{
uint32_t:mode
uint32_t:newFpsDen
uint32_t:newFpsNum
bool:blend
}
15 changes: 7 additions & 8 deletions avidemux_plugins/ADM_videoFilters6/resampleFps/confResampleFps.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Automatically generated, do not edit!
#ifndef ADM_confResampleFps_CONF_H
#define ADM_confResampleFps_CONF_H
// automatically generated by admSerialization.py do not edit
#include "string"
#pragma once
typedef struct {
uint32_t mode;
uint32_t newFpsDen;
uint32_t newFpsNum;
uint32_t mode;
uint32_t newFpsDen;
uint32_t newFpsNum;
bool blend;
}confResampleFps;
#endif //confResampleFps
//EOF
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Automatically generated, do not edit!
const ADM_paramList confResampleFps_param[]={
{"mode",offsetof( confResampleFps,mode),"uint32_t",ADM_param_uint32_t},
{"newFpsDen",offsetof( confResampleFps,newFpsDen),"uint32_t",ADM_param_uint32_t},
{"newFpsNum",offsetof( confResampleFps,newFpsNum),"uint32_t",ADM_param_uint32_t},
// automatically generated by admSerialization.py, do not edit!
extern const ADM_paramList confResampleFps_param[]={
{"mode",offsetof(confResampleFps,mode),"uint32_t",ADM_param_uint32_t},
{"newFpsDen",offsetof(confResampleFps,newFpsDen),"uint32_t",ADM_param_uint32_t},
{"newFpsNum",offsetof(confResampleFps,newFpsNum),"uint32_t",ADM_param_uint32_t},
{"blend",offsetof(confResampleFps,blend),"bool",ADM_param_bool},
{NULL,0,NULL}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// automatically generated by admSerialization.py, do not edit!
#include "ADM_default.h"
#include "ADM_paramList.h"
#include "ADM_coreJson.h"
#include "confResampleFps.h"
bool confResampleFps_jserialize(const char *file, const confResampleFps *key){
admJson json;
json.addUint32("mode",key->mode);
json.addUint32("newFpsDen",key->newFpsDen);
json.addUint32("newFpsNum",key->newFpsNum);
json.addBool("blend",key->blend);
return json.dumpToFile(file);
};
bool confResampleFps_jdeserialize(const char *file, const ADM_paramList *tmpl,confResampleFps *key){
admJsonToCouple json;
CONFcouple *c=json.readFromFile(file);
if(!c) {ADM_error("Cannot read json file");return false;}
bool r= ADM_paramLoadPartial(c,tmpl,key);
delete c;
return r;
};

0 comments on commit 485cdac

Please sign in to comment.