在ImageReader.OnImageAvailableListener
回调中,我只使用SystemClock.elapsedRealtime()
来计算获取fps的帧间隔,并打印出来:
fps = 27.777779
fps = 34.482758
fps = 27.777779
fps = 32.258064
fps = 14.285714
fps = 35.714287
fps = 30.30303
fps = 17.54386
fps = 125.0
所以我的问题是,实际的fps是否只是那样波动?如果是这样,有没有可靠的方法来修复帧速率,假设我只需要它以15或20fps的速度传输。是可以实现还是不可以?
ps:我尝试使用
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, bestFPSRange);
bestFPSRange = [30,30]
,但似乎不起作用。
感谢。
答案 0 :(得分:0)
尝试使用YUV420从ImageReader获取数据: -
ImageReader.newInstance(mWidth,mHeight ,ImageFormat.YUV_420_888, maxImages);
另外,检查你的mWidth和mHeight。
您可以尝试以下方法来测量fps: -
int frameCount=0;
long frameTime=0;
ImageReader.OnImageAvailableListener mImageAvailableRight=new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
try{
Object[] objects=initFPSNew("Measure fps is-->",frameTime,frameCount);
frameTime=(long)objects[0];
frameCount=(int)objects[1];
Image mImage=imageReader.acquireNextImage();
if(mImage!=null){
mImage.close();
}
}catch (Exception exc)
{
exc.printStackTrace();
Log.v(TAG,"Exception Camera2"+ exc.getMessage());
}
}
};
public static Object[] initFPSNew(String message,long startTime,int counter){
Object[] mObjectTime=new Object[2];
if(startTime==0){
startTime=System.currentTimeMillis();
mObjectTime[0]=startTime;
counter+=1;
mObjectTime[1]=counter;
}else{
long difference=System.currentTimeMillis()-startTime;
//We wil check count only after 1 second laps
double seconds = difference / 1000.0;
if(seconds>=1)
{
Log.v(TAGFPS,message+ counter);
counter=0;
mObjectTime[0]=System.currentTimeMillis();
mObjectTime[1]=counter;
}else{
counter++;
mObjectTime[0]=startTime;
mObjectTime[1]=counter;
}
}
return mObjectTime;
}