Grab frame from video using JavaCV

1.6k views Asked by At

I am using JavaCV to grab frame from Video.

I can grab if video is in absolute path. But if video is in HTTP than JavaCV throw error.

    url = new URL("http://www.sample-videos.com/video/mp4/720/SampleVideo.mp4");
    urlConnection = (HttpURLConnection) url.openConnection();
    InputStream inputStream = urlConnection.getInputStream();
    Java2DFrameConverter bimConverter = new Java2DFrameConverter();

    FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(inputStream);

    String output = "C:\\Users\\xxxx\\Downloads\\Test";
    frameGrabber.start();
     Frame frame;  
     double frameRate=frameGrabber.getFrameRate();  
     int imgNum=5;  
     System.out.println("Video has "+frameGrabber.getFrameRate()+" frames and has frame rate of "+frameRate);  
     try {   
       frameGrabber.setFrameNumber(1000);
       frame = frameGrabber.grabKeyFrame();  
       BufferedImage bi = bimConverter.convert(frame);  
       String path = output+File.separator+imgNum+".jpg";  
       ImageIO.write(bi,"png", new File(path));
       frameGrabber.stop();   
       frameGrabber.close();
       frameGrabber.flush();                                                                        
     } catch (Exception e) {  
       e.printStackTrace();  
     } 
0

There are 0 answers