2013-05-27 5 views
0

나는 xuggler를 사용하지만 그걸 이해하지 못한다. 나는 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; 
    } 

답변

1

질문을 편집하고 그 자체로 퍼즐을 만드십시오. Dint는 "처음 5 초 동안 비디오 이미지가 바뀌지 않고 마지막 5 초가 비디오에 전혀 들리지 않습니다."라는 의미를 이해합니다.

0

나는 당신이 당신의 대답을 찾을 것이다 바라지 만이 다른 사람을 도울 수있는 시간이 초기화를 시작으로 이동 한 후 호출 getImagesFromDirectory

long startTime = System.nanoTime(); 
List<BufferedImage> BIList = getImagesFromDirectory(null); 

List<BufferedImage> BIList = getImagesFromDirectory(null); 
long startTime = System.nanoTime();*