How to set Framerate when reading feed from RTSP cam url using Gstreamer for a deepstream application?

1.6k views Asked by At

I have a camera which run at 25fps, Need to access the feed from the same camera with reduced fps (5) using GST. we are using deepstream and hence i was looking for solutions in nvidia forums.

The following code is from nvidia deepstream sample apps.

I saw a post in nvidia forums they suggested to use videorate to throtle the fps. However i'm confused about placement of videorate property.Should it be placed after uri-decode-bin?

Could anyone help?

        GObject.threads_init()
        Gst.init(None)        
        
        pipeline = Gst.Pipeline()
        source_bin = create_source_bin(cam_url)
        pipeline.add(source_bin)
        filter = create_videorate_filter()
        pipeline.add(filter)

create_source_bin (Copied from deepstream python apps sample)

def create_source_bin(cam_url):
    bin_name = "source-bin-test"
    nbin = Gst.Bin.new(bin_name)
    # Source element for reading from the cam_url.
    uri_decode_bin = Gst.ElementFactory.make("uridecodebin", "uri-decode-bin")
    uri_decode_bin.set_property("uri", cam_url)    
    uri_decode_bin.connect("pad-added", cb_newpad, nbin)
    uri_decode_bin.connect("child-added", decodebin_child_added, nbin)

    Gst.Bin.add(nbin, uri_decode_bin)
    
    bin_pad = nbin.add_pad(Gst.GhostPad.new_no_target("src", Gst.PadDirection.SRC))
    return nbin

My proposed videorate fiter with nvmm memory as seen from nvidia forum posts

def  create_videorate_filter():
    filter = Gst.ElementFactory.make('videorate', 'videorate')
    caps = Gst.caps_from_string("video/x-raw(memory:NVMM),framerate=5/1")
    filter.set_property("caps", caps)
    if not filter:
        sys.stderr.write(" Unable to create capsfilter \n")

    return filter

Is this the right thing to do? Where should be the videorate filter placed?

1

There are 1 answers

0
Michael Gruner On
  1. Yes, the videorate element can reduce the framerate as you want.

  2. Yes, the videorate must be after the uri-decodebin since you need the uncompressed frames to modify the framerate.

  3. No, the create_videorate_filter function is not okay. The videorate element does not have a caps property. However, it does have a max-rate property, so you can change your snippet as:

     def  create_videorate_filter():
         filter = Gst.ElementFactory.make('videorate', 'videorate')
         if not filter:
             sys.stderr.write(" Unable to create capsfilter \n")
    
         filter.set_property("max-rate", 5)
    
         return filter