如何使用Java以编程方式将PowerPoint(pptx)导出为带有动画的视频

8fq7wneg  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(199)

我正在尝试以编程方式将powerpoint演示文稿导出为视频。我试着跟随。
1.使用org.apache.poixslf.usermodel.SlideShow打开pptx文件
1.根据要求更新幻灯片
1.为每张幻灯片创建图像(使用slide.draw()
1.通过一个接一个地附加幻灯片图像来创建视频
该代码正在生成视频。视频是幻灯片的静态图像的集合。问题是幻灯片中包含的动画在视频中不存在。
有没有什么方法可以使用apache.poi或其他选项将动画导出到视频中?

f45qwnt8

f45qwnt81#

若要将PowerPoint演示文稿转换为具有形状动画和幻灯片过渡的视频,可以使用Aspose.Slides for Java。此库允许为整个动画生成一组具有特定每秒帧(FPS)的帧。然后,这些帧可以通过FFmpeg等工具用于创建视频。

final int FPS = 30;
Presentation presentation = new Presentation("animated.pptx");
try {
    PresentationAnimationsGenerator animationsGenerator = new PresentationAnimationsGenerator(presentation);
    try {
        PresentationPlayer player = new PresentationPlayer(animationsGenerator, FPS);
        try {
            player.setFrameTick((sender, args) ->
            {
                try {
                    ImageIO.write(args.getFrame(), "PNG", new File("frame_" + sender.getFrameIndex() + ".png"));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });
            animationsGenerator.run(presentation.getSlides());
        } finally {
            if (player != null) player.dispose();
        }
    } finally {
        if (animationsGenerator != null) animationsGenerator.dispose();
    }
} finally {
    if (presentation != null) presentation.dispose();
}

你可以找到更多的细节here

相关问题