NVIDIA DeepStream SDK API Reference

9.2 Release
sources/apps/common/includes/frame_dump.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /*
19  * frame_dump.h — Runtime JPEG + metadata dump feature for a DeepStream pipeline.
20  *
21  * Self-contained module. Attaches a probe to the nvtracker SRC pad and, for the
22  * cameras that are switched ON, writes one JPEG + one JSON metadata file
23  * (detection bbox + tracker id/bbox) per frame, FPS-gated using the mux PTS.
24  *
25  * Output layout:
26  * <output_dir>/<sensor_id>/<YYYY-MM-DD>/<frame_num>.jpg
27  * <output_dir>/<sensor_id>/<YYYY-MM-DD>/<frame_num>.txt (JSON)
28  *
29  * Control via a small built-in HTTP server (default port 9857, configurable):
30  * POST /dump/config {"enable":true,"fps":5,"location":"/data/dumps","quality":80}
31  * fps accepts fractional values below 1 for sparse sampling, e.g. "fps":0.1
32  * dumps roughly one frame every 10 seconds.
33  * POST /dump/camera {"sensor_id":"cam-01","enable":true}
34  * GET /dump/status
35  *
36  * nvmultiurisrcbin is NOT touched — this owns its own port/state.
37  */
38 #ifndef FRAME_DUMP_H
39 #define FRAME_DUMP_H
40 
41 #include <gst/gst.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /* Configuration passed once at startup. Runtime-changeable fields (marked) can
48  * also be overridden later via POST /dump/config. */
49 typedef struct _FrameDumpConfig {
50  const char *http_port; /* control port; NULL -> "9857" */
51  const char *bind_address; /* "0.0.0.0" (default) or "127.0.0.1" */
52  const char *default_output_dir; /* initial dump location (runtime-changeable)*/
53  guint gpu_id; /* GPU for JPEG encode */
54  gboolean enabled; /* initial global on/off (runtime-changeable)*/
55  gdouble fps; /* initial fps (0 -> 1); fractional values */
56  /* (e.g. 0.1 == 1 frame / 10s) are honoured */
57  gint quality; /* JPEG quality (0 -> 80) */
58  gboolean hour_subfolder; /* add /<HH>/ level (runtime-changeable) */
59  gboolean unique_filenames; /* name <frame_num>_<pts> (runtime-changeable)*/
60  guint retention_days; /* delete day-folders older than N; 0 = keep */
61  gboolean all_cameras; /* dump every source (ignores per-camera set) */
62  const char *enable_sensors; /* ";"-separated sensor_ids ON at startup */
63 
64  /* Kafka notification: on every dumped frame, publish a JSON message (jpg/txt
65  * paths + metadata) to a Kafka topic via the DeepStream nvds_msgapi Kafka
66  * protocol adaptor (loaded at runtime; no extra link dependency). */
67  gboolean kafka_enable; /* enable notifications (runtime-changeable) */
68  const char *kafka_broker; /* "host;port" connection string (startup) */
69  const char *kafka_topic; /* notification topic (runtime-changeable) */
70  const char *kafka_proto_lib; /* adaptor .so; NULL -> libnvds_kafka_proto */
71  const char *kafka_config_file; /* optional Kafka producer config file */
72 
73  /* Base64-image mode: instead of writing <frame>.jpg + <frame>.txt, encode the
74  * frame's JPEG in memory, base64 it, and publish {metadata + "image"} to a
75  * separate Kafka topic. Selection (fps/per-camera gating) is unchanged. */
76  gboolean kafka_image; /* on: no files, base64 image over kafka */
77  const char *kafka_image_topic; /* topic for image msgs; empty -> kafka_topic */
79 
80 /* Start the feature: creates the JPEG-encode context, starts the HTTP control
81  * server + async writer + retention sweeper. Returns TRUE on success.
82  * `cfg` may be NULL for defaults. */
83 gboolean frame_dump_init(const FrameDumpConfig *cfg);
84 
85 /* Convenience: read the [frame-dump] group from a DeepStream config file
86  * (GKeyFile .txt) and call frame_dump_init(). Missing group -> feature stays
87  * off but the object is still created so REST can enable it later.
88  * Keys (all optional): enable, fps, location, port, bind-address, gpu-id,
89  * quality, hour-subfolder, unique-filenames, retention-days, enable-sensors. */
90 gboolean frame_dump_init_from_file(const char *config_file, guint gpu_id);
91 
92 /* One-call wiring for the shared deepstream-app framework. On the FIRST call it
93  * lazily starts the feature from `config_file`'s [frame-dump] group (gpu-id read
94  * from that group; deinit auto-registered via atexit); every call attaches the
95  * probe to `tracker`. Safe to call from create_common_elements() of every
96  * pipeline — no-op if `tracker` is NULL. */
97 void frame_dump_wire(const char *config_file, GstElement *tracker);
98 
99 /* Attach the dump probe to the nvtracker element's SRC pad. Call after the
100  * pipeline elements exist. */
101 gboolean frame_dump_attach(GstElement *tracker);
102 
103 /* Stop the HTTP server + writer, flush, and release the encode context. */
104 void frame_dump_deinit(void);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* FRAME_DUMP_H */
frame_dump_wire
void frame_dump_wire(const char *config_file, GstElement *tracker)
_FrameDumpConfig::quality
gint quality
Definition: sources/apps/common/includes/frame_dump.h:57
_FrameDumpConfig::kafka_image_topic
const char * kafka_image_topic
Definition: sources/apps/common/includes/frame_dump.h:77
_FrameDumpConfig::http_port
const char * http_port
Definition: sources/apps/common/includes/frame_dump.h:50
_FrameDumpConfig::enabled
gboolean enabled
Definition: sources/apps/common/includes/frame_dump.h:54
_FrameDumpConfig::fps
gdouble fps
Definition: sources/apps/common/includes/frame_dump.h:55
frame_dump_init_from_file
gboolean frame_dump_init_from_file(const char *config_file, guint gpu_id)
frame_dump_init
gboolean frame_dump_init(const FrameDumpConfig *cfg)
_FrameDumpConfig::unique_filenames
gboolean unique_filenames
Definition: sources/apps/common/includes/frame_dump.h:59
_FrameDumpConfig::all_cameras
gboolean all_cameras
Definition: sources/apps/common/includes/frame_dump.h:61
_FrameDumpConfig::kafka_config_file
const char * kafka_config_file
Definition: sources/apps/common/includes/frame_dump.h:71
_FrameDumpConfig::kafka_enable
gboolean kafka_enable
Definition: sources/apps/common/includes/frame_dump.h:67
_FrameDumpConfig::retention_days
guint retention_days
Definition: sources/apps/common/includes/frame_dump.h:60
_FrameDumpConfig::default_output_dir
const char * default_output_dir
Definition: sources/apps/common/includes/frame_dump.h:52
_FrameDumpConfig
Definition: sources/apps/common/includes/frame_dump.h:49
_FrameDumpConfig::enable_sensors
const char * enable_sensors
Definition: sources/apps/common/includes/frame_dump.h:62
_FrameDumpConfig::kafka_proto_lib
const char * kafka_proto_lib
Definition: sources/apps/common/includes/frame_dump.h:70
_FrameDumpConfig::kafka_image
gboolean kafka_image
Definition: sources/apps/common/includes/frame_dump.h:76
_FrameDumpConfig::hour_subfolder
gboolean hour_subfolder
Definition: sources/apps/common/includes/frame_dump.h:58
_FrameDumpConfig::kafka_topic
const char * kafka_topic
Definition: sources/apps/common/includes/frame_dump.h:69
FrameDumpConfig
struct _FrameDumpConfig FrameDumpConfig
frame_dump_attach
gboolean frame_dump_attach(GstElement *tracker)
frame_dump_deinit
void frame_dump_deinit(void)
_FrameDumpConfig::kafka_broker
const char * kafka_broker
Definition: sources/apps/common/includes/frame_dump.h:68
_FrameDumpConfig::gpu_id
guint gpu_id
Definition: sources/apps/common/includes/frame_dump.h:53
_FrameDumpConfig::bind_address
const char * bind_address
Definition: sources/apps/common/includes/frame_dump.h:51