Skip to content

Commit

Permalink
updated camera commands with ffmpeg command
Browse files Browse the repository at this point in the history
  • Loading branch information
KiraYang3 committed Feb 6, 2025
1 parent 19dd5c1 commit 3f01622
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
7 changes: 5 additions & 2 deletions videos/src/get_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def launch_camera(self, ip):
for device in explorehd_devices:
self.get_logger().info(f"Launching node with device: {device}")
# Add your node launch logic here
# thread = threading.Thread(target=subprocess.run, args=(["ros2", "run", "videos", "videos_launch.py", "--ros-args", device]))
# thread.start()
# Construct the command with f-strings
cmd = ["ros2", "run", "videos", "videos_launch.py", "--ros-args", "-p", f"ip:={ip}", "-p", f"device:={device}"]
# Run in a thread
thread = threading.Thread(target=subprocess.run, args=(cmd,), kwargs={"check": True})
thread.start()


def publish_stop(self):
Expand Down
34 changes: 11 additions & 23 deletions videos/src/videos_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,26 @@
class Camera(Node):
def __init__(self):
super().__init__("cameras")
self.declare_parameter("dev_name", "device=/dev/video2")
self.declare_parameter("ip", "192.168.1.23")
self.declare_parameter("device", "device=/dev/video2")

dev_name = self.get_parameter("dev_name").get_parameter_value().string_value
ip_address = self.get_parameter("ip").get_parameter_value().string_value
dev_name = self.get_parameter("device").get_parameter_value().string_value

# Define RTSP stream URL
rtsp_url = "rtsp://{ip_address}:8554/{dev_name}"

while True:
subprocess.run(
[
"gst-launch-1.0",
"-v",
"v4l2src",
dev_name,
"!",
"video/x-h264,width=1920,height=1080",
"!",
"h264parse",
"!",
"queue",
"!",
"rtph264pay",
"config-interval=10",
"pt=96",
"!",
"udpsink",
"host=224.1.1.1",
"auto-multicast=true",
"port=" + port,
"sync=false",
"buffer-size=1048576",
"ffmpeg", "-f", "v4l2", "--fflags", "nobuffer",
"-i", dev_name, "-vcodec", "copy", "-g", "10",
"-f", "rtsp", rtsp_url
]
)



def main(args=None):
rclpy.init(args=args)
camera_node = Camera()
Expand Down

0 comments on commit 3f01622

Please sign in to comment.