Android Question Use Camera to record video and stream video at the same time

Roger C

Active Member
Licensed User
Hi All,
I've been searching the forum to see if it is possible to, at the same time, record a Full HD video to the device (as you normally do when shooting video) AND at the same time stream the video (lower fps and resolution is ok) to a browser or any other device. Could be an Android device or a laptop.

I haven't found any posts that do both of them. There are CCTV examples and there are recording examples...

I haven't found an app in the store either that does this. There is one that streams the screen to a client and that could work.

My question is, is it possible to record HD and stream SD at the same time?
If so, what library can I use? Any examples?
Is it possible to start/stop recording, to turn flash on/off remotely?
Stream does not need audio but if possible it would be fine too.

Need to use the camera as an 'eye' on a long stick, to inspect ventilation, inner ceilings, ... I need to record what it sees and I need to see and control it too.

There's a lot of camera libraries and I don't have time and the knowledge to dig deep into all of them so I was hoping to at least get a pointer to which library it is possbile to do this in.

Thanks in advance
 

Roger C

Active Member
Licensed User
Thanks Erel.

But when loading the project from
https://www.b4x.com/android/forum/threads/camera2-new-camera-library.83855/

It crashes when I enter video mode. Doesn't matter if I change VideoMode to True, then it crashes directly.
Stills pictures works fine but videomode does not. But where are the pictures saved? I can't find them in the Gallery?

Camera 2 is version 1.10, CameraEX is 1.20, Android version 8.0.0


B4X:
Logger connected to:  samsung SM-G930F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
FULL
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
** Activity (main) Resume **
Start success: true
(Rect)(0, 0, 4032, 3024)
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Start success: true
(Rect)(0, 0, 4032, 3024)
Focused!
Picture taken: (Bitmap): 1920 x 1080, scale = 1,00
** Activity (main) Pause, UserClosed = false **
Ignoring event: camera_previewcapturecomplete
Ignoring event: camera_previewcapturecomplete
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
** Activity (main) Resume **
camex2_startpreview (java line: 1397)
java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
    at android.hardware.camera2.CaptureRequest.convertSurfaceToStreamId(CaptureRequest.java:582)
    at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:938)
    at android.hardware.camera2.impl.CameraDeviceImpl.setRepeatingRequest(CameraDeviceImpl.java:984)
    at android.hardware.camera2.impl.CameraCaptureSessionImpl.setRepeatingRequest(CameraCaptureSessionImpl.java:238)
    at anywheresoftware.b4a.objects.Camera2.SetRepeatingRequest(Camera2.java:359)
    at b4a.example3.camex2._startpreview(camex2.java:1397)
    at b4a.example3.main$ResumableSub_PrepareSurface.resume(main.java:1005)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:185)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1736)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Application_Error
(IllegalArgumentException) java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
    at android.hardware.camera2.CaptureRequest.convertSurfaceToStreamId(CaptureRequest.java:582)
    at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:938)
    at android.hardware.camera2.impl.CameraDeviceImpl.setRepeatingRequest(CameraDeviceImpl.java:984)
    at android.hardware.camera2.impl.CameraCaptureSessionImpl.setRepeatingRequest(CameraCaptureSessionImpl.java:238)
    at anywheresoftware.b4a.objects.Camera2.SetRepeatingRequest(Camera2.java:359)
    at b4a.example3.camex2._startpreview(camex2.java:1397)
    at b4a.example3.main$ResumableSub_PrepareSurface.resume(main.java:1005)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:185)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1736)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (main) Pause, UserClosed = false **
 
Last edited:

Roger C

Active Member
Licensed User
Sorry but it's the exact same error.
Camera works fine but video preview crashes with error as above.
I haven't changed anything in the code.
Phone is Samsung Galaxy7 with Android 8.0.0

Is it possible Camera2 don't work in this camera?

It's line 156 in CamEx2 that crashes.

B4X:
PreviewRequest = Camera.SetRepeatingRequest(PreviewBuilder)
Error in debug mode:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
FULL
** Activity (main) Resume **
Start success: true
(Rect)(0, 0, 4032, 3024)
Error occurred on line: 156 (CamEx2)
java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
    at android.hardware.camera2.CaptureRequest.convertSurfaceToStreamId(CaptureRequest.java:582)
    at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:938)
    at android.hardware.camera2.impl.CameraDeviceImpl.setRepeatingRequest(CameraDeviceImpl.java:984)
    at android.hardware.camera2.impl.CameraCaptureSessionImpl.setRepeatingRequest(CameraCaptureSessionImpl.java:238)
    at anywheresoftware.b4a.objects.Camera2.SetRepeatingRequest(Camera2.java:359)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
    at b4a.example3.camex2._startpreview(camex2.java:194)
    at b4a.example3.main$ResumableSub_PrepareSurface.resume(main.java:1029)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1736)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 
Last edited:

Roger C

Active Member
Licensed User
Hi,

Tried different supported sizes but no change.

Also tried Camera2 example with 5 different phones.
Sony Xperia with Android 6.0.1 works fine and I get LEGACY

Xperia with Android 7 does not work.
Samsung Galaxy 4,5 and S7 does not work.

Guess this idéa won't work since I don't know what phone the users have...
If there aren't any other suggestions...
Standard Camera Lib?
Btw, the errors are the same as above posts.

I might make this just for me as a fun and useful thing but maybe not.
 
Last edited:
Top