deepstream-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeepStream Development Skill
DeepStream开发技能指南
When this skill is active, ALWAYS read the relevant reference documents before generating code. Do NOT rely on memory - the reference documents contain critical details about exact property names, correct API usage, and common pitfalls.
当此技能激活时,生成代码前务必阅读相关参考文档。不要依赖记忆——参考文档包含了关于精确属性名称、正确API用法和常见陷阱的关键细节。
SDK and Architecture Quick Reference
SDK与架构快速参考
DeepStream SDK 9.0 Version Requirements
DeepStream SDK 9.0版本要求
- GStreamer: 1.24.2
- NVIDIA Driver: 590+
- CUDA: 13.1
- TensorRT: 10.14.1.48
- Platforms: Ubuntu 24.04 (x86_64 and ARM64/Jetson)
- GStreamer: 1.24.2
- NVIDIA驱动: 590+
- CUDA: 13.1
- TensorRT: 10.14.1.48
- 平台: Ubuntu 24.04(x86_64及ARM64/Jetson)
Typical Pipeline Flow
典型流水线流程
Source → Stream Muxer → Inference → [Tracker] → OSD → RendererComponents in are optional -- only add them when the user explicitly requests them.
[brackets]| Stage | Role | Key Element(s) | Required? |
|---|---|---|---|
| Source | Input from files, RTSP, cameras | | Yes |
| Stream Muxer | Batches streams for inference | | Yes |
| Inference | TensorRT model execution | | Yes |
| Tracker | Multi-object tracking across frames | | Only if requested |
| OSD | Draws bounding boxes, labels, overlays | | Yes (for visualization) |
| Renderer | Display or save output | | Yes |
Source → Stream Muxer → Inference → [Tracker] → OSD → Renderer方括号中的组件为可选——仅在用户明确要求时添加。
[]| 阶段 | 作用 | 核心元素 | 是否必需? |
|---|---|---|---|
| Source | 从文件、RTSP、摄像头输入 | | 是 |
| Stream Muxer | 批量处理流以进行推理 | | 是 |
| Inference | TensorRT模型执行 | | 是 |
| Tracker | 跨帧多目标追踪 | | 仅在用户要求时添加 |
| OSD | 绘制边界框、标签、叠加层 | | 是(用于可视化) |
| Renderer | 显示或保存输出 | | 是 |
Memory Model
内存模型
DeepStream uses NVIDIA Video Memory Manager (NVMM) for zero-copy GPU buffer transfers. Caps strings use to indicate GPU memory (e.g., ).
memory:NVMMvideo/x-raw(memory:NVMM), format=NV12DeepStream使用NVIDIA视频内存管理器(NVMM)实现零拷贝GPU缓冲区传输。Caps字符串使用表示GPU内存(例如:)。
memory:NVMMvideo/x-raw(memory:NVMM), format=NV12Critical Rules
关键规则
-
Only Add Requested Components: Do NOT add pipeline elements the user did not ask for.
- Tracker (): Only add when the user explicitly requests tracking or object IDs across frames
nvtracker - Secondary GIEs: Only add when the user requests classification or attribute extraction
- Analytics (): Only add when the user requests line crossing, ROI counting, etc.
nvdsanalytics - Message broker (/
nvmsgbroker): Only add when the user requests Kafka/cloud messagingnvmsgconv - When in doubt, build the minimal working pipeline and let the user ask for additions
- Tracker (
-
Default tofor Sources: When the user says "camera", "stream", "video", or provides a file path:
nvurisrcbin- Always use -- it handles RTSP, HTTP, and local files (
nvurisrcbin) transparentlyfile:// - Only use +
filesrc+ parser when the user explicitly needs raw file source controlqtdemux - For RTSP/live sources, also set on
live-source=1andnvstreammuxon the sinksync=0 - Convert local paths to URI:
"file://" + os.path.abspath(path)
- Always use
-
Metadata Iteration: Useand
.frame_items(returns iterators, NOT lists).object_items- NEVER use on these - iterate to count
len() - Iterator can only be consumed once
- NEVER use
-
Request Pad Syntax: Usetemplate, NEVER literal pad names
"sink_%u"pythonpipeline.link(("decoder", "mux"), ("", "sink_%u")) # CORRECT # pipeline.link(("decoder", "mux"), ("", "sink_0")) # WRONG - will fail -
Platform Detection for Sinks:python
import platform sink_type = "nv3dsink" if platform.processor() == "aarch64" else "nveglglessink" -
Buffer Cloning: Always clone buffers for async processingpython
tensor = buffer.extract(0).clone() # CRITICAL -
Queue Types:
- → Use with
queue.Queuethreading.Thread - → Use with
multiprocessing.Queuemultiprocessing.Process - Using wrong type causes silent data loss!
-
nvinfer Config Format:
- YAML: Use section (NOT
property:),model:with space after colonkey: value - INI: Use section,
[property]with equals signkey=value - Section MUST be named
property
- YAML: Use
-
nvmsgbroker is a SINK: Cannot have downstream elements - useto split pipeline
tee -
ALL Sinks Need async=0 for Tee Splits or Dynamic Sources: CRITICAL for state transitionspython
# When using tee splits OR dynamic sources, ALL sinks MUST have async=0 pipeline.add("nveglglessink", "sink", { "sync": 0, "qos": 0, "async": 0 # CRITICAL - prevents state transition deadlock })Symptom if missing: Pipeline stays in PAUSED state, no video displays. -
Built-in Probe Attachment:can only be attached to processing elements (e.g.,
measure_fps_probe,nvinfer), NOT to sink elements. Attaching to a sink raisesnvosdbin.RuntimeError: Probe failure -
Dynamic ONNX Models Require: When the ONNX model has dynamic input shapes (e.g., exported with
infer-dimsin Ultralytics YOLO, or with dynamic batch/height/width axes), you MUST adddynamic=Trueto the nvinfer config. Without it, TensorRT seesinfer-dims=C;H;Wfor dynamic dimensions and fails with-1. Common values:setDimensions: Error Code 3- YOLO models (640 input):
infer-dims=3;640;640 - Models with 416 input:
infer-dims=3;416;416 - Models with 1280 input:
infer-dims=3;1280;1280
- YOLO models (640 input):
-
Ultralytics YOLO Output Format Depends on Model Generation — newer models (v10+/v26+) output post-NMS results; older models (v8/v11) output raw pre-NMS tensors. The custom parser andmust match the actual output:
cluster-mode
| Model generation | Output tensor shape | Fields | |
|---|---|---|---|
| v8 / v11 | | | |
| v10 / v26+ | | | |
How to identify at runtime: log and inside the custom parser.
inferDims.d[0]inferDims.d[1]- → pre-NMS (v8/v11 style)
d={84, 8400} - → post-NMS (v10/v26+ style)
d={300, 6}
Symptom of mismatch: If is used with a post-NMS output, bounding boxes appear shifted by 45° or 135° from the actual objects (DeepStream's NMS incorrectly re-processes already-final coordinates).
If you see tilted or rotated boxes, also check the OBB / note in : for non-OBB models, value-initialize with and keep ; plain leaves fields uninitialized.
cluster-mode: 2[N, 6]rotation_anglereferences/nvinfer_config.mdNvDsInferObjectDetectionInfoobj{}rotation_angle = 0NvDsInferObjectDetectionInfo obj;- Virtual Environment Must Include pyservicemaker: is installed system-wide but is NOT accessible from a standard Python virtual environment. When a task requires a venv (e.g., for model download/conversion pip dependencies), always install
pyservicemakerandpyservicemakerinside the venv. The venv setup in generated code and README must always include:pyyamlSymptom if missing:bashpython3 -m venv venv source venv/bin/activate pip install /opt/nvidia/deepstream/deepstream/service-maker/python/pyservicemaker*.whl pyyaml pip install -r requirements.txt # other dependencieswhen running the app inside the venv.ModuleNotFoundError: No module named 'pyservicemaker'
-
仅添加用户请求的组件:不要添加用户未要求的流水线元素。
- Tracker ():仅在用户明确要求追踪或跨帧目标ID时添加
nvtracker - Secondary GIEs:仅在用户要求分类或属性提取时添加
- Analytics ():仅在用户要求越线检测、ROI计数等功能时添加
nvdsanalytics - 消息中间件 (/
nvmsgbroker):仅在用户要求Kafka/云消息传递时添加nvmsgconv - 如有疑问,先构建最小可用流水线,让用户提出额外需求
- Tracker (
-
默认使用作为源:当用户提到“摄像头”、“流”、“视频”或提供文件路径时:
nvurisrcbin- 始终使用——它可透明处理RTSP、HTTP和本地文件(
nvurisrcbin)file:// - 仅在用户明确需要原始文件源控制时使用+
filesrc+ 解析器qtdemux - 对于RTSP/实时源,需在上设置
nvstreammux,在sink上设置live-source=1sync=0 - 将本地路径转换为URI:
"file://" + os.path.abspath(path)
- 始终使用
-
元数据迭代:使用和
.frame_items(返回迭代器,而非列表).object_items- 切勿对这些对象使用——通过迭代来计数
len() - 迭代器仅能被消费一次
- 切勿对这些对象使用
-
请求Pad语法:使用模板,切勿使用字面Pad名称
"sink_%u"pythonpipeline.link(("decoder", "mux"), ("", "sink_%u")) # 正确 # pipeline.link(("decoder", "mux"), ("", "sink_0")) # 错误 - 会失败 -
针对Sink的平台检测:python
import platform sink_type = "nv3dsink" if platform.processor() == "aarch64" else "nveglglessink" -
缓冲区克隆:异步处理时务必克隆缓冲区python
tensor = buffer.extract(0).clone() # 关键步骤 -
队列类型:
- → 与
queue.Queue配合使用threading.Thread - → 与
multiprocessing.Queue配合使用multiprocessing.Process - 使用错误类型会导致静默数据丢失!
-
nvinfer配置格式:
- YAML:使用节(而非
property:),采用model:格式(冒号后需加空格)key: value - INI:使用节,采用
[property]格式(使用等号)key=value - 节名称必须为
property
- YAML:使用
-
nvmsgbroker是Sink:不能有下游元素——使用拆分流水线
tee -
所有Sink在Tee拆分或动态源场景下需设置async=0:这对状态转换至关重要python
# 当使用tee拆分或动态源时,所有Sink必须设置async=0 pipeline.add("nveglglessink", "sink", { "sync": 0, "qos": 0, "async": 0 # 关键 - 防止状态转换死锁 })缺失时的症状:流水线停留在PAUSED状态,无视频显示。 -
内置探针挂载限制:仅能挂载到处理元素(如
measure_fps_probe、nvinfer),不能挂载到sink元素。挂载到sink会引发nvosdbin。RuntimeError: Probe failure -
动态ONNX模型需要:当ONNX模型具有动态输入形状时(例如,在Ultralytics YOLO中使用
infer-dims导出,或具有动态批次/高度/宽度轴),必须在nvinfer配置中添加dynamic=True。否则,TensorRT会将动态维度识别为infer-dims=C;H;W,并因-1失败。常见值:setDimensions: Error Code 3- YOLO模型(640输入):
infer-dims=3;640;640 - 416输入模型:
infer-dims=3;416;416 - 1280输入模型:
infer-dims=3;1280;1280
- YOLO模型(640输入):
-
Ultralytics YOLO输出格式取决于模型版本 —— 新版本模型(v10+/v26+)输出NMS后结果;旧版本模型(v8/v11)输出原始NMS前张量。自定义解析器和必须与实际输出匹配:
cluster-mode
| 模型版本 | 输出张量形状 | 字段 | |
|---|---|---|---|
| v8 / v11 | | | |
| v10 / v26+ | | | |
运行时识别方法:在自定义解析器中记录和。
inferDims.d[0]inferDims.d[1]- → NMS前(v8/v11风格)
d={84, 8400} - → NMS后(v10/v26+风格)
d={300, 6}
不匹配时的症状:如果对NMS后的输出使用,边界框会相对于实际对象偏移45°或135°(DeepStream的NMS错误地重新处理已最终确定的坐标)。
如果看到倾斜或旋转的框,还需检查中的OBB / 说明:对于非OBB模型,需用初始化并保持;直接声明会导致字段未初始化。
[N, 6]cluster-mode: 2references/nvinfer_config.mdrotation_angleobj{}NvDsInferObjectDetectionInforotation_angle = 0NvDsInferObjectDetectionInfo obj;- 虚拟环境必须包含pyservicemaker:是系统级安装的,但无法从标准Python虚拟环境访问。当任务需要虚拟环境时(例如,用于模型下载/转换的pip依赖),务必在虚拟环境中安装
pyservicemaker和pyservicemaker。生成代码和README中的虚拟环境设置必须包含:pyyaml缺失时的症状:在虚拟环境中运行应用时出现bashpython3 -m venv venv source venv/bin/activate pip install /opt/nvidia/deepstream/deepstream/service-maker/python/pyservicemaker*.whl pyyaml pip install -r requirements.txt # 其他依赖。ModuleNotFoundError: No module named 'pyservicemaker'
Key Paths (DeepStream 9.0)
关键路径(DeepStream 9.0)
- Models:
/opt/nvidia/deepstream/deepstream/samples/models/ - Primary Detector:
/opt/nvidia/deepstream/deepstream/samples/models/Primary_Detector/resnet18_trafficcamnet_pruned.onnx - Tracker lib:
/opt/nvidia/deepstream/deepstream/lib/libnvds_nvmultiobjecttracker.so - Kafka lib:
/opt/nvidia/deepstream/deepstream/lib/libnvds_kafka_proto.so - Sample configs:
/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/
- 模型:
/opt/nvidia/deepstream/deepstream/samples/models/ - 主检测器:
/opt/nvidia/deepstream/deepstream/samples/models/Primary_Detector/resnet18_trafficcamnet_pruned.onnx - 追踪器库:
/opt/nvidia/deepstream/deepstream/lib/libnvds_nvmultiobjecttracker.so - Kafka库:
/opt/nvidia/deepstream/deepstream/lib/libnvds_kafka_proto.so - 示例配置:
/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/
Reference Documents
参考文档
IMPORTANT: Always read these documents for complete details. Do NOT generate code from memory.
| Document | Use When |
|---|---|
| references/gstreamer_plugins.md | Looking up plugin properties, ALL properties listed |
| references/service_maker_api.md | Using Pipeline/Flow API, metadata access, probes, EventMessageUserMetadata |
| references/use_cases_pipelines.md | Building pipelines: simple playback, multi-inference, cascaded GIE |
| references/kafka_messaging.md | Kafka/message broker setup, nvmsgconv/nvmsgbroker config, msg2p-newapi |
| references/best_practices.md | Design patterns, common pitfalls, anti-patterns |
| references/buffer_apis.md | BufferProvider/Feeder (injection), BufferRetriever/Receiver (extraction) |
| references/media_extractor_advanced.md | MediaExtractor, MediaChunk, FrameSampler |
| references/utilities_config.md | PerfMonitor, EngineFileMonitor, SourceConfig, SensorInfo, SmartRecordConfig |
| references/nvinfer_config.md | nvinfer config file format, ALL parameters |
| references/tracker_config.md | nvtracker config, NvDCF/IOU/DeepSORT/NvSORT |
| references/troubleshooting.md | Error messages and solutions |
| references/rest_api_dynamic.md | REST API, dynamic source add/remove, nvmultiurisrcbin |
| references/metamux_config.md | nvdsmetamux config, parallel multi-model inference, metadata merging, source ID filtering |
| references/docker_containers.md | Docker images, Dockerfile examples, pyservicemaker install, container run commands |
重要提示:如需完整细节,请务必阅读这些文档。不要仅凭记忆生成代码。
| 文档 | 使用场景 |
|---|---|
| references/gstreamer_plugins.md | 查询插件属性,所有属性均已列出 |
| references/service_maker_api.md | 使用Pipeline/Flow API、元数据访问、探针、EventMessageUserMetadata |
| references/use_cases_pipelines.md | 构建流水线:简单播放、多推理、级联GIE |
| references/kafka_messaging.md | Kafka/消息中间件设置、nvmsgconv/nvmsgbroker配置、msg2p-newapi |
| references/best_practices.md | 设计模式、常见陷阱、反模式 |
| references/buffer_apis.md | BufferProvider/Feeder(注入)、BufferRetriever/Receiver(提取) |
| references/media_extractor_advanced.md | MediaExtractor、MediaChunk、FrameSampler |
| references/utilities_config.md | PerfMonitor、EngineFileMonitor、SourceConfig、SensorInfo、SmartRecordConfig |
| references/nvinfer_config.md | nvinfer配置文件格式、所有参数 |
| references/tracker_config.md | nvtracker配置、NvDCF/IOU/DeepSORT/NvSORT |
| references/troubleshooting.md | 错误消息及解决方案 |
| references/rest_api_dynamic.md | REST API、动态源添加/移除、nvmultiurisrcbin |
| references/metamux_config.md | nvdsmetamux配置、并行多模型推理、元数据合并、源ID过滤 |
| references/docker_containers.md | Docker镜像、Dockerfile示例、pyservicemaker安装、容器运行命令 |
Quick Error Reference
快速错误参考
| Error | Solution |
|---|---|
| Iterate to count, don't use |
| Use |
| Queue data loss | Use |
| Config parse failed | Use |
| Use |
| Use |
| Secondary GIE inactive | Set |
| Tee/dynamic source stuck PAUSED | Set |
| RTSP no data/reconnecting | Test URL with ffplay, check credentials |
| |
| Add |
| |
| Use |
| 错误 | 解决方案 |
|---|---|
| 通过迭代计数,不要使用 |
| 使用 |
| 队列数据丢失 | 将 |
| 配置解析失败 | 在YAML中使用 |
| 对于分类器,使用 |
| 在 |
| Secondary GIE未激活 | 设置 |
| Tee/动态源停留在PAUSED状态 | 在所有sink元素上设置 |
| RTSP无数据/重连 | 使用ffplay测试URL,检查凭据 |
| |
| 为动态ONNX模型添加 |
虚拟环境中出现 | 在虚拟环境中执行 |
| 在pyservicemaker中使用 |