錄像:過時的方法setPreviewFrameRate 替代辦法

setPreviewFrameRate是在api level1就開始使用了,然後不是簡單地設置這個方法就可以讓攝像頭每秒捕獲多少幀數的。
比如我設置2,它一秒不會只捕獲2幀數據的,從日誌記錄來看,相當糟糕,不會是預期的2幀,於是我查找文檔,發現這個方法已經廢除了。

在api level9時加入了一個方法setPreviewFpsRange (int min, int max)
預覽幀數從min到max,這個值再*1000.
這個方法已經在高版本的sdk中取代了舊的setPreviewFrameRate。

如何知道攝像頭的預覽範圍呢?我原以爲從1到n,其實不然。
getSupportedPreviewFpsRange()這個方法就可以顯示出你的手機攝像頭支持的範圍。
Java代碼  收藏代碼
  1. List<int[]> range=parameters.getSupportedPreviewFpsRange();  
  2.         Log.d(TAG, "range:"+range.size());  
  3.         for(int j=0;j
  4.             int[] r=range.get(j);  
  5.             for(int k=0;k
  6.                 Log.d(TAG, TAG+r[k]);  
  7.             }  
  8.         }  

如i9000會是7-30而不是1-30.。。
所以在Camera.PreviewCallback回調中,onPreviewFrame會得到的幀數就不會小於7了。

我還一直以爲預覽幀數是2,看到的畫面還是很流暢。。。

Java代碼  收藏代碼
  1. 文檔裏還有這麼一段話:  
  2. Gets the supported preview fps (frame-per-second) ranges. Each range contains a minimum fps and maximum fps. If minimum fps equals to maximum fps, the camera outputs frames in fixed frame rate. If not, the camera outputs frames in auto frame rate. The actual frame rate fluctuates between the minimum and the maximum. The values are multiplied by 1000 and represented in integers. For example, if frame rate is 26.623 frames per second, the value is 26623.  
  3.   
  4. 如果最大值與最小值是一樣的,就是以這個值輸出預覽,如果不同,則會以這個區間自動輸出。  
  5. 看上去,預覽幀數還是不可控制的啊 
發佈了34 篇原創文章 · 獲贊 39 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章