我正在使用一堆 png 文件来创建视频。我的问题是,虽然 png 文件的质量还可以,但视频帧的渲染质量不够好。你知道我该如何解决这样的问题吗?事物?这是我写的关于此事的代码:
private void createVideo() throws IOException{
IMediaWriter writer = ToolFactory.makeWriter(outputFilename);
Dimension screenBounds = Toolkit.getDefaultToolkit().getScreenSize();
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,screenBounds.width/2, screenBounds.height/2);
long startTime = System.nanoTime();
File directory = new File(sourceFolder);
ArrayList<File> filenames = new ArrayList<File> ();
File[] list= directory.listFiles();
for(int i=0;i<list.length;i++){
filenames.add(list[i]);
}
for (int index = 0; index < filenames.size(); index++) {
if(filenames.get(index).toString().contains("png")){
BufferedImage screen = ImageIO.read(filenames.get(index));
// convert to the right image type
BufferedImage bgrScreen = convertToType(screen,BufferedImage.TYPE_3BYTE_BGR);
int i=0;
while(i<FRAME_RATE){
writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime,
TimeUnit.NANOSECONDS);
++i;
}
// sleep for frame rate milliseconds
try {
Thread.sleep((long) (1000 / FRAME_RATE));
}
catch (InterruptedException e) {
}
}
}
writer.close();
}
解决方案:问题出在这条线
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,screenBounds.width/2, screenBounds.height/2);
在我删除它之后,我不应该将宽度和高度除以 2,它的质量就像它本身的 png 一样。