gpt4 book ai didi

java - 图像到视频 Xuggler

转载 作者:行者123 更新时间:2023-12-01 14:32:18 25 4
gpt4 key购买 nike

我使用 xuggler 但不明白。我有 ArrayList,我想用这些图像、视频制作。但是当我编译这段代码时,视频图像的前 5 秒没有改变,视频的最后 5 秒根本没有改变。怎么解决。

public class ScreenRecordingExample {

private static int FPS = 1000 / 25;
private static final String outputFilename = "c:/mydesktop.mp4";
private static Dimension screenBounds;

public static void main(String[] args) throws IOException {

final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);

screenBounds = Toolkit.getDefaultToolkit().getScreenSize();

writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,
screenBounds.width / 2, screenBounds.height / 2);

long startTime = System.nanoTime();

List<BufferedImage> BIList = getImagesFromDirectory(null);

for (int index = 0; index < BIList.size(); index++) {

BufferedImage bgrScreen = convertToType(BIList.get(index),BufferedImage.TYPE_3BYTE_BGR);
writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime,
TimeUnit.NANOSECONDS);

try {
Thread.sleep((long) (1000 / 15));
} catch (InterruptedException e) {}
}

writer.close();

}

public static BufferedImage convertToType(BufferedImage sourceImage, int targetType) {

BufferedImage image;

// if the source image is already the target type, return the source image
if (sourceImage.getType() == targetType) {
image = sourceImage;
} // otherwise create a new image of the target type and draw the new image
else {
image = new BufferedImage(sourceImage.getWidth(),
sourceImage.getHeight(), targetType);
image.getGraphics().drawImage(sourceImage, 0, 0, null);
}

return image;

}

private static List<BufferedImage> getImagesFromDirectory(File directory) throws IOException {


File dir = new File("C:\\fotos\\");
final String[] EXTENSIONS = new String[]{"gif", "png", "bmp"};

final List<BufferedImage> imageList = new ArrayList<BufferedImage>();

FilenameFilter IMAGE_FILTER = new FilenameFilter() {

@Override
public boolean accept(final File dir, final String name) {
for (final String ext : EXTENSIONS) {
if (name.endsWith("." + ext)) {
return (true);
}
}
return (false);
}
};
if (dir.isDirectory()) { // make sure it's a directory
for (final File f : dir.listFiles(IMAGE_FILTER)) {
BufferedImage img = null;
img = ImageIO.read(f);
imageList.add(img);
}
}
return imageList;
}

最佳答案

编辑你的问题,它本身就是一个谜题。不明白“视频图像前 5 秒不变,视频后 5 秒根本不变”的意思。

关于java - 图像到视频 Xuggler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16771306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com