Make Movies

Step 1:

Do screen grab at every frame and encode the captured image to JPEG format. The solution could come from Java 3D but using Robot seems to be a more stable method (from I read from different forums).

     try {
       //setLocationRelativeTo(null);
       Rectangle win = getBounds();
       Robot robot = new Robot(getGraphicsConfiguration().getDevice());
       BufferedImage image =
         robot.createScreenCapture(new Rectangle(win.x, win.y,
                                                 win.width, win.height));
       FileOutputStream out = new FileOutputStream("image" + jpgCount + ".jpg");
       JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
       JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
       param.setQuality(0.9f, false);
       encoder.setJPEGEncodeParam(param);
       encoder.encode(image);
       out.close();
     } catch(AWTException e) {
       e.printStackTrace();
     } catch(IOException e) {
       System.err.println("I/O exception!");
     }
     jpgCount++;

Step 2:

Stitch the still images into a movie using ffmpeg:

or

Bit rate is probably the main factor for quality. Choose wisely. The default bit rate of 200 yields low quality result.

Advertisements

One Response to “Make Movies”

  1. Yung-Chang Tan Says:

    In windows, make a “makemovie.bat” that consists of this line will also works

    ffmpeg -i imageimage%%d.jpg -sameq movie.mpg–>

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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: