Error in pipeline porting pygst program from gstre

2019-08-12 22:12发布

问题:

I'm porting a program from pygst 0.10 to 1.0 and I've problems with the pipeline. The pipeline I use in the 0.10 version, and works well, is:

udpsrc name=src ! tsparse ! tsdemux ! queue ! ffdec_h264 max-threads=0 ! identity ! xvimagesink force-aspect-ratio=True name=video

For the 1.0 version the pipeline should be something like:

udpsrc name=src ! tsparse ! tsdemux ! queue ! avdec_h264 ! videoconvert ! xvimagesink force-aspect-ratio=True name=video

The code is:

self.pipeline = Gst.Pipeline()

self.udpsrc = Gst.ElementFactory.make('udpsrc', 'src')
self.pipeline.add(self.udpsrc)
self.udpsrc.set_property("socket", Gio.Socket().new_from_fd(self.videosocket.fileno()))

self.tsparse = Gst.ElementFactory.make("tsparse", None)
self.pipeline.add(self.tsparse)

self.demux = Gst.ElementFactory.make('tsdemux', None)
self.pipeline.add(self.demux)

self.queue = Gst.ElementFactory.make('queue', None)
self.pipeline.add(self.queue)

self.h264 = Gst.ElementFactory.make('avdec_h264', None)
self.pipeline.add(self.h264)

self.videoconvert = Gst.ElementFactory.make('videoconvert', None)
self.pipeline.add(self.videoconvert)

self.imagesink = Gst.ElementFactory.make('xvimagesink', None)
self.pipeline.add(self.imagesink)

self.udpsrc.link(self.tsparse)
self.tsparse.link(self.demux)
self.demux.link(self.queue)
self.queue.link(self.h264)
self.h264.link(self.videoconvert)
self.videoconvert.link(self.imagesink)

I've set the debug flag and the output iS:

GST_EVENT gstevent.c:709:gst_event_new_segment: creating segment event time segment start=0:00:00.000000000, stop=99:99:99.999999999, rate=1,000000, applied_rate=1,000000, flags=0x00, time=0:00:00.000000000, base=0:00:00.000000000, position 0:00:00.000000000, duration 99:99:99.999999999
0:00:06.241739369  5576      0x2f1c590 INFO                 basesrc gstbasesrc.c:2772:gst_base_src_loop:<src> marking pending DISCONT
0:00:06.241751688  5576      0x2f1c590 INFO        mpegtspacketizer mpegtspacketizer.c:770:mpegts_try_discover_packet_size: have packetsize detected: 188 bytes
0:00:06.241786466  5576      0x2f1c590 INFO              mpegtsbase mpegtsbase.c:726:mpegts_base_apply_pat:<mpegtsparse2-0> PAT
0:00:06.242321432  5576      0x2f1c590 INFO        GST_ELEMENT_PADS gstelement.c:897:gst_element_get_static_pad: found pad mpegtsparse2-0:sink
0:00:06.252539174  5576      0x2f1c590 INFO               GST_EVENT gstevent.c:628:gst_event_new_caps: creating caps event video/mpegts, systemstream=(boolean)true, packetsize=(int)188
0:00:06.252604078  5576      0x2f1c590 INFO               GST_EVENT gstevent.c:709:gst_event_new_segment: creating segment event time segment start=0:00:00.000000000, stop=99:99:99.999999999, rate=1,000000, applied_rate=1,000000, flags=0x00, time=0:00:00.000000000, base=0:00:00.000000000, position 0:00:00.000000000, duration 99:99:99.999999999
0:00:06.252655518  5576      0x2f1c590 INFO        mpegtspacketizer mpegtspacketizer.c:770:mpegts_try_discover_packet_size: have packetsize detected: 188 bytes
0:00:06.252693109  5576      0x2f1c590 INFO              mpegtsbase mpegtsbase.c:726:mpegts_base_apply_pat:<tsdemux0> PAT
0:00:06.252856437  5576      0x2f1c590 INFO        GST_ELEMENT_PADS gstelement.c:897:gst_element_get_static_pad: found pad tsdemux0:sink
0:00:06.252870522  5576      0x2f1c590 INFO               GST_EVENT gstevent.c:628:gst_event_new_caps: creating caps event audio/mpeg, mpegversion=(int)1
0:00:06.252894869  5576      0x2f1c590 WARN                 default descriptions.c:612:format_info_get_desc: Unexpected MPEG-1 layer in audio/mpeg, mpegversion=(int)1
0:00:06.252931277  5576      0x2f1c590 INFO        GST_ELEMENT_PADS gstelement.c:897:gst_element_get_static_pad: found pad tsdemux0:sink
0:00:06.252940534  5576      0x2f1c590 INFO               GST_EVENT gstevent.c:628:gst_event_new_caps: creating caps event video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal
0:00:06.252997433  5576      0x2f1c590 INFO        GST_ELEMENT_PADS gstelement.c:646:gst_element_add_pad:<tsdemux0> adding pad 'audio_0041'
0:00:06.253006343  5576      0x2f1c590 INFO               GST_EVENT gstevent.c:709:gst_event_new_segment: creating segment event time segment start=0:00:00.000000000, stop=99:99:99.999999999, rate=1,000000, applied_rate=1,000000, flags=0x00, time=0:00:00.000000000, base=0:00:00.000000000, position 0:00:00.000000000, duration 99:99:99.999999999
0:00:06.253348125  5576      0x2f1c590 INFO        GST_ELEMENT_PADS gstelement.c:646:gst_element_add_pad:<tsdemux0> adding pad 'video_0040'
0:00:06.253394366  5576      0x2f1c590 INFO                 basesrc gstbasesrc.c:2785:gst_base_src_loop:<src> pausing after gst_pad_push() = not-linked
0:00:06.253408940  5576      0x2f1c590 WARN                 basesrc gstbasesrc.c:2865:gst_base_src_loop:<src> error: Internal data flow error.
0:00:06.253413835  5576      0x2f1c590 WARN                 basesrc gstbasesrc.c:2865:gst_base_src_loop:<src> error: streaming task paused, reason not-linked (-1)
0:00:06.253425400  5576      0x2f1c590 INFO        GST_ERROR_SYSTEM gstelement.c:1835:gst_element_message_full:<src> posting message: Internal data flow error.
0:00:06.253439614  5576      0x2f1c590 INFO        GST_ERROR_SYSTEM gstelement.c:1858:gst_element_message_full:<src> posted error message: Internal data flow error.
0:00:06.253513306  5576      0x2f1c590 INFO        GST_ELEMENT_PADS gstelement.c:766:gst_element_remove_pad:<tsdemux0> removing pad 'audio_0041'
0:00:06.253531993  5576      0x2f1c590 INFO        GST_ELEMENT_PADS gstelement.c:766:gst_element_remove_pad:<tsdemux0> removing pad 'video_0040'
('on_error():', (GError('Internal data flow error.',), 'gstbasesrc.c(2865): gst_base_src_loop (): /GstPipeline:pipeline0/GstUDPSrc:src:\nstreaming task paused, reason not-linked (-1)'))
0:00:06.253551147  5576      0x2f1c590 INFO                    task gsttask.c:300:gst_task_func:<src:src> Task going to paused

回答1:

do you have to use socket? cannot try port for starters? what about udpsrc caps.. I think you have to specify them otherwise it wont be linked (probably)..

I would do this(not accurate - you have to debug/tune it):

self.pipeline = Gst.Pipeline()

self.udpsrc = Gst.ElementFactory.make('udpsrc', 'src')
self.pipeline.add(self.udpsrc)
self.udpsrc.set_property("port", 1234)
self.udpsrc.set_property("caps", "your caps)
self.decodebin = Gst.ElementFactory.make("decodebin", None)
self.pipeline.add(self.decodebin)
self.imagesink = Gst.ElementFactory.make('xvimagesink', None)
self.pipeline.add(self.imagesink)

self.udpsrc.link(self.decodebin)
self.decodebin.link(self.imagesink)


回答2:

I think that following lines had errors:

self.udpsrc = Gst.ElementFactory.make('udpsrc', 'src')
self.pipeline.add(self.udpsrc)
self.udpsrc.set_property("socket",Gio.Socket().new_from_fd(self.videosocket.fileno()))

They should be:

self.udpsrc = Gst.ElementFactory.make('udpsrc', 'src')
self.udpsrc.set_property("socket",Gio.Socket().new_from_fd(self.videosocket.fileno()))
self.pipeline.add(self.udpsrc)