我希望扩展Kivy's视频小部件的功能。
使用以下RTSP代码播放RTSP视频流时,延迟时间为几秒钟。我想将延迟减少到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视频模块的行为,以允许传递“拖放-延迟=真”和"latency=100“参数。
相关的Kivy源代码在这里:gstplayer.pyx#L237-L256
Q1.如何子类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)注意:试图编译上述代码是不成功的。这是伪码。
Q2.如何将上述子类集成为视频小部件的CoreVideo提供程序?
发布于 2019-01-16 00:55:48
以下提交提供了一个硬编码的解决方案来指定延迟值和拖放延迟值: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的视频小部件中传递延迟和拖放延迟的值。有人能建议如何使这件事成功吗?
https://stackoverflow.com/questions/54175833
复制相似问题