yoe*_*oel 5 cython python-3.x gstreamer-1.0
我使用 Python3.6 与GStreamer-1.0和PyGObject (用于 python 访问)从相机( tiscamera )读取视频帧。
这些帧是通过 python 代码获取的,最终我得到了一个 GstBuffer:
import gi
gi.require_version("Gst", "1.0")
from gi.repository import
# Set up
Gst.init([])
pipeline = Gst.parse_launch("tcambin serial=12345678 name=source ! video/x-raw,format=GRAY8,width=1920,height=1080,framerate=18/1 ! appsink name=sink")
sink = pipeline.get_by_name("sink")
sink.set_property("max-buffers", 10)
sink.set_property("drop", 1)
sink.set_property("emit-signals", 1)
pipeline.set_state(Gst.State.PLAYING)
# Get sample
sample = sink.emit("pull-sample")
buffer = sample.get_buffer()
meta = buffer.get_meta("TcamStatisticsMetaApi")
Run Code Online (Sandbox Code Playgroud)
元的类型是 gi.repository.Gst.Meta,但在 C 中它实际上是 TcamStatisticsMeta*,可以通过查看 tiscamera 的 c 代码示例10-metadata.c来理解。那里的C代码是:
GstBuffer* buffer = gst_sample_get_buffer(sample);
GstMeta* meta = gst_buffer_get_meta(buffer, g_type_from_name("TcamStatisticsMetaApi"));
GstStructure* struc = ((TcamStatisticsMeta*)meta)->structure;
Run Code Online (Sandbox Code Playgroud)
我的问题是,在 Python 中,我无法访问TcamStatisticsMeta. 我只是缺少从 GstMeta* 到 TcamStatisticsMeta* 的转换位以及将 TcamStatisticsMeta* 转换为 PyObject 的转换。
有谁知道如何在不需要修改/重新编译 gstreamer-1.0 C 代码的情况下完成此操作吗?也许使用 Cython?
我开始使用 Cython 尝试使用从 Python 获得的数据调用 C 函数。python 对象是类型gi.repository.Gst.Buffer,函数应该获取 a GstBuffer*,但我找不到从 Python 对象获取结构指针的方法。
这是我的 .pxd 文件:
cdef extern from "gstreamer-1.0/gstmetatcamstatistics.h":
ctypedef unsigned long GType
ctypedef struct GstBuffer:
pass
ctypedef struct GstMeta:
pass
GstMeta* gst_buffer_get_meta(GstBuffer* buffer, GType api)
GType g_type_from_name(const char* name)
Run Code Online (Sandbox Code Playgroud)
我的 .pyx 文件:
from my_pxd_file cimport GType, g_type_from_name, GstMeta, gst_buffer_get_meta
cdef void c_a(buffer):
cdef char* tcam_statistics_meta_api = "TcamStatisticsMetaApi"
cdef GType gt = g_type_from_name(tcam_statistics_meta_api)
cdef GstMeta* meta = gst_buffer_get_meta(buffer, gt)
def a(buffer):
c_a(buffer)
Run Code Online (Sandbox Code Playgroud)
还有我的 python 文件:
# No need to use pyximport as I've cythonized the code in setup.py
from . import my_pyx_file
...
buffer = sample.get_buffer()
my_pyx_file.a(buffer)
Run Code Online (Sandbox Code Playgroud)
这会导致 SIGSEGV 错误:
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
Run Code Online (Sandbox Code Playgroud)
问题是我无法将缓冲区转换为 GstBuffer*。有谁知道这是怎么做到的吗?
在Pycharm中调试,我实际上可以看到GstBuffer*地址:
<Gst.Buffer object at 0x7f3a0b4fc348 (GstBuffer at 0x7f39ec007060)>
Run Code Online (Sandbox Code Playgroud)
但是我如何获得这个地址以便将其传递给gst_buffer_get_meta?有规范的 Cython 方法来做到这一点吗?
| 归档时间: |
|
| 查看次数: |
633 次 |
| 最近记录: |