!7 lib 1006715 // jcodec 0.2.0 lib 1006717 // jcodec 0.2.0 javase import org.jcodec.api.awt.AWTSequenceEncoder8Bit; /** * This class is part of JCodec ( www.jcodec.org ) This software is distributed * under FreeBSD License * * A demo of SequenceEncoder that generates a video with a bouncing ball * * @author Stan Vitvitskyy * */ p { final int speed = 4; final int ballSize = 40; File outFile = prepareProgramFile("test.mp4"); int framesToEncode = 100; AWTSequenceEncoder8Bit enc = AWTSequenceEncoder8Bit.create25Fps(outFile); enc.getEncoder().setKeyInterval(25); long totalNano = 0; BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_3BYTE_BGR); for (int i = 0, x = 0, y = 0, incX = speed, incY = speed; i < framesToEncode; i++, x += incX, y += incY) { Graphics g = image.getGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, image.getWidth(), image.getHeight()); g.setColor(Color.YELLOW); if (x >= image.getWidth() - ballSize) incX = -speed; if (y >= image.getHeight() - ballSize) incY = -speed; if (x <= 0) incX = speed; if (y <= 0) incY = speed; g.fillOval(x, y, ballSize, ballSize); long start = System.nanoTime(); enc.encodeImage(image); totalNano += System.nanoTime() - start; } enc.finish(); System.out.println("FPS: " + ((1000000000L * framesToEncode) / totalNano)); }