Making movies with IDL, part II

Last week, I gave an example of making a movie with IDLffVideoWrite and DG. This week, I’ll use NG to make a similar movie.

The example is again written as a procedure. Start the program by declaring some test data and making a simple visualization:

pro ng_movie_ex
   compile_opt idl2

   data = dist(30)

   s = surface(data, color='blue', /buffer)
   c = contour(data, n_levels=10, zvalue=0.0, /overplot)
   t = text(0.5, 0.9, 'IDL Movie Example - NG', alignment=0.5, font_size=16)

Note that the BUFFER property is set on the call to SURFACE. It forces the visualization to be rendered to an offscreen buffer; it’s the analog to the DG Z buffer device.

Next, set up the IDLffVideoWrite object:

   video_file = 'ng_movie_ex.mp4'
   video = idlffvideowrite(video_file)
   framerate = 10
   wdims = s.window.dimensions
   stream = video.addvideostream(wdims[0], wdims[1], framerate)

As in last week’s example, I’ve chosen to output to an MPEG-4 video file. The dimensions of the movie are taken from the dimensions of the buffer (the default, 640 x 512) created in the call to the SURFACE function.

The next step is to make and load frames into the movie file:

   nframes = 50
   for i=0, nframes-1 do begin
      s.rotate, 1.0, /yaxis               ; degrees
      c.zvalue = i*max(s.zrange)/nframes  ; data coordinates
      timestamp = video.put(stream, s.copywindow())
   endfor

On each iteration of the loop:

  1. The Rotate method rotates the surface by one degree about the global y-axis of the visualization (this is from Object Graphics; +x is right, +y is up, +z is pointed toward you)
  2. By modifying its ZVALUE property, the contour plot moves up by a fraction of the total height of the surface.
  3. The CopyWindow method (the analog to the TVRD function in DG) takes a picture of the visualization in the buffer. The picture is a pixel-interleaved RGB image, with dimensions 3 x 640 x 512.
  4. The Put method of IDLffVideoWrite loads this picture as a frame into the video stream.

End the program by destroying the video object and the buffered graphic:

   video.cleanup
   print, 'File "' + video_file + '" written to current directory.'
   s.close
end

Click below to see the resulting video on the VIS YouTube channel.

 

Notes:

  1. I have a more complex NG movie example that uses the SetData method introduced in 8.1. You can download it from this [exelisvis.com] page; look for the “What’s New in IDL 8.1” webinar files, grab them and look for the program called VIDEO_WRITE1. I may give this example the blog treatment at a later point.
  2. I also have two other fun examples that should get the blog treatment: a) creating an AVI movie that can be embedded in a PowerPoint presentation, and b) creating a SWF movie that, with an HTML+Javascript framework, can be viewed in a web browser. Both are included in the IDL 8.1 examples above; look for the program VIDEO_WRITE2 and its output.
About these ads

About Mark

I solve scientific programming and visualization problems with IDL.
This entry was posted in language, output, programming, visualization and tagged , , , , , , , . Bookmark the permalink.

4 Responses to Making movies with IDL, part II

  1. Pingback: Making movies with IDL, part I | The IDL Data Point

  2. Hey Dr. Piper,
    What can I do if I the ffmpeg library distributed with IDL 8.2 lacks support for the codec of my dreams? Is there anything I, as an aspiring filmmaker, can do to address this?
    Thanks,
    Jim P.

  3. Mark says:

    Hey Mr. P,

    Would you like, for example, to use H.264? I assure you there will be a way in IDL 8.2! (I’ve even made an example with the latest build.)

    mp

  4. Stephan N says:

    Hi,
    IDLffVideowrite offers a tremendous number of codecs on my Mac and I really appreciate this addition to IDL’s armamentarium (47 on my Mac). Not unexpected, the default MPEG-4 renders my MRI videos a little blocky. Which codec would you recommend if
    a) the typical data size is 800x800x25
    b) the target is Powerpoint
    and c) the desired file size should stay below 3MB ?
    Hints are greatly appreciated !
    Stephan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s