View Full Version : How to create a new PVideoFrame from a Cropped PVideoFrame?
milkyjing
17th November 2009, 15:43
Hello Everybody!
I'm new here, so I'm not sure whether I've post my thread at the right place. But I'm looking for ANY help urgently.
my question is:
## test.avs###
LoadPlugin("testPlugin.dll") # my own plugin only contains a very simple function named testFunc
clip = AVISource("test.avi") # just open a normal video
clip = clip.crop(16, 16, -16, -16) # then crop it
clip = clip.testFunc() # simply returns a new copy of the cropped frames
return clip
###end###
the testFunc just returns a new PVideoFrame.
PVideoFrame __stdcall testPlugin::GetFrame(int n, IScriptEnvironment *env)
{
PVideoFrame src = child->GetFrame(n, env);
PVideoFrame dst = env->NewVideoFrame(vi);
// what should I do here?
return dst;
}
thank you for advance!
p.s. Sorry for my bad English!
Regards,
milkyjing
neuron2
17th November 2009, 16:06
// what should I do here? You have to copy the data. Here's an example that copies copyframe->copy (from Dup source code):
PVideoFrame copy = env->NewVideoFrame(vi);
/* Refresh from copyframe. */
if (vi.IsYUY2())
{
env->BitBlt(copy->GetWritePtr(), copy->GetPitch(),
copyframe->GetReadPtr(), copyframe->GetPitch(),
copyframe->GetRowSize(), copyframe->GetHeight());
}
else // YV12
{
env->BitBlt(copy->GetWritePtr(PLANAR_Y),
copy->GetPitch(PLANAR_Y),
copyframe->GetReadPtr(PLANAR_Y),
copyframe->GetPitch(PLANAR_Y),
copyframe->GetRowSize(PLANAR_Y),
copyframe->GetHeight(PLANAR_Y));
env->BitBlt(copy->GetWritePtr(PLANAR_U),
copy->GetPitch(PLANAR_U),
copyframe->GetReadPtr(PLANAR_U),
copyframe->GetPitch(PLANAR_U),
copyframe->GetRowSize(PLANAR_U),
copyframe->GetHeight(PLANAR_U));
env->BitBlt(copy->GetWritePtr(PLANAR_V),
copy->GetPitch(PLANAR_V),
copyframe->GetReadPtr(PLANAR_V),
copyframe->GetPitch(PLANAR_V),
copyframe->GetRowSize(PLANAR_V),
copyframe->GetHeight(PLANAR_V));
}
milkyjing
17th November 2009, 16:24
thank you very much neuron2 !
but I'm sorry to say that I'm not very sure what the "copyframe" means, does it mean child->GetFrame(n, env) ?
if so, I think copyframe->GetReadPtr(...) is the same with the origional frame buffer , so, since we don't know the value of l1 and l2, how could we copy the data from "S" to our dest "N"
http://www.tcsub.com/attachments/month_0911/091117232273592fb72842322d.bmp
neuron2
17th November 2009, 16:31
The clip coming in to testFunc is already cropped, so I don't understand why you think the source frame and the copy you want to make in testFunc have different frame sizes.
milkyjing
17th November 2009, 17:19
Thank you nueran2, you are really helpful!
the problem has been solved successfully with your help.
indeed it was the pitch that puzzled me much, I thought src->GetPitch() and dst->GetPitch() would be the same which proved to be false. in fact src->GetPitch() is equal to the origional frame buffer pitch which made me reconsider that src->GetReadPtr() is also the same with the origional (instead of the cropped).
Can we conclude that the frame buffer of the cropped is the same with the origional, while src->GetReadPtr() indicates the top-left corner of the square "S" instead of the top-left corner of the square "O"?
regards,
milkyjing
Gavino
17th November 2009, 18:18
Can we conclude that the frame buffer of the cropped is the same with the origional, while src->GetReadPtr() indicates the top-left corner of the square "S" instead of the top-left corner of the square "O"?
Yes, that's right - that's why Crop is a relatively fast operation, it just adjusts pointers.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.