-1

I was trying to capture a video in kivy/android using camera4kivy. but it seems that this function won't work. I tried capture video with location, subdir and filename (kwarg**) but still nothing happend.

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from camera4kivy.preview import Preview

class CamApp(App):

    def build(self):

        self.cam = Preview()

        self.cam.connect_camera(enable_analyze_pixels=True)
        self.cam.select_camera('1')

        box1 = BoxLayout()
        box1.add_widget(self.cam)

        try:
            self.cam.capture_video(location = 'shared', subdir='myapp', name='myvid')
        except Exception as e: print(e)

        return box1
 
    def on_stop(self):
        self.cam.disconnect_camera()
        return super().on_stop()


if __name__ == '__main__':
    CamApp().run()

07-21 16:17:14.405 28320 29758 I python : JVM exception occurred: Attempt to invoke virtual method 'void androidx.camera.core.VideoCapture.startRecording(androidx.camera.core.VideoCapture$OutputFileOptions, java.util.concurrent.Executor, androidx.camera.core.VideoCapture$OnVideoSavedCallback)' on a null object reference java.lang.NullPointerException 07-21 16:17:14.406 28320 28320 I python : Traceback (most recent call last): 07-21 16:17:14.406 28320 28320 I python : File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/android/runnable.py", line 38, in run 07-21 16:17:14.407 28320 28320 I python : File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/camera4kivy/preview_camerax.py", line 289, in do_select_camera 07-21 16:17:14.407 28320 28320 I python : File "jnius/jnius_export_class.pxi", line 857, in jnius.jnius.JavaMethod.call 07-21 16:17:14.407 28320 28320 I python : File "jnius/jnius_export_class.pxi", line 954, in jnius.jnius.JavaMethod.call_method 07-21 16:17:14.407 28320 28320 I python : File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception 07-21 16:17:14.407 28320 28320 I python : jnius.jnius.JavaException: JVM exception occurred: Attempt to invoke virtual method 'void androidx.camera.lifecycle.ProcessCameraProvider.unbindAll()' on a null object reference java.lang.NullPointerException 07-21 16:17:14.408 28320 29758 I python : [WARNING] [Base ] Unknown provider 07-21 16:17:14.408 28320 29758 I python : [INFO ] [Base
] Start application main loop 07-21 16:17:14.411 28320 29758 I python : [INFO ] [Base ] Leaving application in progress... 07-21 16:17:14.412 28320 29758 I python : Traceback (most recent call last): 07-21 16:17:14.412 28320 29758 I python : File "/home/testapp/.buildozer/android/app/main.py", line 31, in 07-21 16:17:14.412 28320 29758 I python : File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/kivy/app.py", line 955, in run 07-21 16:17:14.412 28320 29758 I python : File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/kivy/base.py", line 574, in runTouchApp 07-21 16:17:14.413 28320 29758 I python :
File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/kivy/base.py", line 339, in mainloop 07-21 16:17:14.413 28320 29758 I python :
File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/kivy/base.py", line 391, in idle 07-21 16:17:14.413 28320 29758 I python : File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/kivy/clock.py", line 783, in tick_draw 07-21 16:17:14.414 28320 29758 I python :
File "kivy/_clock.pyx", line 662, in kivy._clock.CyClockBase._process_events_before_frame 07-21 16:17:14.414 28320 29758 I python : File "kivy/_clock.pyx", line 708, in kivy._clock.CyClockBase._process_events_before_frame 07-21 16:17:14.414 28320 29758 I python : File "kivy/_clock.pyx", line 704, in kivy._clock.CyClockBase._process_events_before_frame 07-21 16:17:14.414 28320 29758 I python : File "kivy/_clock.pyx", line 218, in kivy._clock.ClockEvent.tick 07-21 16:17:14.414 28320 29758 I python : File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/kivy/uix/anchorlayout.py", line 122, in do_layout 07-21 16:17:14.415 28320 29758 I python :
File "kivy/properties.pyx", line 520, in kivy.properties.Property.set 07-21 16:17:14.415 28320 29758 I python : File "kivy/properties.pyx", line 1478, in kivy.properties.ReferenceListProperty.set 07-21 16:17:14.415 28320 29758 I python : File "kivy/properties.pyx", line 606, in kivy.properties.Property._dispatch 07-21 16:17:14.415 28320 29758 I python : File "kivy/_event.pyx", line 1307, in kivy._event.EventObservers.dispatch 07-21 16:17:14.416 28320 29758 I python : File "kivy/_event.pyx", line 1213, in kivy._event.EventObservers._dispatch 07-21 16:17:14.416 28320 29758 I python : File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/camera4kivy/preview_camerax.py", line 159, in on_size 07-21 16:17:14.416 28320 29758 I python :
File "/home/testapp/.buildozer/android/platform/build-arm64-v8a/build/python-installs/test/arm64-v8a/camera4kivy/preview_camerax.py", line 217, in stop_capture_video 07-21 16:17:14.416 28320 29758 I python : File "jnius/jnius_export_class.pxi", line 857, in jnius.jnius.JavaMethod.call 07-21 16:17:14.417 28320 29758 I python : File "jnius/jnius_export_class.pxi", line 954, in jnius.jnius.JavaMethod.call_method 07-21 16:17:14.417 28320 29758 I python : File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception 07-21 16:17:14.417 28320 29758 I python : jnius.jnius.JavaException: JVM exception occurred: Attempt to invoke virtual method 'void androidx.camera.core.VideoCapture.stopRecording()' on a null object reference java.lang.NullPointerException 07-21 16:17:14.417 28320 29758 I python : Python for android ended. 07-21 16:17:14.540 28320 29758 F com.moria.test: mutex.cc:340] destroying mutex with owner or contenders. Owner:29737 07-21 16:17:14.541 28320 29737 F com.moria.test: debugger_interface.cc:356] Check failed: removed_it == removed_entries.end()

  • aalways put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Jul 21 '22 at 11:33
  • is this all your code? What do you expect for this code? GUIs usually need more code - they have to run `event loop` which runs all functions in GUIs. If you have more code then better show minimal working code with this problem. Maybe problem is in different place. – furas Jul 21 '22 at 11:35
  • @furas I want to learn and this is my test code, all of my code. and i wasn't able to edit my question with traceback but i have managed it like this. – Mohammad Mujtaba Oria Jul 21 '22 at 11:53
  • error message shows in few places `on a null object reference` which may suggest that it couldn't detect/access camera. Do you run it on real phone with Android or on emulator? – furas Jul 21 '22 at 12:45
  • https://stackoverflow.com/questions/14910065/accessing-android-camera-through-kivy – Amin Etesamian Jul 21 '22 at 13:05
  • @Juggernaut it's about taking picture but i want to record video, taking picture with this module is perfect but cant capture video – Mohammad Mujtaba Oria Jul 21 '22 at 15:40

2 Answers2

0

Kivy does not support encoding video and saving it into a file. It only supports playing video from camera widget.

Amin Etesamian
  • 3,363
  • 5
  • 27
  • 50
0

The documentation/README of Camera4Kivy says, the preview.connect_camera method can only be called after on_start.

You are calling the connect_camera during the build.

You might want to look at the example of using camera4kivy here for more information on how to use it.

unlockme
  • 3,897
  • 3
  • 28
  • 42