elsampsa / valkka-core

Valkka - Create video surveillance, management and analysis programs with PyQt
GNU Lesser General Public License v3.0
181 stars 35 forks source link

The FrameFifo class lacks python bindings for public functions #3

Closed i-agrawal closed 5 years ago

i-agrawal commented 5 years ago

Thanks for writing the library! I am writing this because there seems to be an issue with the python bindings for the FrameFifo class.

Here is my source code

from valkka.core import *

if __name__ == '__main__':
    url = 'rtsp://localhost/media/1/1/Profile1'

    fifo_queue = FrameFifo('fifo_queue')
    fifo_filter = FifoFrameFilter('fifo_filter', fifo_queue)
    ctx = LiveConnectionContext(LiveConnectionType_rtsp, url, 1, fifo_filter)
    live_thread = LiveThread('live_thread')

    live_thread.startCall()
    live_thread.registerStreamCall(ctx)
    live_thread.playStreamCall(ctx)

    while True:
        frame = fifo_queue.read()
        print(frame)

    live_thread.stopCall()

The resulting error traceback

Traceback (most recent call last):
  File "test_fifo.py", line 17, in <module>
    frame = fifo_queue.read()
  File "/usr/lib/python3/dist-packages/valkka/core/valkka_core.py", line 558, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, FrameFifo, name)
  File "/usr/lib/python3/dist-packages/valkka/core/valkka_core.py", line 80, in _swig_getattr
    raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
AttributeError: 'FrameFifo' object has no attribute 'read'

The error seems to stem from swig being unable to the find the attribute "read" so my first thought is it has to do with the python bindings. Thanks for any response.

elsampsa commented 5 years ago

Hi Ishan,

Unfortunately FrameFifo is not part of the Python API, and you're not supposed to use it the way you're describing.

For receiving decoded frames at your Python code, you should use the shared-memory infrastructure instead. How to do this, please refer to the tutorial.

Some more info of what goes on "under-the-hood":

i-agrawal commented 5 years ago

Hi Sampsa,

Thanks for the response. I can understand why you set it up in this fashion. Perhaps you could point me in the right direction for what I am trying to do.

I am using the RGBShmemFrameFilter and ShmemRGBClient to pass read images from an rtsp feed to the python process. There are no problems there, I can get the numpy arrays just fine. But I also want the timestamp along with the image's numpy array. Is there a way to do this in the python api?

elsampsa commented 5 years ago

Ok, I get it.

The problem with the current shared memory implementation is, that it in addition to the payload, the only metadata it provides, is the payload size.

But it's your lucky day! If you look at the latest commits in the development branch, you can see that @eranpet has been working recently (last week actually) on the shared memory implementation.

That new shared memory implementation will provide additional metadata, namely, the millisecond timestamp, slot number and width & height of the image, so you'll get all you need.

These changes should appear in the main branch and in a new libValkka version next week, right, @eranpet ?

i-agrawal commented 5 years ago

Cool that sounds super useful and close to what I need. Thanks for your help so far!

elsampsa commented 5 years ago

The new version 0.12.0 is out & build system is still churning through the compilation here

After that's finished, please update everything and read the new api example here

bobbych commented 5 years ago

@elsampsa thanks for the awesome library. There seem to be very latency 400-500ms per frame when using ShmemRGBClient. We have experienced this before on 0.11.0 as well, changing it to use SharedMemRingBuffer fixed that. Any help is appreciated

elsampsa commented 5 years ago

@bobbych could you please open a separate ticket for your question. Please give more details. I didn't get it.. is the live stream showing latency issues when you're using ShmemRGBClient ..? How is your filtergraph? etc.