Gstreamer 插件从未被调用

问题描述 投票:0回答:1

以下 Python Gstreamer 插件如何正确初始化,并且数据流过它(请参阅附加管道),除了

__init__
函数中的打印之外,不打印任何内容?

import logging
import timeit
import math
import traceback
import time
import cv2

import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstBase', '1.0')
gi.require_version('GstVideo', '1.0')

from gi.repository import Gst, GObject, GLib, GstBase, GstVideo  # noqa:F401,F402

from gstreamer.utils import gst_buffer_with_caps_to_ndarray


Gst.init(None)

logger = logging.getLogger(__name__)


class GstDropFrames(GstBase.BaseTransform):

    GST_PLUGIN_NAME = 'gstdropframes'

    __gstmetadata__ = (
        "GstDropFrames",
        "Transform",
        "Drop frames when the pipeline can't consume them all",
        "author"
    )

    __gsttemplates__ = (
        Gst.PadTemplate.new(
            "src",
            Gst.PadDirection.SRC,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.new_any(),
        ),
        Gst.PadTemplate.new("sink",
            Gst.PadDirection.SINK,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.new_any(),
        )
    )

    __gproperties__ = {}

    def __init__(self):
        super(GstDropFrames, self).__init__()
        print("PLUGIN Initialized GstDropFrames")

    def do_prepare_output_buffer(self, inbuf):
        print("PLUGIN do_prepare_output_buffer")
        buf = Gst.Buffer.new()
        buf.copy_into(inbuf, Gst.BufferCopyFlags.FLAGS | Gst.BufferCopyFlags.TIMESTAMPS |
            Gst.BufferCopyFlags.META | Gst.BufferCopyFlags.MEMORY, 0, inbuf.get_size())
        buf.pts = inbuf.pts
        return (Gst.FlowReturn.OK, buf)

    def do_transform(self, inbuf, outbuf):
        print("PLUGIN do_transform")
        # outbuf.copy_into(inbuf, Gst.BufferCopyFlags.FLAGS | Gst.BufferCopyFlags.TIMESTAMPS |
        #     Gst.BufferCopyFlags.META | Gst.BufferCopyFlags.MEMORY, 0, inbuf.get_size())
        return Gst.FlowReturn.OK

    def do_transform_ip(self, buffer: Gst.Buffer) -> Gst.FlowReturn:
        print("PLUGIN do_transform_ip")
        return Gst.FlowReturn.OK



# Register plugin to use it from command line
GObject.type_register(GstDropFrames)
__gstelementfactory__ = (
    GstDropFrames.GST_PLUGIN_NAME,
    Gst.Rank.NONE,
    GstDropFrames
)

管道:https://drive.google.com/file/d/1Vu8DR1Puam14k-fUKVBW2bG1gN4AgSPm/view?usp=sharing

python plugins gstreamer
1个回答
0
投票

我找到了上述问题的解决方案,如果我们在任何其他元素/插件之前创建自定义 Python 插件,那么 Python 应用程序就可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.