Kivy:将延迟和延迟放置参数传递给GstPlayer视频流小部件

时间:2019-01-14 04:33:42

标签: python override kivy cython gstreamer

我希望扩展Kivy's视频小部件的功能。

使用以下RTSP代码播放Kivy视频流时,会有几秒钟的延迟。我想将等待时间减少到100ms左右。

videostreaming.py:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import os.path

path_to_kv = os.path.join(os.path.dirname(__file__), 'videostreaming.kv')
Builder.load_file(path_to_kv)


class VideoStreaming(BoxLayout):
    pass


class TestApp(App):
    def build(self):
        root_widg = VideoStreaming()
        return root_widg


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

videostreaming.kv:

<VideoStreaming>
    orientation: 'vertical'
    Video:
        source: "rtsp://192.168.1.88:554"
        state: 'play'

可以通过以下命令在命令提示符中实现所需的低延迟:

$ .\gst-launch-1.0 -v playbin uri=rtsp://192.168.1.88:554 drop-on-latency=true latency=100

我想修改Kivy中GstPlayer视频模块的行为,以允许传入“ drop-on-latency = true”和“ latency = 100”参数。

相关的Kivy源代码在这里: https://github.com/kivy/kivy/blame/master/kivy/lib/gstplayer/_gstplayer.pyx#L237-L256

第1季度。如何将GstPlayer Cython模块子类化,以包括对延迟和延迟放置参数的访问?

我认为子类应该重写load()方法,如下所示:

# import GstPlayer module to be subclassed
from kivy.lib.gstplayer cimport GstPlayer

# define subclass
cdef class LowLatencyGst(GstPlayer):

    #override load() method
    def load(self):
        # run parent's load() method
        super(LowLatencyGst, self).load()

        # set required attributes: latency = 100, drop-on-latency = True
        # Unconfirmed whether these commands are correctly named
        g_object_set_int(self.appsink, 'latency', 100)
        g_object_set_int(self.appsink, 'drop-on-latency', 1)

注意:尝试编译以上代码失败。这是伪代码。

第二季度。如何将上述子类集成为Video小部件的CoreVideo提供者?

1 个答案:

答案 0 :(得分:0)

以下提交提供了一种硬编码的解决方案,用于指定延迟和延迟放置值: https://github.com/sabarlow/kivy/commit/846e3147db4ac784c1aa4d02f47666716fb57644

将以下代码行添加到\ kivy \ lib \ gstplayer_gstplayer.pyx:265

g_object_set_int(self.pipeline, 'drop-on-latency', self.drop_on_latency)
g_object_set_int(self.pipeline, 'latency', self.latency)

使用\ kivy \ lib \ gstplayer_gstplayer.pyx:184进行设置

cdef int latency, drop_on_latency

并在同一文件中:

def __init__(self, uri, sample_cb=None, eos_cb=None, message_cb=None, latency=500, drop_on_latency=1):
        super(GstPlayer, self).__init__()
        self.uri = uri
        self.sample_cb = sample_cb
        self.eos_cb = eos_cb
        self.message_cb = message_cb
        self.latency = latency
        self.drop_on_latency = drop_on_latency

然后重新编译Kivy。

这不允许从Kivy的“视频”小部件中传递延迟和延迟放置值。谁能建议如何做这项工作?