google-research / CVD-paper-mobile-camera-example

Apache License 2.0
37 stars 9 forks source link

Exception when using sensor manager to record video and output generated by sensor manager are multiple images in place of video file #118

Open karansihcl opened 2 months ago

karansihcl commented 2 months ago

Camera sensor throwing exception every time, when starting sensor manager for VideoRequest.

Also output generated by sensor manager for video recording contain multiple images. But expected output is a single video file in place of images.

Exception logs:

FATAL EXCEPTION: main
Process: com.abc.xyz, PID: 783
java.io.FileNotFoundException: /data/user/0/com.abc.xyz/files/tbapp/recordings_2024-09-06T10:56:44.406777Z/1_1725620204772.video/mp4v-es: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at com.google.android.sensing.capture.sensors.CameraSensor$saveImage$2.invokeSuspend(CameraSensor.kt:285)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@44ef58f, Dispatchers.Main.immediate]
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

Initialisation code:

sensorManager.start(
                    InternalSensorType.CAMERA,
                    CameraCaptureRequest.VideoRequest(
                        externalIdentifier = "Patient1",
                        outputFolder = "outputFolderName",
                        outputTitle = "Video",
                        outputFormat = "video/mp4v-es",
                        bufferCapacity = Int.MAX_VALUE
                    )
                )
MJ1998 commented 2 months ago

Thanks for pointing this out. The current CameraSensor implementation does not support VideoRequests right now so I'll add code to properly handle this exception. However this CameraSensor implementation is just a sample implementation and we encourage you to set up your own Sensor interface's implementation for whichever Sensor you want to work with. More details in the Sensor interface kdoc.

You can write your own CameraSensor implementation and register it with the Sensing library using api registerSensorFactory. Then use generic apis of SensorManager to capture using your sensor implementation.