我有一个 LinkedList< BufferedImage> imgList 对象。当我添加BufferedImage时,我可以创建视频。当我使用
BufferedImage tmp1 = img.getSubimage(0,0,500,500);
imgList.add(temp1);
img 是带有加载图片的BufferedImage。
我收到此错误:
Exception in thread "main" java.nio.BufferOverflowException
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:363)
at java.nio.ByteBuffer.put(ByteBuffer.java:859)
at com.xuggle.xuggler.video.BgrConverter.toPicture(BgrConverter.java:132)
at com.xuggle.mediatool.MediaWriter.convertToPicture(MediaWriter.java:970)
at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:805)
at xuggler.CreateVideo.<init>(CreateVideo.java:61)
at xuggler.CreateGraphics.<init>(CreateGraphics.java:108)
at xuggler.Main.main(Main.java:12)
以下是我创建视频的课程:
public class CreateVideo {
private static final double framerate = 30;
private static final String outputFilename = "outputvideo.mp4";
public CreateVideo(LinkedList<BufferedImage> imgList) {
final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, bordwidth/2, bordheight/2);
long startTime = System.nanoTime();
for (BufferedImage imgs : imgList){
writer.encodeVideo(0, imgs, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
try {
Thread.sleep((long) ((1000)/ framerate));
}
catch (InterruptedException e) {
}
}//End for
writer.close();
}//end CreateVideo
}
答案 0 :(得分:0)
你能检查一下imgList和writer的大小吗?它看起来你的writer对象无法处理imageList对象中的所有图像?检查这是否有帮助