2017-02-12 59 views
0

嘗試使用javaCV,FFFmpegFramGrabber和FFFmpegFramGrabber從視頻文件中提取每個幀並保存爲jpg,最終每次都獲取相同的幀。每次使用Android中的FFmpegFrameGrabber.grabImage()獲取相同的幀

 FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(cVideoFilePath+ "/" + "VID_20170211_132657.mp4"); 
    try { 
     AndroidFrameConverter convertToBitmap = new AndroidFrameConverter(); 
     grabber.start(); 

     for (int i= 0; i< grabber.getFrameRate();i++){ 

      frame1 = grabber.grabImage(); 
      Bitmap bitmap = convertToBitmap.convert(frame1); 
      String date = simpleDateFormat.format(new Date()); 
      File picfile = new File(file_name); 
      if (!picfile.exists()) { 
       try { 
        picfile.createNewFile(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 
      try { 

       FileOutputStream out = new FileOutputStream(picfile); 
       bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); 
       out.flush(); 
       out.close(); 

      } catch (IOException ex) { 

      } finally { 

      } 
} 

回答

0

該循環看起來不正確。下面是這個循環是如何預計:

int frame_count = grabber.getLengthInFrames(); 
for (int i=0; i<frame_count; i+=grabber.getFrameRate()) 
+0

每次仍然得到同樣的框架,雖然deluging的價值我遞增時,理所應當的,但輸出圖像是一樣的,每次 – AlphabateCoder

+0

目前尚不清楚如何你生成'file_name'。可能你不會爲每一幀創建一個新文件。 –

+0

感謝Alex現在根據需要獲取所有框架。但問題在於延遲,每秒只能獲得2幀。 – AlphabateCoder

相關問題