Hello,
I ran some more tests without using decoders. Apart from the result mentioned above, the following code also has the same behaviour.
NOTE: This code has no decoders, but it has pgie, tracker and sgie.
I am not sure if this is related to the same problem above. But the GPU memory utilisation increases by about 10-15mb for every video file.
For convenience, instead of using a file, I am using a test video source and terminating the pipeline after 100 buffers. I repeat this 1000 times and can see the memory increasing over time.
I suspect I am missing something with respect to deallocation of the gst elements. Because when I use the gst-launch-1.0
command for the same pipeline and run it 1000 times, there is no leak.
import sys
from time import sleep
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
def bus_call(bus, message, loop):
t = message.type
if t == Gst.MessageType.EOS:
loop.quit()
elif t == Gst.MessageType.WARNING:
err, debug = message.parse_warning()
sys.stderr.write("Warning: %s: %s\n" % (err, debug))
elif t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
sys.stderr.write("Error: %s: %s\n" % (err, debug))
loop.quit()
return True
def main():
pipeline = Gst.Pipeline()
# videotestsrc ! ...
source = Gst.ElementFactory.make("videotestsrc", "source")
source.set_property('num-buffers', 100)
# ... ! nvvideoconvert ! ...
nv12_vid_conv = Gst.ElementFactory.make("nvvideoconvert", "video-convert-nv12")
# ... ! video/x-raw(memory:NVMM), format=NV12 ! ...
nv12caps = Gst.ElementFactory.make('capsfilter', 'nv12-caps')
nv12caps.set_property('caps', Gst.caps_from_string('video/x-raw(memory:NVMM), format=NV12'))
# ... ! nvstreammux ! ...
streammux = Gst.ElementFactory.make("nvstreammux", "streammux")
streammux.set_property('width', 2160)
streammux.set_property('height', 2160)
streammux.set_property('batch-size', 1)
streammux.set_property('batched-push-timeout', 4000000)
# ... ! nvinfer ! nvtracker ! nvinfer ! ...
pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
pgie.set_property('config-file-path', "models/pgie/pgie.txt")
tracker = Gst.ElementFactory.make("nvtracker", "tracker")
tracker.set_property('tracker-width', 512)
tracker.set_property('tracker-height', 288)
tracker.set_property('gpu_id', 0)
tracker.set_property('ll-lib-file', "/opt/nvidia/deepstream/deepstream/lib/libnvds_nvmultiobjecttracker.so")
tracker.set_property('ll-config-file', "dcf.yml")
tracker.set_property('enable_batch_process', True)
tracker.set_property('enable_past_frame', True)
sgie = Gst.ElementFactory.make("nvinfer", "secondary1-nvinference-engine")
sgie.set_property('config-file-path', "models/sgie/sgie.txt")
# ... ! nvvideoconvert ! ...
rgba_vid_conv = Gst.ElementFactory.make("nvvideoconvert", "video-convert-rgba")
# ... ! video/x-raw(memory:NVMM), format=NV12 ! ...
rgbacaps = Gst.ElementFactory.make('capsfilter', 'rgba-caps')
rgbacaps.set_property('caps', Gst.caps_from_string('video/x-raw(memory:NVMM), format=RGBA'))
# ... ! nvdsosd ! ...
nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")
# ... ! fakesink
sink = Gst.ElementFactory.make("fakesink", "sink")
pipeline.add(source)
pipeline.add(nv12_vid_conv)
pipeline.add(nv12caps)
pipeline.add(streammux)
pipeline.add(pgie)
pipeline.add(tracker)
pipeline.add(sgie)
pipeline.add(rgba_vid_conv)
pipeline.add(rgbacaps)
pipeline.add(nvosd)
pipeline.add(sink)
source.link(nv12_vid_conv)
nv12_vid_conv.link(nv12caps)
sinkpad = streammux.get_request_pad("sink_0")
srcpad = nv12caps.get_static_pad("src")
srcpad.link(sinkpad)
streammux.link(pgie)
pgie.link(tracker)
tracker.link(sgie)
sgie.link(rgba_vid_conv)
rgba_vid_conv.link(rgbacaps)
rgbacaps.link(nvosd)
nvosd.link(sink)
loop = GObject.MainLoop()
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", bus_call, loop)
pipeline.set_state(Gst.State.PLAYING)
try:
loop.run()
except:
pass
pipeline.set_state(Gst.State.NULL)
if __name__ == '__main__':
Gst.init(None)
for _ in range(1000):
main()
sleep(1)