0
我使用xuggler但不明白that.I有ArrayList,我想從這個圖像,視頻製作。但是,當我在視頻圖像的第一個5秒內編譯此代碼不會改變,而在視頻上持續5秒時,則完全不會。如何解決它。圖像到視頻Xuggler
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;
}