Hello. I’m trying to simply re-transmit video with a Jetson Nano (4GB). I am using a USB camera that operates ~30FPS @1280x960. When I connect to the Nano from another device (using VLC) the feed is black for a long time then only sends a single frame before staying the same. I’ve tried another camera that operates ~30FPS @640x480 without any issue. My script is below:
import argparse
import sys
import os
sys.path.append('../')
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import GObject, Gst, GstRtspServer
from common.is_aarch_64 import is_aarch64
from common.bus_call import bus_call
def main(args):
# 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("v4l2src", "usb-cam-source")
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
# 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")
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")
# Make the encoder
if codec == "H264":
encoder = Gst.ElementFactory.make("nvv4l2h264enc", "encoder")
print("Creating H264 Encoder")
elif codec == "H265":
encoder = Gst.ElementFactory.make("nvv4l2h265enc", "encoder")
print("Creating H265 Encoder")
if not encoder:
sys.stderr.write(" Unable to create encoder")
encoder.set_property('bitrate', bitrate)
if is_aarch64():
encoder.set_property('preset-level', 1)
encoder.set_property('insert-sps-pps', 1)
encoder.set_property('bufapi-version', 1)
encoder.set_property('maxperf-enable', 1)
# Make the payload-encode video into RTP packets
if codec == "H264":
rtppay = Gst.ElementFactory.make("rtph264pay", "rtppay")
print("Creating H264 rtppay")
elif codec == "H265":
rtppay = Gst.ElementFactory.make("rtph265pay", "rtppay")
print("Creating H265 rtppay")
if not rtppay:
sys.stderr.write(" Unable to create rtppay")
# Make the UDP sink
updsink_port_num = 5400
sink = Gst.ElementFactory.make("udpsink", "udpsink")
if not sink:
sys.stderr.write(" Unable to create udpsink")
sink.set_property('host', '224.224.255.255')
sink.set_property('port', updsink_port_num)
sink.set_property('async', False)
sink.set_property('sync', 1)
print("Playing cam %s " % camera_path)
caps_v4l2src.set_property('caps', Gst.Caps.from_string("video/x-raw, framerate=30/1"))
source.set_property('device', camera_path)
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(encoder)
pipeline.add(rtppay)
pipeline.add(sink)
# Link the elements together:
# file-source -> h264-parser -> nvh264-decoder ->
# caps -> encoder -> rtppay -> udpsink
print("Linking elements in the Pipeline \n")
source.link(caps_v4l2src)
caps_v4l2src.link(vidconvsrc)
vidconvsrc.link(nvvidconvsrc)
nvvidconvsrc.link(caps_vidconvsrc)
caps_vidconvsrc.link(encoder)
encoder.link(rtppay)
rtppay.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)
# Start streaming
rtsp_port_num = int(os.environ.get('RTSP_SERVER_PORT_NUMBER', '8554'))
rtsp_stream_end = os.environ.get('RTSP_SERVER_STREAM_END', "/rtsp/camera")
username = os.environ.get('CAMERA_USERNAME', 'user')
password = os.environ.get('CAMERA_PASSWORD', "pass")
server = GstRtspServer.RTSPServer.new()
server.props.service = "%d" % rtsp_port_num
auth = GstRtspServer.RTSPAuth()
token = GstRtspServer.RTSPToken()
token.set_string('media.factory.role', username)
basic = GstRtspServer.RTSPAuth.make_basic(username, password)
auth.add_basic(basic, token)
server.set_auth(auth)
server.attach(None)
factory = GstRtspServer.RTSPMediaFactory.new()
factory.set_launch(
"( udpsrc name=pay0 port=%d buffer-size=524288 caps=\"application/x-rtp, media=video, clock-rate=90000, "
"encoding-name=(string)%s, payload=96 \" )" % (
updsink_port_num, codec))
factory.set_shared(True)
permissions = GstRtspServer.RTSPPermissions()
permissions.add_permission_for_role(username, "media.factory.access", True)
permissions.add_permission_for_role(username, "media.factory.construct", True)
factory.set_permissions(permissions)
server.get_mount_points().add_factory(rtsp_stream_end, factory)
print("\n *** DeepStream: Launched RTSP Streaming at rtsp://%s:%s@0.0.0.0:%d%s ***\n\n" %
(username, password, rtsp_port_num, rtsp_stream_end))
# 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)
def parse_args():
parser = argparse.ArgumentParser(description='RTSP Output Sample Application Help ')
parser.add_argument("-c", "--codec", default="H264",
help="RTSP Streaming Codec H264/H265 , default=H264", choices=['H264', 'H265'])
parser.add_argument("-b", "--bitrate", default=4000000,
help="Set the encoding bitrate ", type=int)
parser.add_argument("-i", "--input-device", default="/dev/video0",
help="Set the USB Camera device", type=str)
args = parser.parse_args()
global codec
global bitrate
global camera_path
camera_path = args.input_device
codec = args.codec
bitrate = args.bitrate
return 0
if __name__ == '__main__':
parse_args()
sys.exit(main(sys.argv))
I’ve enabled Jetson clocks + MAXN and when doing this I am running the Jetson Nano in headless mode.
I’ve tried viewing the camera using “Cheese” on the Jetson device and it views fine.
Is there something I can do to enable full resolution video transmission from this camera? Could I do a larger resolution potentially with more tweaks?