[vtkusers] How to write AVI files properly, Please Help

Janny Dong janny.dong at gmail.com
Wed May 30 12:40:37 EDT 2007


Hey Beau,

Thank you so much! You are right! I update the pointer to the
vtkWindowToImageFilter
every time when I call the image rendering function. After I added
avi->SetInputConnection(w2i->GetOutputPort())
to the loop, the generated movie looks normal.

Also, off-screen rendering is acceptable. That is, when I set the off-screen
rendering on, the program can still get proper movies.

Janny

On 5/30/07, Beau Sapach <beau.sapach at ualberta.ca> wrote:
>
>  Hi Janny,
>
>
>
> I'm not sure I understand your code… the ImgRender() function somehow
> changes your input data and renders the image (changing what is displayed in
> the window) and then returns a pointer to the vtkWindowToImageFilter,
> correct?  I'm not sure why you have w2i = ImgRender() in your loop.  Once
> you have a pointer to the filter you shouldn't need to assign that pointer
> again, unless you're deleting and re-creating the vtkWindowToImageFilter on
> each call to ImgRender(), are you?  If you are, then you should call
> avi->SetInputConnection(w2i->GetOutputPort()) each time you get a new w2i
> pointer.
>
>
>
> Beau
>
>
>  ------------------------------
>
> *From:* Janny Dong [mailto:janny.dong at gmail.com]
> *Sent:* Tuesday, May 29, 2007 3:16 PM
> *To:* Beau Sapach
> *Subject:* Re: [vtkusers] How to write AVI files properly, Please Help
>
>
>
> Hey Beau,
>
> Thanks a lot for your suggestions. I still could not get correct movies.
> What I did is:
>
> Define a function - static vtkWindowToImageFilter *ImgRender() to render
> the images and pass WindowToImageFilter as a parameter to main();
> My main function is
> int main( int argc, char *argv[] )
> {
>     int imageN;
>     //Generate avi file
>     vtkWindowToImageFilter *w2i = ImgRender();
>     vtkAVIWriter *avi = vtkAVIWriter::New();
>     avi->SetInputConnection(w2i->GetOutputPort());
>     avi->SetFileName("test.avi");
>     avi->Start();
>
>     for (imageN = 0; imageN < 10; imageN ++)
>     {
>         w2i = ImgRender();
>         avi->Write();
>     }
>     avi->End();
>     avi->Delete();
>     w2i->Delete();
>     return 0;
> }
>
> I don't know how you set up your loop to generate movies. I already
> switched to on-screen rendering and I could see the images in the rendering
> window were changing. I am guessing probably it's not a good way to pass the
> WindowToImageFilter as a parameter, but I have no better idea to do this
> right now, because my image rendering part is fairly large, and I try to
> make the code neat by defining the rendering part as a function and calling
> it in the main function.
>
> Sorry to bother you and thanks for sharing your experience with me.
>
> Janny
>
> On 5/29/07, *Beau Sapach* < beau.sapach at ualberta.ca> wrote:
>
> Hi Janny,
>
>
>
> My movies are 2-4MB or less for 30 frames @ 25 frames per second.  I just
> realized something though.  If you're using SetOffScreenRendering(1) then
> when you call Render() the image in the window is not updated.  It's the
> image in the vtkRenderWindow that the vtkWindowToImageFilter uses.  I'm just
> guessing but the single static image you're seeing in the AVI file is
> probably the last image that was rendered to the window (before off-screen
> rendering was switched on).
>
>
>
> It may work properly if you leave rendering on-screen.  Or if you want to
> use off-screen rendering you could probably get the memory buffer that the
> vtkRenderWindow it's rendering to, and use the RGBA data in there to build
> your own vtkImageData object and write that to the AVI.
>
>
>
> Beau
>
>
>  ------------------------------
>
> *From:* Janny Dong [mailto:janny.dong at gmail.com]
> *Sent:* Tuesday, May 29, 2007 12:27 PM
> *To:* Beau Sapach
> *Cc:* vtkusers
> *Subject:* Re: [vtkusers] How to write AVI files properly, Please Help
>
>
>
> Beau, you said you didn't have size problem. You are saying your movie is
> reasonably smaller?
>
> I added Modified() before the line WindowToImage->update() as you
> suggested. The movie still shows a single static image. :(
>
> Janny
>
> On 5/29/07, *Janny Dong* <janny.dong at gmail.com> wrote:
>
> Thanks, Beau. I tried to play with FFMPEG, but with no success. I am using
> MSVC, and unfortunately FFMPEG doesn't support it, so I couldn't get the
> library installed. My project requires automated movie generation. That's
> why I am struggling to get everything under control in my code. :(
>
> Janny
>
>
>
> On 5/29/07, *Beau Sapach* < beau.sapach at ualberta.ca> wrote:
>
> I think I had a similar problem, not the size issue but the single, static
> image issue.  Try calling Modified() on vtkWindowToImageFilter before you
> call Update().  As for frame rate I don't know how to set that with vtk's
> classes, I suggest you look at FFMPEG, it can be built into VTK but I've had
> little luck doing so.  Currently I write out image files and have my
> application call the ffmpeg executable to encode the images as a movie,
> using ffmpeg command line options you can control framerate.
>
>
>
> Beau
>
>
>  ------------------------------
>
> *From:* vtkusers-bounces+beau.sapach= ualberta.ca at vtk.org [mailto:
> vtkusers-bounces+beau.sapach=ualberta.ca at vtk.org] *On Behalf Of *Janny
> Dong
> *Sent:* Tuesday, May 29, 2007 8:24 AM
> *To:* vtkusers
> *Subject:* [vtkusers] How to write AVI files properly, Please Help
>
>
>
> I posted a similar question but didn't get any answer, probably I didn't
> make it clear enough.
>
> I am coding a C++ program to visualize my data and generate movie
> automatically. I put vtkAVIWriter in a loop to get a movie out of the
> rendering. It did get an avi file, but not the one I expected. I have two
> questions about it.
>
> (1) The size of the movie file is 18MB, but it has only 50 frames.
> Moreover, it is only 3 second long. Can I compress the movie file with
> vtkAVIWriter? How can I control the speed of the movie, like specifying
> number of frames per second?
>
> (2) I found the avi file displayed only one frame like a static image.
> However, I did update the data when rendering each frame. The data rendering
> part in my program is like
> data
> points--->vtkPolyData--->vtkDelaunay2D--->vktPolyDataMapper--->vtkRenderer--->vtkWin32OpenGLRenderWindow->SetOffScreenRendering(1)--->vtkWindowToImageFilter--->vtkAVIWriter
>
>
> I have something like: PolyDataMapper->update(); WindowToImage->update()
> in my code.  Did I call update() in a wrong way or should I call it in
> different parts of the code?
>
> Any suggestions will be greatly appreciated.
>
> Janny
>
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070530/e5d69762/attachment.htm>


More information about the vtkusers mailing list