Page 1 of 1

first frame from a blob??

Posted: 2009-05-21T18:21:58-07:00
by kunjbhai
This is in continuity of thread viewtopic.php?f=1&t=13609. Since no replies are coming over there so I thought may be that too has become inactive.

I could not get the sampling going while streaming through an image. Can you please give an example for that.
Also I tried following plz have a look into it:

Magick::Image image;
image.subImage(3);
image.subRange(1);

I was trying to use the above methods to get the first scene from a mpg http://cid-7572e6fdaea4368b.skydrive.li ... ic/vid.mpg while using blob but it does not work like ("vid.mpg[0]")
I used the following code:

Code:

Code: Select all

int main(int argc,char * argv)
{
InitializeMagick(argv);
std::string path("C:\\Tests\\vid.mpg");

/** Passing [0] in the file name itself **/
Image *image1=new Image();
image1->read(path+"[0]");
image1->write("C:\\Tests\\SceneInName.jpeg");
delete(image1);
cout<<"Copying from image done.";

/** Asking to retrieve only first frame by using subRange **/
ifstream fl(path.c_str(), ios::in | IOS_IN_BINARY );
fl.seekg(0, ios::end );
size_t blobLen = fl.tellg();
unsigned char* blobData = new unsigned char[blobLen];
char* c=reinterpret_cast<char *>(blobData);
fl.seekg(0,ios::beg);
fl.read(c, blobLen);
fl.close();

// Construct Magick++ Blob
Blob blob(static_cast<const unsigned char*>(blobData), blobLen);
delete [] blobData;

image1=new Magick::Image();
image1->subImage(3);
image1->subRange(1);

image1->magick("MPG");

image1->read( blob);
image1->write("C:\\Tests\\SceneInSubRange.jpeg");
delete(image1);
cout<<"Copying from Bytes done.";
}

Though I only get the first scene by both methods but that happens even if I don't use [0] OR subImage() and subRange() methods at all.

But in first case (path+"[0]") the time taken is way less than during subImage(),subRange() methods which suggests that they are not doing the same thing.

How can we get the same effect as (path+"[0]") for the case where we want to read image from inside a file, from an offset other than zero, (i.e. in case of blobs)?

Re: first frame from a blob??

Posted: 2009-05-21T19:15:31-07:00
by anthony
Note I am not a C++ programmer in IM, and while I have done a lot of C programming (in the core library) PerlMagick and sheel programmer, I could only basically follow what you are attempting to do.

I think I understand what your problem is. Hopefully I will not be too far off base. If so perhaps you should rephrase your problem more generally (away from C++ specifics) more people can help.


A blob is essentially a image file format in memory. You should still be able to specify an image range while reading the images.

Of course if memory is not a problem, then you could just read in all the images the delete the ones
you do not want.

Eg equivalent to convert image.mpg -delete 0-3,5--1 ...process the 5th image...
so as to only keep image number '4' (the 5th image in sequence).

Another way is move the image out then delete the rest.
convert image.mpg -swap 0,4 -delete 2--1 ....


However mpegs can be very large (why is it in a in-memory blob if use of memory a problem?) and the more usual way of handling mpegs is to use a utilitiy like mencoder, mplayer or some other streaming video filter, to extract the frame wanted, before passing just that frame to Imagemagick for processing.

See the raw notes in IM examples, MPG and AVI file format handling
http://www.imagemagick.org/Usage/formats/#mpeg

Re: first frame from a blob??

Posted: 2009-05-21T19:24:36-07:00
by magick
Anthony we added a patch lately to only read as many frames as needed with a subimage specification (e.g. vid.mpg[0]). We can reproduce the problem and will have a fix for it in ImageMagick-6.5.2-8 Beta within a few days. Thanks.