Printable Version of Topic
Click here to view this topic in its original format
Unofficial VirtualDub Support Forums > VirtualDub Filters and Filter Development > Prefetching Multiple Source Frames In Vdub.


Posted by: diablo23q Jul 18 2011, 01:32 PM
Hi everyone,

Need some help. Could someone explain me how to deal with prefetchProc2 and mpInputFrames/mpOutputFrames arrays? A small example would be great.
Thank you.

Posted by: phaeron Jul 24 2011, 02:33 AM
Use the prefetcher object passed to prefetchProc2 to request the source frames that you want.

In runProc, the requested source frames appear in the order you requested them in the mpInputFrames array. Process those into the buffer pointed to by mpOutputFrames[0].

Posted by: diablo23q Jul 24 2011, 02:44 PM
So prefetchProc2 will simply look like:
CODE
bool prefetchProc2(const VDXFilterActivation *fa, const VDXFilterFunctions *ff, sint64 frame, IVDXVideoPrefetcher *prefetcher) {
prefetcher->PrefetchFrame(0, frame, 1);
prefetcher->PrefetchFrame(0, frame + 1, 2);
return true;
}

And in runProc I can get this frames via fa->mpSourceFrames[0] and fa->mpSourceFrames[1] ?

Posted by: phaeron Jul 31 2011, 11:50 PM
Yup. You don't need to set the cookie value to 1 and 2 respectively, though, if you're not actually going to use it. No matter what you set those to, you would always receive #frame in element [0] and #frame+1 in element [1].

Posted by: diablo23q Aug 3 2011, 08:27 PM
I think I'm doing something wrong sad.gif Frame in mpInputFrames[0] is always correct, but in other elements I get some random trash. For example following runProc crashes:
CODE
int runProc(const VDXFilterActivation *fa, const VDXFilterFunctions *ff) {
PixDim w, h;
const VDXFBitmap& frame0 = *fa->mpSourceFrames[0];
const VDXFBitmap& frame1 = *fa->mpSourceFrames[1];

const Pixel32 *src = (Pixel32 *)frame0.data;
const Pixel32 *src2 = (Pixel32 *)frame1.data;
Pixel32 *dst = (Pixel32 *)fa->mpOutputFrames[0]->data;

h = frame0.h;
do {
       w = frame0.w;
       do {
               *dst++ = ((*src++) + (*src2++))/2;          
       } while(--w);
       src = (Pixel32 *)((char *)src + frame0.modulo);
       src2 = (Pixel32 *)((char *)src2 + frame1.modulo);
       dst = (Pixel32 *)((char *)dst + fa->mpOutputFrames[0]->modulo);
   } while(--h);
   return 0;
}

Where did I go wrong?

Posted by: jpsdr Aug 4 2011, 08:05 AM
You use old format/information wich are not valid with new structure.

Correct use would be :
CODE

int runProc(const VDXFilterActivation *fa, const VDXFilterFunctions *ff) {
sint32 h,w;

const VDXPixmap& frame0 = *fa->mpSourceFrames[0]->mpPixmap;
const VDXPixmap& frame1 = *fa->mpSourceFrames[1]->mpPixmap;

// Only if you are in RGB32 mode, otherwise, other planes are on data2 and data3 on YCbCr mode.
// Horizontal is /2 if you are on YUYV or UYVY mode. Warning !!!
// Get information from frame0.format to check the color mode.
const Pixel32 *src = (Pixel32 *)frame0.data;
const Pixel32 *src2 = (Pixel32 *)frame1.data;
Pixel32 *dst = (Pixel32 *)fa->mpOutputFrames[0]->mpPixmap->data

// Modulo doesn't exist anymore on this new structure, only pitch.
// Also, for other planes, there is pitch2 and pitch3.
for (h=0, h<frame0.h, h++)
{
 for (w=0, w<frame0.w, w++)
   dst[w]=(src[w]+src2[w])>>1;
 src=(Pixel32 *)((char *)src + frame0.pitch);
 src2=(Pixel32 *)((char *)src2 + frame1.pitch);
 dst=(Pïxel32 *) ((char *)dst + fa->mpOutputFrames[0]->mpPixmap->pitch);
}

return 0;
}

Posted by: diablo23q Aug 5 2011, 10:04 AM
Thanks, it works! Just one more question and I'll be satisfied. To be clear I'm writing deinterlacer and need to double video frame rate. How can I do this using mpOutputFrames or somewhat else? Tanks again, it really helps.

Posted by: jpsdr Aug 5 2011, 02:40 PM
Argh... Sorry, i have no idea for this one.
Get the latest source code (1.10.1-test12), and :
- Take a look at the code of filtres like IVTC and deinterlace.
- Read SDK.

Combining both, you may find out how things work.

Posted by: dloneranger Aug 5 2011, 02:46 PM
this is my sourcecode for an internal vdub double framerate filter in my modified virtualdub
should be easy enough to modify
CODE

#include "stdafx.h"

#include <vd2/system/cpuaccel.h>
#include <vd2/system/vdstl.h>
#include <vd2/system/fraction.h>
#include <vd2/system/memory.h>
#include <vd2/VDXFrame/VideoFilter.h>
#include <vd2/VDLib/Dialog.h>
#include <vd2/Kasumi/pixmap.h>
#include <vd2/Kasumi/pixmaputils.h>
#include <intrin.h>
#include <emmintrin.h>

#include "resource.h"
#include "filter.h"

////////////////////////////////////////////////////////////


class VDVideoFilter_fps_doublerate : public VDXVideoFilter {
public:
uint32 GetParams();
void Start();
void Run();
bool Prefetch2(sint64 frame, IVDXVideoPrefetcher *prefetcher);

//VDXVF_DECLARE_SCRIPT_METHODS();
protected:
bool mActive;
};

//VDXVF_BEGIN_SCRIPT_METHODS(VDVideoFilter_fps_doublerate)
//VDXVF_DEFINE_SCRIPT_METHOD(VDVideoFilter_fps_doublerate, ScriptConfig, "iii")
//VDXVF_DEFINE_SCRIPT_METHOD2(VDVideoFilter_fps_doublerate, ScriptConfig, "iiii")
//VDXVF_END_SCRIPT_METHODS()


uint32 VDVideoFilter_fps_doublerate::GetParams() {
const VDXPixmapLayout& srcLayout = *fa->src.mpPixmapLayout;

if (srcLayout.format ==255  )
 return FILTERPARAM_NOT_SUPPORTED;

VDFraction fr(fa->dst.mFrameRateHi, fa->dst.mFrameRateLo);
 double frConv=fr.asDouble();



fr *= VDFraction(2, 1);

fa->dst.mFrameRateHi = fr.getHi();  
fa->dst.mFrameRateLo = fr.getLo();
fa->dst.mFrameCount = ((fa->dst.mFrameCount )<<1);

frConv=fr.asDouble();
mActive=true;
 

fa->dst.mpPixmapLayout = fa->src.mpPixmapLayout;

return  FILTERPARAM_SUPPORTS_ALTFORMATS;
}


bool VDVideoFilter_fps_doublerate::Prefetch2(sint64 frame, IVDXVideoPrefetcher *prefetcher) {
 prefetcher->PrefetchFrame(0, frame>>1  , 0);

return true;
}

void VDVideoFilter_fps_doublerate::Run() {
const VDXPixmap *pxsrc[1]={
  fa->mpSourceFrames[0]->mpPixmap
};

const VDXPixmap& pxdst = *fa->mpOutputFrames[0]->mpPixmap;

fa->dst.pitch = fa->src.pitch;
fa->dst.offset  = fa->src.offset;

}


void VDVideoFilter_fps_doublerate::Start() {

}





///////////////////////////////////////////////////////////////////////////

extern const VDXFilterDefinition filterDef_fps_doublerate =
VDXVideoFilterDefinition<VDVideoFilter_fps_doublerate>(
 NULL,
//  "half rate",
 "fps double",
 "Doubles frame rate");

// warning C4505: 'VDXVideoFilter::[thunk]: __thiscall VDXVideoFilter::`vcall'{24,{flat}}' }'' : unreferenced local function has been removed
#pragma warning(disable: 4505)

Posted by: diablo23q Aug 6 2011, 12:58 AM
Thanks a lot! Wait for new deinterlacer smile.gif

Posted by: diablo23q Feb 22 2012, 02:44 PM
And finally - http://forums.virtualdub.org/index.php?act=ST&f=7&t=20890

Powered by Invision Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)