Gstreamer Pipeline 从未将状态设置为 PLAYING

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

我一直在尝试通过使用 appsrc 的 gstreamer 管道发送从其他程序收到的图像,但是该管道似乎永远不会达到 PLAYING 状态。这是我的代码。抱歉,如果我做错了什么,这是我的第一篇文章。

#import buscaminas
import time
import VideoReceiver
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject

destination_ip = "127.0.0.1"
destination_port = "7070"

def on_playing(bus, message, pipeline):
    if message.type == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        print("Error:", err, debug)
        pipeline.set_state(Gst.State.NULL)
    elif message.type == Gst.MessageType.STATE_CHANGED:
        if message.src == pipeline:
            old_state, new_state, pending_state = message.parse_state_changed()
            if new_state == Gst.State.PLAYING:
                print("Pipeline is now in PLAYING state")

def update_image():

    while True:
        if not Receiver.frame_available():
            continue

        frame = Receiver.frame()
        #buscaminas.run(frame)
        image_data = frame.tobytes()
        ret = appsrc.emit("push-buffer", Gst.Buffer.new_wrapped(image_data))
        print(ret)
        time.sleep(1)

if __name__ == '__main__':
    
    Receiver = VideoReceiver.VideoReceiver()
    
    Gst.init(None)

    pipeline = Gst.parse_launch(
        f"appsrc name=source emit-signals=True is-live=True ! videoconvert ! autovideosink "
        #f"appsrc name=source ! videoconvert ! videoscale ! video/x-raw,width=480,height=360 ! tee name=t "
        #f"t. ! queue ! nvvidconv ! omxh264enc ! video/x-h264,stream-format=byte-stream ! rtph264pay ! udpsink host={destination_ip} port={destination_port} "
    )
    appsrc = pipeline.get_by_name("source")

    bus = pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect("message", on_playing, pipeline)

    pipeline.set_state(Gst.State.PLAYING)

    loop = GObject.MainLoop()

    GObject.idle_add(update_image)

    try:
        loop.run()
    except KeyboardInterrupt:
        loop.quit()
        pipeline.set_state(Gst.State.NULL)

   

我尝试使用不同的线程、不同的管道,我确保我正在从 VideoReceiver 接收图像。预先感谢。

python pipeline gstreamer
1个回答
0
投票

您是否尝试在

queue
之后添加
appsrc
元素?

pipeline = Gst.parse_launch(
    f"appsrc name=source emit-signals=True is-live=True ! queue ! videoconvert ! autovideosink "
© www.soinside.com 2019 - 2024. All rights reserved.