0

无法使用 tee 并使用 splitmuxsink 保存视频,下面是代码,我在运行下面的代码段时出现链接错误。我使用 tee 有 2 个接收器(视频保存和 RTSP 流)

nvvidconv_c = "convertor_%u" %index
print("Creating nvvidconv \n ")
nvvidconv = Gst.ElementFactory.make("nvvideoconvert", nvvidconv_c)
if not nvvidconv:
    sys.stderr.write(" Unable to create nvvidconv %u\n", i)

caps_c = "caps1_%u" %index
caps1 = Gst.ElementFactory.make("capsfilter", caps_c)
caps1.set_property("caps", Gst.Caps.from_string("video/x-raw(memory:NVMM), format=I420"))


# Make the encoder
encoder_c = "encoder1_%u" %index
print("Creating H264 Encoder")
encoder1 = Gst.ElementFactory.make("nvv4l2h264enc", encoder_c)
if not encoder1:
    sys.stderr.write(" Unable to create encoder")

encoder1.set_property('bitrate', bitrate)


caps_c = "cap2s_%u" %index
caps2 = Gst.ElementFactory.make("capsfilter", caps_c)
# caps1.set_property("caps", Gst.Caps.from_string("video/x-raw(memory:NVMM), format=I420"))
caps2.set_property("caps", Gst.Caps.from_string("video/x-raw, format=I420"))

encoder_c = "encoder2_%u" %index
print("Creating H264 Encoder")
# encoder2 = Gst.ElementFactory.make("nvv4l2h264enc", encoder_c)
encoder2 = Gst.ElementFactory.make("x264enc", encoder_c)
if not encoder2:
    sys.stderr.write(" Unable to create encoder")

encoder2.set_property('bitrate', bitrate)





# Make the payload-encode video into RTP packets
rtppay_c = "rtppay_%u" %index
rtppay = Gst.ElementFactory.make("rtph264pay", rtppay_c)
print("Creating H264 rtppay")
if not rtppay:
    sys.stderr.write(" Unable to create rtppay")

# Make the UDP sink
updsink_port_num = udp_sink_port_num
updsink_port_num += index
print("\n updsink_port_num = %u", updsink_port_num)
udpsink_c = "udpsink_%u" %index
sink = Gst.ElementFactory.make("udpsink", udpsink_c)
if not sink:
    sys.stderr.write(" Unable to create udpsink")

sink.set_property('host', '224.224.255.255')
sink.set_property('port', updsink_port_num)
sink.set_property('async', False)
sink.set_property('sync', 1)

sink.set_property("qos",0)

tee=Gst.ElementFactory.make("tee", "nvsink-tee")
if not tee:
    sys.stderr.write(" Unable to create tee \n")
tee_msg_pad=tee.get_request_pad('src_%u')
tee_render_pad=tee.get_request_pad("src_%u")

if not tee_msg_pad or not tee_render_pad:
    sys.stderr.write("Unable to get request pads\n")

queue1 = Gst.ElementFactory.make("queue", "nvtee-que1")
if not queue1:
    sys.stderr.write(" Unable to create queue1 \n")

queue2 = Gst.ElementFactory.make("queue", "nvtee-que2")
if not queue2:
    sys.stderr.write(" Unable to create queue2 \n")




splitmuxsink_c = "splitmuxsink_%u" %index
print("Creating splitmuxsink \n ")
splitmuxsink = Gst.ElementFactory.make("splitmuxsink", splitmuxsink_c)
# splitmuxsink.set_property('muxer', Gst.ElementFactory.make('matroskamux'))

splitmuxsink.set_property('muxer', Gst.ElementFactory.make('qtmux'))
splitmuxsink.set_property('location', '/home/ubuntu/sriharsha/videos/testing/segment_%09d.mkv')
splitmuxsink.set_property('max-size-time', 10000000000) #10s segments


sink_pad = queue1.get_static_pad("sink")
tee_msg_pad = tee.get_request_pad('src_%u')
tee_render_pad = tee.get_request_pad("src_%u")
if not tee_msg_pad or not tee_render_pad:
    sys.stderr.write("Unable to get request pads\n")
tee_msg_pad.link(sink_pad)
sink_pad = queue2.get_static_pad("sink")
tee_render_pad.link(sink_pad)
try:    
    Gst.Bin.add(nbin, queue, nvvidconv_pre, nvosd, nvvidconv, caps1, encoder1, caps2, encoder2, queue1, queue2 ,tee,  splitmuxsink,

rtppay, sink) 例外为 e: print("error in gst bin add", e)

#link 
queue.link(nvvidconv_pre)

nvvidconv_pre.link(nvosd)
nvosd.link(nvvidconv)
nvvidconv.link(tee)

queue2.link(caps2)
caps2.link(encoder2)
encoder2.link(encoder2)
encoder2.link(splitmuxsink)

queue1.link(caps1)
caps1.link(encoder1)
encoder1.link(rtppay)
rtppay.link(sink)





#ghostpad
pad = queue.get_static_pad("sink")
ghost_pad = Gst.GhostPad.new("sink", pad)
nbin.add_pad(ghost_pad)

我收到以下错误:

错误:gst-stream-error-quark:内部数据流错误。(1): gstqueue.c(988): gst_queue_handle_sink_event (): /GstPipeline:pipeline0/GstBin:sink-bin-00/GstQueue:queue_sink_0: 流停止,原因未链接 (-1)

4

1 回答 1

0

不确定您的情况,但在 tee splitmuxsink 之后可能需要async-handling启用属性。

于 2022-01-30T19:56:09.053 回答