Log in

View Full Version : Frame Copying question


nlemozz
17th September 2010, 22:41
I have a question about copying/saving frames between calls.

I want to do the following in my GetFrame function:

PVideoFrame src = child->GetFrame(n, env);
PVideoFrame dst = env->NewVideoFrame(vi);

const unsigned int * srcp = (const unsigned int*) src->GetReadPtr();
unsigned int* dstp = (unsigned int*) dst->GetWritePtr();

**** Do some operations on dst through dstp here *****

*** Save dst to a member of my class which is a PVideoFrame here eg PVideoFrame savedFrame****

**** Do more operations on dst through dstp here without affecting the saved version *****

return dst



My question is, can I just use:
savedFrame = dst;
or do I have to do some sort of new/copy/delete?

Thanks in advance.

kemuri-_9
18th September 2010, 00:10
No, assigning one PVideoFrame to another does not copy the data, it just adds another reference to the original.

you'll need to use something like env->BitBlt to copy the pixel data from one frame to another; it's one call per plane.


PVideoFrame src = child->GetFrame(n, env);
PVideoFrame dst = env->NewVideoFrame(vi);

/* alter dst here */

PVideoFrame savedFrame = env->NewVideoFrame(vi);

/* use env->BitBlt to copy the frame data from dst to savedFrame */
(for 'single-planed' csps like YUY2, RGB, and RGBA the following should work)
env->BitBlt( savedFrame->GetWritePtr(), savedFrame->GetPitch(), dst->GetReadPtr(), dst->GetPitch(), dst->GetRowSize(), dst->GetHeight() );

/* finish altering dst */

return dst;

nlemozz
18th September 2010, 00:22
Thanks.
Will do.