How can I turn a series of images into a video using JCodec?

后端 未结 2 632
情书的邮戳
情书的邮戳 2021-01-07 07:06

I\'m trying to use JCodec to turn a series of images into a video inside of a Java SE desktop application. The few methods I\'ve tried all resulted in a video that Windows

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 07:42

    With 0.2.0 there is now https://github.com/jcodec/jcodec/blob/master/javase/src/main/java/org/jcodec/api/awt/AWTSequenceEncoder8Bit.java

    This example creates a MP4 with a fixed background and overlaid animation. No sound.

        AWTSequenceEncoder8Bit enc = AWTSequenceEncoder8Bit.create2997Fps(outputMovieFile); 
        int framesToEncode = (int) (29.97 * durationInSeconds);
        java.awt.image.BufferedImage image = ...(some background image)
    
        for (int frameIndx = 0, x = 0, y = 0, incX = speed, incY = speed; frameIndx < framesToEncode; frameIndx++, x += incX, y += incY) {
            Graphics g = image.getGraphics();
            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);
            enc.encodeImage(image);
        }
        enc.finish();
    

提交回复
热议问题