gi 라이브러리를 사용하여 gstreamer 파이프 라인을 Python 코드로 변환하려고합니다.
다음은 터미널에서 성공적으로 실행중인 파이프 라인입니다.
gst-launch-1.0 rtspsrc location="rtsp://admin:[email protected]:554/H264?ch=1&subtype=0&proto=Onvif" latency=300 ! rtph264depay ! h264parse ! nvv4l2decoder drop-frame-interval=1 ! nvvideoconvert ! video/x-raw,width=1920,height=1080,formate=I420 ! queue ! nveglglessink window-x=0 window-y=0 window-width=1080 window-height=720
그러나 파이썬 코드를 사용하여 동일한 파이프 라인을 실행하는 동안 rtsp 스트림을 표시하는 출력 창이없고 터미널에 오류도 없습니다. 터미널은 ctrl + c를 누를 때까지 멈췄습니다.
다음은 gstreamer 명령을 실행하는 데 사용하는 코드입니다.
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst, GObject
def main(device):
GObject.threads_init()
Gst.init(None)
pipeline = Gst.Pipeline()
source = Gst.ElementFactory.make("rtspsrc", "video-source")
source.set_property("location", device)
source.set_property("latency", 300)
pipeline.add(source)
depay = Gst.ElementFactory.make("rtph264depay", "depay")
pipeline.add(depay)
source.link(depay)
parse = Gst.ElementFactory.make("h264parse", "parse")
pipeline.add(parse)
depay.link(parse)
decoder = Gst.ElementFactory.make("nvv4l2decoder", "decoder")
decoder.set_property("drop-frame-interval", 2)
pipeline.add(decoder)
parse.link(decoder)
convert = Gst.ElementFactory.make("nvvideoconvert", "convert")
pipeline.add(convert)
decoder.link(convert)
caps = Gst.Caps.from_string("video/x-raw,width=1920,height=1080,formate=I420")
filter = Gst.ElementFactory.make("capsfilter", "filter")
filter.set_property("caps", caps)
pipeline.add(filter)
convert.link(filter)
queue = Gst.ElementFactory.make("queue", "queue")
pipeline.add(queue)
filter.link(queue)
sink = Gst.ElementFactory.make("nveglglessink", "video-sink")
sink.set_property("window-x", 0)
sink.set_property("window-y", 0)
sink.set_property("window-width", 1280)
sink.set_property("window-height", 720)
pipeline.add(sink)
queue.link(sink)
loop = GObject.MainLoop()
pipeline.set_state(Gst.State.PLAYING)
try:
loop.run()
except:
pass
pipeline.set_state(Gst.State.NULL)
if __name__ == "__main__":
main("rtsp://admin:[email protected]:554/H264?ch=1&subtype=0&proto=Onvif")
실수가 무엇인지 아는 사람이 있습니까? 감사합니다!
작동하지 않는 이유는 rtspsrc
의 소스 패드가 소위 "가끔 패드" 이기 때문 입니다. 여기에있는 링크는이를 아주 잘 설명하지만 기본적으로 rtspsrc
RTSP 서버에서 제공하는 SDP에 따라 달라지기 때문에 에서 사용할 수있는 패드 수를 미리 알 수 없습니다 .
따라서의 "pad-added"
신호를 들어야 합니다 rtspsrc
. 여기서 나머지 파이프 라인을 콜백에 방금 나타난 소스 패드에 연결할 수 있습니다.
요약하면 다음과 같습니다.
def main(device):
GObject.threads_init()
Gst.init(None)
pipeline = Gst.Pipeline()
source = Gst.ElementFactory.make("rtspsrc", "video-source")
source.set_property("location", device)
source.set_property("latency", 300)
source.connect("pad-added", on_rtspsrc_pad_added)
pipeline.add(source)
# We will add/link the rest of the pipeline later
loop = GObject.MainLoop()
pipeline.set_state(Gst.State.PLAYING)
try:
loop.run()
except:
pass
pipeline.set_state(Gst.State.NULL)
def on_rtspsrc_pad_added(rtspsrc, pad, *user_data):
# Create the rest of your pipeline here and link it
depay = Gst.ElementFactory.make("rtph264depay", "depay")
pipeline.add(depay)
rtspsrc.link(depay)
# and so on ....
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다