无法使用tee和splitmuxsink来保存视频,下面是代码,我在运行下面的代码段时遇到链接错误。im使用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 %un", 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 padsn") 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 padsn") 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,水槽(例外情况除外,e:打印("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流错误quark:内部数据流错误。(1( :gstqueue.c(988(:gst_queue_handle_sink_event((:/GstPipeline:pipeline0/GstBin:sink-bin-00/GstQueue:queue_sink_0:流停止,原因未链接(-1(
不确定您的情况,但在tee-splitmuxsink之后,可能需要启用async-handling
属性。
我同意SeB的观点。设置async-handling=true
为我解决了类似的问题。但是我也使用工厂并启用了async-finalize=true
。