(Created page with "=How to start camera stream on boot with systemd service – NVIDIA Jetson Tutorial= This tutorial demonstrates how to automatically launch a Python-based camera streaming application on boot using a <code>systemd</code> service on NVIDIA Jetson devices. == Prerequisites == * NVIDIA Jetson board (e.g., Orin NX, Nano, Xavier) * Your custom Python GStreamer/WebRTC camera application * Access to the terminal and root privileges == Step 1: Prepare the Python Script == E...") |
(No difference)
|
Latest revision as of 22:38, 8 June 2025
How to start camera stream on boot with systemd service – NVIDIA Jetson Tutorial
This tutorial demonstrates how to automatically launch a Python-based camera streaming application on boot using a systemd
service on NVIDIA Jetson devices.
Prerequisites
- NVIDIA Jetson board (e.g., Orin NX, Nano, Xavier)
- Your custom Python GStreamer/WebRTC camera application
- Access to the terminal and root privileges
Step 1: Prepare the Python Script
Ensure your Python streaming script is available on the Jetson device. Below is the exact script used in this tutorial camera_stream.py
:
Note: Make sure to set the correct IP address for the device that will be consuming the stream. In this case 10.42.0.1 is used.
#!/usr/bin/env python3
import gi
import signal
import sys
gi.require_version('Gst', '1.0')
gi.require_version('GLib', '2.0')
from gi.repository import Gst, GLib
Gst.init(None)
loop = GLib.MainLoop()
def on_message(bus, message, loop):
msg_type = message.type
if msg_type == Gst.MessageType.ERROR:
err, debug = message.parse_error()
print(f"Error: {err}, Debug: {debug}")
loop.quit()
def signal_handler(sig, frame):
print("Interrupt received, stopping pipeline...")
loop.quit()
# Handle SIGINT (Ctrl+C) and SIGTERM (systemd stop)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
pipeline = Gst.parse_launch(
"nvarguscamerasrc sensor-id=0 ! "
"nvv4l2h264enc bitrate=4000000 ! "
"h264parse ! rtph264pay config-interval=1 pt=96 ! "
"udpsink host=10.42.0.1 port=5000"
)
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", on_message, loop)
pipeline.set_state(Gst.State.PLAYING)
try:
print("Pipeline started. Streaming...")
loop.run()
finally:
print("Shutting down pipeline.")
pipeline.set_state(Gst.State.NULL)
bus.remove_signal_watch()
Save this as /usr/local/bin/camera_stream.py
.
Make sure all required GStreamer plugins are installed and working. You can test this script manually before proceeding.
python3 /usr/local/bin/camera_stream.py
Step 2: Create a systemd Service File
Use the following systemd
unit file to run the Python script at boot:
[Unit]
Description=Jetson camera UDP stream on boot
After=nvargus-daemon.service
Requires=nvargus-daemon.service
[Service]
ExecStart=/usr/bin/python3 /usr/local/bin/camera_stream.py
Restart=on-failure
StandardOutput=journal
StandardError=journal
Save this file as /etc/systemd/system/camera-stream.service
.
Step 3: Enable and Start the Service
To enable and start the service on boot, run the following commands:
sudo systemctl daemon-reload
sudo systemctl enable camera-stream.service
sudo systemctl start camera-stream.service
To check the service status:
systemctl status camera-stream.service
To view logs:
journalctl -u camera-stream.service
Step 4: Testing auto camera stream feature
In order to test this feature, run the following GStreamer pipeline on the device that will preview the camera stream put by the NVIDIA Jetson device.
gst-launch-1.0 -v udpsrc port=5000 ! application/x-rtp, encoding-name=H264, payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink
Then, reboot or power-cycle the board.
Finally, make sure that the stream is shown as expected on the client device.
Need Further Support?
📞 Book Consultation Call: Show Calendar!
📩 Contact Via Email: support@proventusnova.com
🌐 Visit Our Website: ProventusNova.com