Simple Python code to run video using Gstream does not show anything?

I am a beginner in Gstreamer, trying simple Python code to see video output using the following code on my laptop. After running the code it does not show anything only the cursor blinking on the terminal. The same code works fine on Jetson Orin Nano. can anyone help me with what’s wrong with my code or system ? Thanks in advance.

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject, GLib

# Initialize Gstreamer
Gst.init(None)

# Create a Gstreamer pipeline
pipeline = Gst.Pipeline()

# Create elements for the pipeline
source = Gst.ElementFactory.make("v4l2src", "source")
source.set_property("device", "/dev/video1")  # Set the device to your UVC Camera
capsfilter = Gst.ElementFactory.make("capsfilter", "capsfilter")
caps = Gst.Caps.from_string("video/x-raw, width=640, height=480")  # Adjust width and height as needed
capsfilter.set_property("caps", caps)
sink = Gst.ElementFactory.make("autovideosink", "sink")

# Add elements to the pipeline
pipeline.add(source)
pipeline.add(capsfilter)
pipeline.add(sink)

# Link elements
source.link(capsfilter)
capsfilter.link(sink)

# Set the pipeline state to playing
pipeline.set_state(Gst.State.PLAYING)

# Create a main loop to handle Gstreamer events
loop = GLib.MainLoop()

try:
loop.run()
except KeyboardInterrupt:
# Stop the pipeline when the user interrupts the program
pipeline.set_state(Gst.State.NULL)
loop.quit()

You may further tell what OS is running your laptop.
If it is running Linux, you may check what camera modes are available from camera at /dev/video1 with:

v4l2-ctl -d1 --list-formats-ext

and check if it does provides 640x480.

Also note that autovideosink would choose a different video sink depending on your system. With jetson this would be xvimagesink in most cases AFAIK, but with a different platform it may may different, so you may have to convert or upload.

@Honey_Patouceul Thanks for your response.

My OS is Ubuntu 22.04 LTS

v4l2-ctl -d1 --list-formats-ext result in

anil@anil-Dell-G15-5520:~$ v4l2-ctl -d1 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
       Type: Video Capture

There are no reported modes, this looks suspect to me.
First check for the same in working case with Jetson.
On your laptop, it may be /dev/video0 so you would check modes with -d0 (or --device=/dev/video0), or /dev/video2, or another video node (check with ls /dev/video*).
Also note that in recent Linux releases a camera can create 2 video nodes, one for video and one for metadata (in such case you may also use v4l2-ctl -d0 --all and v4l2-ctl -d1 --all and check for difference).

@Honey_Patouceul

anil@anil-Dell-G15-5520:~/GstreamCode/C_Code$ ls /dev/video*
/dev/video0  /dev/video1

So you may try /dev/video0 instead of /dev/video1.