mapbox / mapbox-vision-android

Other
50 stars 43 forks source link

Record video (in my own code) while VisionManager is running #260

Open billylo1 opened 3 years ago

billylo1 commented 3 years ago

Given the VisionManager.startRecording is for debugging only, I am trying to find a simple way to record the video using my own code.

I used Google's Camera2 video recorder sample as starting point. https://github.com/googlearchive/android-Camera2Video

And then add the VisionManager start into onResume().

The result is somewhat strange... it seems to work initially, but after 5 minutes. The app crashes with this in logcat.

Any hints on how to do my own video recording?

thanks,

2020-11-18 23:40:43.768 31462-31703/com.katlalabs.sidekick I/MediaCodec: (0x797a890200) start
2020-11-18 23:40:43.784 31462-847/com.katlalabs.sidekick I/MediaCodec: (0x797a890200) kWhatStartCompleted
2020-11-18 23:40:43.793 31462-31703/com.katlalabs.sidekick E/AndroidRuntime: FATAL EXCEPTION: RecorderThread
    Process: com.katlalabs.sidekick, PID: 31462
    java.lang.RuntimeException: Error loading texture.
        at com.mapbox.vision.utils.GlUtils.createTexture(GlUtils.kt:197)
        at com.mapbox.vision.gl.GLBackgroundFrame.createTexture(GLBackgroundFrame.kt:29)
        at com.mapbox.vision.video.videosource.recording.MediaEncoderWrapper.<init>(MediaEncoderWrapper.kt:82)
        at com.mapbox.vision.video.videosource.recording.Camera2VideoSourceRecorderImpl.initEncoderWrapper(Camera2VideoSourceRecorderImpl.kt:28)
        at com.mapbox.vision.video.videosource.recording.Camera2VideoSourceRecorderImpl.access$initEncoderWrapper(Camera2VideoSourceRecorderImpl.kt:7)
        at com.mapbox.vision.video.videosource.recording.Camera2VideoSourceRecorderImpl$startRecording$1.invoke(Camera2VideoSourceRecorderImpl.kt:69)
        at com.mapbox.vision.video.videosource.recording.Camera2VideoSourceRecorderImpl$startRecording$1.invoke(Camera2VideoSourceRecorderImpl.kt:7)
        at com.mapbox.vision.utils.threads.WorkThreadHandler$post$1.run(WorkThreadHandler.kt:19)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:241)
        at android.os.HandlerThread.run(HandlerThread.java:67)
yunikkk commented 3 years ago

Hey @billylo1, is the question still relevant? At the moment we don't have simple way to record video aside from startRecording. The Google's Camera2 video recorder app open's camera inside, and we also open camera in Vision, so I guess it have a lot of conflicts and isn't going to work stable anyway. Could you describe your use case more?

billylo1 commented 3 years ago

Hi, This is what I built for iOS. sidekick-app.com. Mapbox vision can coexist with standard camera api there... hoping to do the same thing on Android.

Cosxin commented 3 years ago

I had the same issue and I found a walkaround. Since you have your own recording I am assuming you have a previewView sort of thing. So instead of creating the VisionManager and attaching it to the camera, you can attach it to a customVideoSource VisionManager.create(customVideoSource) and from the customVideoSource you fetch the bitmap from your previewView on a fixed timed interval (To do this you need to post message to UIThread).

This allows you to decouple the detection fps from the UI fps.

billylo1 commented 3 years ago

thanks! Let me give it a try.