# How can I use DS python code to pipe CSI camera streaming?

**URL:** <https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326>\
**Category:** DeepStream SDK\
**Created:** [December 19, 2019, 12:59am UTC](https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326 "2019-12-19T00:59:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tzuchun](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tzuchun](https://forums.developer.nvidia.com/u/tzuchun)\
**Post date:** [December 19, 2019, 12:59am UTC](https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326/1 "2019-12-19T00:59:16Z")

</div>

Dear NVIDIA,

I am new to DeepStream tech.

It’s exciting to hear that DS started to support Python.

Is there anyway to change deepstream\_test\_1.py code to pipe CSI camera (like Jetson TX2 camera onboard) streaming?

Looking forward to your reply/feedback. Thanks.

---

<div class="post-metadata">

**Author:** ![ChrisDing](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/chrisding/32/14043_2.png) [@ChrisDing](https://forums.developer.nvidia.com/u/ChrisDing)\
**Post date:** [December 23, 2019, 2:44am UTC](https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326/2 "2019-12-23T02:44:54Z")

</div>

Can you use “nvarguscamerasrc” ?

camerasrc = Gst.ElementFactory.make(“nvarguscamerasrc”, “nv-arguscamerasrc”)  
camerasrc.set\_property()

---

<div class="post-metadata">

**Author:** ![tzuchun](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tzuchun](https://forums.developer.nvidia.com/u/tzuchun)\
**Post date:** [January 7, 2020, 2:44am UTC](https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326/3 "2020-01-07T02:44:54Z")

</div>

Using “nvarguscamerasrc”

I tested and it works. Thank you very much.

---

<div class="post-metadata">

**Author:** ![noobforever1502](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@noobforever1502](https://forums.developer.nvidia.com/u/noobforever1502)\
**Post date:** [January 21, 2020, 8:52am UTC](https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326/4 "2020-01-21T08:52:10Z")

</div>

Hey tzuchun, have you done running on CSIcamera? Can you share with me all params of gstream you used? I tried to modified deepstream\_test\_1.py for many times but it didn’t work.

---

<div class="post-metadata">

**Author:** ![tzuchun](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tzuchun](https://forums.developer.nvidia.com/u/tzuchun)\
**Post date:** [January 31, 2020, 1:55am UTC](https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326/5 "2020-01-31T01:55:48Z")

</div>

Hi noobforever1502,

This is my worked main function code modified from [https://devtalk.nvidia.com/default/topic/1066912/deepstream-sdk/deepstream-now-supports-python-/post/5408100/#5408100](https://devtalk.nvidia.com/default/topic/1066912/deepstream-sdk/deepstream-now-supports-python-/post/5408100/#5408100)

and it refered the information: [https://devtalk.nvidia.com/default/topic/1066251/deepstream-sdk/save-camera-feed/post/5400303/#5400303](https://devtalk.nvidia.com/default/topic/1066251/deepstream-sdk/save-camera-feed/post/5400303/#5400303)

hope it helps.

```auto
def main(args):
    # Check input arguments
    if len(args) != 2:
        sys.stderr.write("usage: %s <v4l2-device-path>\n" % args[0])
        sys.exit(1)

    # Standard GStreamer initialization
    GObject.threads_init()
    Gst.init(None)

    # Create gstreamer elements
    # Create Pipeline element that will form a connection of other elements
    print("Creating Pipeline \n ")
    pipeline = Gst.Pipeline()

    if not pipeline:
        sys.stderr.write(" Unable to create Pipeline \n")

    # Source element for reading from the file
    print("Creating Source \n ")
    source = Gst.ElementFactory.make("nvarguscamerasrc", "nv-nvarguscamerasrc")
    if not source:
        sys.stderr.write(" Unable to create Source \n")

    #caps_v4l2src = Gst.ElementFactory.make("capsfilter", "v4l2src_caps")
    #if not caps_v4l2src:
    # sys.stderr.write(" Unable to create v4l2src capsfilter \n")

print("Creating Video Converter \n")

    # Adding videoconvert -> nvvideoconvert as not all
    # raw formats are supported by nvvideoconvert;
    # Say YUYV is unsupported - which is the common
    # raw format for many logi usb cams
    # In case we have a camera with raw format supported in
    # nvvideoconvert, GStreamer plugins' capability negotiation
    # shall be intelligent enough to reduce compute by
    # videoconvert doing passthrough (TODO we need to confirm this)

# videoconvert to make sure a superset of raw formats are supported
    vidconvsrc = Gst.ElementFactory.make("videoconvert", "convertor_src1")
    if not vidconvsrc:
        sys.stderr.write(" Unable to create videoconvert \n")

    # nvvideoconvert to convert incoming raw buffers to NVMM Mem (NvBufSurface API)
    nvvidconvsrc = Gst.ElementFactory.make("nvvideoconvert", "convertor_src2")
    if not nvvidconvsrc:
        sys.stderr.write(" Unable to create Nvvideoconvert \n")

    caps_vidconvsrc = Gst.ElementFactory.make("capsfilter", "nvmm_caps")
    if not caps_vidconvsrc:
        sys.stderr.write(" Unable to create capsfilter \n")

    # Create nvstreammux instance to form batches from one or more sources.
    streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
    if not streammux:
        sys.stderr.write(" Unable to create NvStreamMux \n")

    # Use nvinfer to run inferencing on camera's output,
    # behaviour of inferencing is set through config file
    pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
    if not pgie:
        sys.stderr.write(" Unable to create pgie \n")

    # Use convertor to convert from NV12 to RGBA as required by nvosd
    nvvidconv = Gst.ElementFactory.make("nvvideoconvert", "convertor")
    if not nvvidconv:
        sys.stderr.write(" Unable to create nvvidconv \n")

    # Create OSD to draw on the converted RGBA buffer
    nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")

    if not nvosd:
        sys.stderr.write(" Unable to create nvosd \n")

    # Finally render the osd output
    if is_aarch64():
        transform = Gst.ElementFactory.make("nvegltransform", "nvegl-transform")

    print("Creating EGLSink \n")
    sink = Gst.ElementFactory.make("nveglglessink", "nvvideo-renderer")
    if not sink:
        sys.stderr.write(" Unable to create egl sink \n")

    print("Playing cam %s " %args[1])
    caps_v4l2src.set_property('caps', Gst.Caps.from_string("video/x-raw, framerate=30/1"))
    caps_vidconvsrc.set_property('caps', Gst.Caps.from_string("video/x-raw(memory:NVMM)"))
    source.set_property('bufapi-version', 1)
    streammux.set_property('width', 1280)
    streammux.set_property('height', 720)
    streammux.set_property('batch-size', 1)
    #streammux.set_property('batched-push-timeout', 4000000)
    pgie.set_property('config-file-path', "dstest1_pgie_config.txt")
    # Set sync = false to avoid late frame drops at the display-sink
    sink.set_property('sync', False)

    print("Adding elements to Pipeline \n")
    pipeline.add(source)
    #pipeline.add(caps_v4l2src)
    pipeline.add(vidconvsrc)
    pipeline.add(nvvidconvsrc)
    pipeline.add(caps_vidconvsrc)
    pipeline.add(streammux)
    pipeline.add(pgie)
    pipeline.add(nvvidconv)
    pipeline.add(nvosd)
    pipeline.add(sink)
    if is_aarch64():
        pipeline.add(transform)

    # we link the elements together
    # v4l2src -> nvvideoconvert -> mux -> 
    # nvinfer -> nvvideoconvert -> nvosd -> video-renderer
    print("Linking elements in the Pipeline \n")
    source.link(vidconvsrc)
    #source.link(caps_v4l2src)
    #caps_v4l2src.link(vidconvsrc)
    vidconvsrc.link(nvvidconvsrc)
    nvvidconvsrc.link(caps_vidconvsrc)

    sinkpad = streammux.get_request_pad("sink_0")
    if not sinkpad:
        sys.stderr.write(" Unable to get the sink pad of streammux \n")
    srcpad = caps_vidconvsrc.get_static_pad("src")
    if not srcpad:
        sys.stderr.write(" Unable to get source pad of caps_vidconvsrc \n")
    srcpad.link(sinkpad)
    streammux.link(pgie)
    pgie.link(nvvidconv)
    nvvidconv.link(nvosd)
    if is_aarch64():
        nvosd.link(transform)
        transform.link(sink)
    else:
        nvosd.link(sink)

    # create an event loop and feed gstreamer bus mesages to it
    loop = GObject.MainLoop()
    bus = pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect ("message", bus_call, loop)

    # Lets add probe to get informed of the meta data generated, we add probe to
    # the sink pad of the osd element, since by that time, the buffer would have
    # had got all the metadata.
    osdsinkpad = nvosd.get_static_pad("sink")
    if not osdsinkpad:
        sys.stderr.write(" Unable to get sink pad of nvosd \n")

    osdsinkpad.add_probe(Gst.PadProbeType.BUFFER, osd_sink_pad_buffer_probe, 0)

    # start play back and listen to events
    print("Starting pipeline \n")
    pipeline.set_state(Gst.State.PLAYING)
    try:
        loop.run()
    except:
        pass
    # cleanup
    pipeline.set_state(Gst.State.NULL)

```

> [@](#):
>
> Hey tzuchun, have you done running on CSIcamera? Can you share with me all params of gstream you used? I tried to modified deepstream\_test\_1.py for many times but it didn’t work.

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [October 12, 2021, 4:18pm UTC](https://forums.developer.nvidia.com/t/how-can-i-use-ds-python-code-to-pipe-csi-camera-streaming/109326/6 "2021-10-12T16:18:32Z")

</div>

Closed on October 12, 2021, 4:18pm UTC


