-3

My code here is compiling correctly, but I am running into the problem that my ArrayList of BufferedImages is always empty. Honestly I don't have any knowledge regarding ImageIO or the likes!

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;

import net.sf.javavp8decoder.imageio.WebPImageReader;
import net.sf.javavp8decoder.imageio.WebPImageReaderSpi;

class MyProj{

    public static void main(String[] args) throws IOException{
        System.out.println("Main"); 

        ArrayList<BufferedImage> collectedImg=getFrames();
    }

    static ArrayList<BufferedImage> getFrames() throws IIOException{
        File MyWebM= new File("/users/case3/mcclusm4/workspace/LineTech/src/goal.webm");
        ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
        try{
            ImageReader ir = new WebPImageReader(new WebPImageReaderSpi());
            ir.setInput(ImageIO.createImageInputStream(MyWebM));


            for(int i = 0; i < ir.getNumImages(true); i++)
                frames.add(ir.read(i));

        }catch(IOException e){}
        return frames;
    }

}
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
user1861013
  • 139
  • 8
  • Are you sure there's no exceptions? What value does `ir.getNumImage(true)` return? The code above doesn't work as an MVCE, because we don't have your input file... Can you share it? – Harald K Nov 27 '14 at 10:57

2 Answers2

0

First of all dont catch Exception and do nothing:

catch (Exception e) {}

Now when an exception is catched it silently fails without any information.

Change catch to print stacktrace: e.printStackTrace() and post it.

robocoder
  • 113
  • 1
  • 9
0

Disclaimer: I have never tested the code in question myself. But...

From looking at the source code of net.sf.javavp8decoder.imageio.WebPImageReader it cannot decode WebM files. It only supports single frame WebP files.

If you stop swallowing the exception and ignoring it, as suggested by @robocoder, you should get an IIOException with the message "Bad WEBP signature!".

Harald K
  • 26,314
  • 7
  • 65
  • 111