Combining Multiple videos

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Combining Multiple videos

satish_kodavali2000
I have a 4 video(avi) files.
Now I need to combine all 4 of them into single file.
In the output video all the 4 files need to be played simultaneously.
Something like the screen is split into 4 parts and each part contain
one of the 4 videos.

Any idea how can i do this? Urgent help is requested

Sateesh

Reply | Threaded
Open this post in threaded view
|

Re: Combining Multiple videos

wl2776
Administrator
--- In [hidden email], "satish_kodavali2000" <kodavali.satish@...> wrote:

>
> I have a 4 video(avi) files.
> Now I need to combine all 4 of them into single file.
> In the output video all the 4 files need to be played simultaneously.
> Something like the screen is split into 4 parts and each part contain
> one of the 4 videos.
>
> Any idea how can i do this? Urgent help is requested
>
> Sateesh

That's fairly simple, provided videos have the same frame rate.

You have to create an empty image having enough size to include all your pictures.

IplImage *combined=cvCreateImage(cvSize(width, height), depth, channels);

/*you have to determine the arguments, of course.*/

Then you create 4 image headers.
Regions of the combined image data will be the data for these headers.

IplImage *im1=cvCreateImageHeader(cvSize(width_of_1st_movie,
height_of_1st_movie),combined->depth,combined->nChannels)

im1->origin=combined->origin;
im1->widthStep=combined->widthStep;
im1->imageData=combined->imageData+
    0 /*y coordinare of top left corner*/ * combined->width->Step+
    0 /*x coordinate of top left corner*/ * combined->nChannels;

IplImage *im2=cvCreateImageHeader(cvSize(width_of_2nd_movie,
height_of_2nd_movie),combined->depth,combined->nChannels)
im2->origin=combined->origin+im1->width*combined->nChannels; /*to the right of the
first movie*/
im2->widthStep=combined->widthStep;
im2->imageData=combined->imageData+
    0 /*y coordinare */ * combined->width->Step+
    im2->width /*x coordinate */ * combined->nChannels;

Same way for other two images.

Then you do the loop
{

Four times query frame
Then save combined image to a video frame

}

Reply | Threaded
Open this post in threaded view
|

Re: Combining Multiple videos

satish_kodavali2000
Thank you for the response.

I have some questions here about the logic.
You have created the 4 headers in the beginning right. And there you
are using im1->imageData=combined->imageData+
combined->width->Step+combined->nChannels;

But at this point combined->imageData has got nothing in it. So should
we do it in the loop after reading the frames?

And I didn't understand "Then save combined image to a video frame" in
the loop.
Where are we actually combining images. We just have four image
headers with required coordinates.

Thanks again. Awaiting reply.

Sateesh

--- In [hidden email], "wl27761" <wl2776@...> wrote:
>
> --- In [hidden email], "satish_kodavali2000"
<kodavali.satish@> wrote:

> >
> > I have a 4 video(avi) files.
> > Now I need to combine all 4 of them into single file.
> > In the output video all the 4 files need to be played simultaneously.
> > Something like the screen is split into 4 parts and each part contain
> > one of the 4 videos.
> >
> > Any idea how can i do this? Urgent help is requested
> >
> > Sateesh
>
> That's fairly simple, provided videos have the same frame rate.
>
> You have to create an empty image having enough size to include all
your pictures.
>
> IplImage *combined=cvCreateImage(cvSize(width, height), depth,
channels);

>
> /*you have to determine the arguments, of course.*/
>
> Then you create 4 image headers.
> Regions of the combined image data will be the data for these headers.
>
> IplImage *im1=cvCreateImageHeader(cvSize(width_of_1st_movie,
> height_of_1st_movie),combined->depth,combined->nChannels)
>
> im1->origin=combined->origin;
> im1->widthStep=combined->widthStep;
> im1->imageData=combined->imageData+
>     0 /*y coordinare of top left corner*/ * combined->width->Step+
>     0 /*x coordinate of top left corner*/ * combined->nChannels;
>
> IplImage *im2=cvCreateImageHeader(cvSize(width_of_2nd_movie,
> height_of_2nd_movie),combined->depth,combined->nChannels)
> im2->origin=combined->origin+im1->width*combined->nChannels; /*to
the right of the

> first movie*/
> im2->widthStep=combined->widthStep;
> im2->imageData=combined->imageData+
>     0 /*y coordinare */ * combined->width->Step+
>     im2->width /*x coordinate */ * combined->nChannels;
>
> Same way for other two images.
>
> Then you do the loop
> {
>
> Four times query frame
> Then save combined image to a video frame
>
> }
>


Reply | Threaded
Open this post in threaded view
|

Re: Combining Multiple videos

wl2776
Administrator
--- In [hidden email], "satish_kodavali2000" <kodavali.satish@...> wrote:
>
> Thank you for the response.
>
> I have some questions here about the logic.
> You have created the 4 headers in the beginning right. And there you
> are using im1->imageData=combined->imageData+
> combined->width->Step+combined->nChannels;
Some basics.
They are described in the book. I strongly recommend. (Gary Gradsky and Adrian
Kaehler. Learning OpenCV, published by O'Reilly).
I have read this method in the book.

In OpenCV, an image is represented with a structure, describing its width, height,
colorspace, bit depth, etc - a header ( IplImage ).
This structure also contains the pointer to the actual image data (IplImage::imageData).
Image is stored pixel after pixel, each pixel is represented with 3 bytes: for red, green
and blue components of a color (in case of color image).
 
OpenCV also allows separate allocation of the structure parts. You can create a header
only and attach already allocated data to it. This is happening here.
I have suggested you to allocate one large data array with attached header with
cvCreateImage.

Then I have suggested you to create four more headers and attach them to the parts of
that data array.

> But at this point combined->imageData has got nothing in it. So should
> we do it in the loop after reading the frames?

I have referred to the info about cvQueryFrame.

It appears, all is a bit more complicated in case of video.
You should use cvCopyImage.

Again.

Initially, you call cvCreateFileCapture four times for your files.
It gives you four capture structures.

Then you call in a loop

frame=cvQueryFrame(capture1);
cvCopyImage(im1,frame);
im2=cvQueryFrame(capture2);
cvCopyImage(im2,frame);
im3=cvQueryFrame(capture3);
cvCopyImage(im3,frame);
im4=cvQueryFrame(capture4);
cvCopyImage(im4,frame);

And hopefully, this will give you all images, combined in one large image.


> And I didn't understand "Then save combined image to a video frame" in
> the loop.
> Where are we actually combining images. We just have four image
> headers with required coordinates.
>
> Thanks again. Awaiting reply.
>