Android Question CameraEx_Preview FPS

peacemaker

Expert
Licensed User
Longtime User
HI, All

If to measure (by NanoTime lib) the FPS of _Preview events - i can get 10 ... 18 fps max.
Tried to use various settings among:
B4X:
        camEx.SetJpegQuality(90)
        camEx.CancelAutoFocus
        camEx.SetPreviewSize(videoW, videoH)  'here 320x240 really
        camEx.SetPreviewFpsRange(30000, 30000)   'for sure supported values in GetSupportedPreviewFpsRange list
'        camEx.SetPreviewFrameRate(30)
'        camEx.SetParameter("camera-mode", "1")
'        camEx.SetParameter("cam-mode","1")
'        camEx.SetParameter("cam_mode","1")
        camEx.setRecordingHint
        camEx.CommitParameters
        'Log("StartPreview 1")
        camEx.StartPreview

No help. Camera indeed support 30 FPS of preview, but ... how to reach ?
 

JordiCP

Expert
Licensed User
Longtime User
Some things I would check
  • Do FPS measurements vary between a day-light scene and an interior low-light? --> if so, try to set "setAutoWhiteBalanceLock" and "setAutoExposureLock" to true (if supported), and see if results improve in low-light scenes.
  • Also, from another post in this forum the user did get better results with a smaller preview panel (or hiding it totally if what you want is to process it).
  • Internally, camera allows to work with queued preview buffers so that after one is 'released' to the preview event, an alternative one is used in order to prevent the preview code to delay it --> this would only be needed if the FPS drop is due to the processing delay due to what is done in the preview event.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
try to set "setAutoWhiteBalanceLock" and "setAutoExposureLock" to true
Tried, no help

B4X:
Public Sub SetRecordingHint(v As Boolean)
    r.target = parameters
    r.RunMethod2("setRecordingHint", v, "java.lang.boolean")
End Sub

Public Sub SetAutoWhiteBalanceLock(v As Boolean)
    r.target = parameters
    r.RunMethod2("setAutoWhiteBalanceLock", v, "java.lang.boolean")
End Sub

Public Sub SetAutoExposureLock(v As Boolean)
    r.target = parameters
    r.RunMethod2("setAutoExposureLock", v, "java.lang.boolean")
End Sub

a smaller preview panel
Yes, it was and is always used, small panel

camera allows to work with queued preview buffers so that after one is 'released' to the preview event
I only save the preview Bitmap (and later get it by a timer when needed):
B4X:
Sub Camera1_Preview (Data() As Byte)
    Dim dataJpg() As Byte, iSt As InputStream
    Try
        dataJpg = camEx.PreviewImageToJpeg(Data, 80)
        iSt.InitializeFromBytesArray(dataJpg, 0, dataJpg.Length)
    Catch
        Dim a As String = "PreviewImageToJpeg.error=" & LastException.Message
        ToastMessageShow("Camera is not supported: " & a, True)
        Log(a)
        camEx.Release
        Stop_Camera
        Return
    End Try
    Dim img As Bitmap
    img.Initialize2(iSt)
    PreviewImg = img
    NanoTime1 = NanoTime2
    NanoTime2 = nt.NanoTime
 
    Try
        camEx.StartPreview
    Catch
        Log(LastException)
    End Try
End Sub


Sub timInterval_Tick
    If PreviewImg.IsInitialized Then
        pnlRes.SetBackgroundImage(PreviewImg)
    End If
    Dim TimeBetweenPreviews As Double = NanoTime2 - NanoTime1
    TimeBetweenPreviews = TimeBetweenPreviews / 1000000
    Log(TimeBetweenPreviews)
    Dim FPS1 As Float = 1/TimeBetweenPreviews*1000
    Dim FPS2 As Float = 1/timInterval.Interval*1000
    lblResult.Text = "FPS1=" & NumberFormat(FPS1, 1, 1) & ", FPS2=" & NumberFormat(FPS2, 1, 1)
End Sub

And moreover - if not to convert and save YUV source into JPG and just StartPreview again immediately - no speed change !
 
Last edited:
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
And moreover - if not to convert and save YUV source into JPG and just StartPreview again immediately - no speed change !
Not sure how it affects, but there's no need at all to call startPreview inside the preview_event. It should only be called once unless it has been stopped, a picture taken, or the camera initted again.

Also, saving every preview frame is a bit "hard". What is exactly the purpose of the code? --> Anyway, I would first focus to increase "as much as possible" the FPS with an empty preview_event, and then see how the added actions affect.
 
Upvote 0
Top