Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Java 3D / October 2004

Tip: Looking for answers? Try searching our database.

How to render Java3D to AVI using JMF

Thread view: 
Chin-Chi - 07 Oct 2004 04:50 GMT
I think that everyone can easy to write a Java3D program to slie show some
picture. But I don't know how to render it into AVI file or another movie
format. Who can help me to solve this problem ASAP. Thanks.
Christian Wiech - 08 Oct 2004 19:24 GMT
> I think that everyone can easy to write a Java3D program to slie show some
> picture. But I don't know how to render it into AVI file or another movie
> format. Who can help me to solve this problem ASAP. Thanks.

Hi,

I had that problem once ago too. The only solution I found was to take a
screenshot of the canvas in postSwap() (inherited from Canvas3D). When I
switched recording on (iMode = VIDEO) everytime postSwap was called an JPEG
is saved to disk. After turning recording off the images were processed to
a video (that is something you can find in every JMF tutorial). The problem
is that postSwap() is only called whenever somethin happens to the
universe. So e.g. if you have an animation with a shere moving to the
right, staing there for 2 seconds and the moving back. The video won't show
the two seconds of rest for the sphere. Here is a part of the code in
postSwap() (hardly undocumended but I don't have much time now).

public void postSwap()
 {
     if(iMode != NORMAL) {
    //System.out.println("get image..");
           GraphicsContext3D  ctx = getGraphicsContext3D();
    // The raster components need all be set!
    Raster ras = new Raster(
                  new Point3f(-1.0f,-1.0f,-1.0f),
    Raster.RASTER_COLOR,
    0,0,
    this.getWidth(),getHeight(),
    new ImageComponent2D(
                            ImageComponent.FORMAT_RGB,
       new BufferedImage(getWidth(), getHeight(),
           BufferedImage.TYPE_INT_RGB)),
    null);

    ctx.readRaster(ras);

    // Now strip out the image info
    BufferedImage img = ras.getImage().getImage();

    // write that to disk....
    try {
               FileOutputStream out;
 if (iMode == VIDEO)
               {
                    out = new FileOutputStream(theSavePath.getParent() +
"Capture" + postSwapCount_+".jpg");
                    //store which files belong to this videosequence in a
buffer
  imageBuffer.add(theSavePath.getParent() + "Capture" +
postSwapCount_+".jpg");
               }
 //take just one screenshot so we don't need a special name
               else
               {
                   out = new FileOutputStream(theSavePath);
               }
 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
 param.setQuality(0.75f,false); // 75% quality for the JPEG
 encoder.setJPEGEncodeParam(param);
 encoder.encode(img);
 out.close();
 //OK we've got our screenshot --> do nothing next time this function is
called
               if (iMode == SCREENSHOT) iMode = NORMAL;
    } catch ( IOException e ) {
 System.out.println("I/O exception!");
    }
    //for the next image...
    if (iMode == VIDEO) postSwapCount_++;
}
   }

Hope it helps

Cheers

Christian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.