It's hard to say without seeing your stack, but this line.
ImageIO.write(frame, "png", new File("frame_150.png"));
Exception frame null can be selected. I would rewrite code like this.
try { BufferedImage frame = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); frame = FrameGrab.getFrame(new File("/Users/AG/Downloads/video.mp4"), frameNumber); if (frame != null) { ImageIO.write(frame, "png", new File("frame_150.png")); } } catch (IOException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); } catch (JCodecException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); }
Note that it makes no sense to instantiate a new BufferedImage if you reassign it on the next line, and it makes no sense to run the third line ( ImageIO.write ) if FrameGrab.getFrame returns null (which is most likely what happens here).
source share