### Install GStreamer - apt-get - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md Installs the necessary GStreamer core libraries, plugins (base, good, bad, ugly, libav), tools, and development packages (including RTSP server) on Ubuntu using apt-get. This provides the multimedia framework required by VideoPipe. ```Shell apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio libgstrtspserver-1.0-dev gstreamer1.0-rtsp ``` -------------------------------- ### GStreamer Command - Soft Decode Example - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md A command-line example using gst-launch-1.0 to demonstrate software-based video decoding. It reads an MP4 file, demuxes, parses H.264, decodes using avdec_h264 (CPU), converts format, and outputs to an auto video sink. ```Shell gst-launch-1.0 filesrc location=./face.mp4 ! qtdemux ! h264parse ! avdec_h264 ! videoconvert ! autovideosink ``` -------------------------------- ### GStreamer Command - Soft Encode Example - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md A command-line example using gst-launch-1.0 to demonstrate software-based video encoding. It reads an MP4 file, decodes using avdec_h264 (CPU), encodes using x264enc (CPU), parses H.264, muxes into FLV, and saves to a file. ```Shell gst-launch-1.0 filesrc location=./face.mp4 ! qtdemux ! h264parse ! avdec_h264 ! x264enc ! h264parse ! flvmux ! filesink location=./new_face.flv ``` -------------------------------- ### RTSP Server Run Example Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/rtsp_server/README.md A practical example demonstrating how to start the RTSP server on port 8555, configured to receive UDP streams on ports 8000, 9000, and 9005, which will be served as RTSP streams 'rtsp0', 'rtsp1', and 'rtsp2'. ```Shell ./build/run_rtsp_server -p 8555 -s rtsp0:8000/rtsp1:9000/rtsp2:9005 ``` -------------------------------- ### GStreamer Command - Hardware Decode Example (NVIDIA) - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md A command-line example using gst-launch-1.0 to demonstrate hardware-accelerated video decoding using NVIDIA GPUs. It replaces the CPU-based avdec_h264 with nvv4l2decoder for decoding, reading an MP4 file, demuxing, parsing, decoding, converting, and outputting to an auto video sink. ```Shell gst-launch-1.0 filesrc location=./face.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! videoconvert ! autovideosink ``` -------------------------------- ### GStreamer Command - Hardware Encode Example (NVIDIA) - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md A command-line example using gst-launch-1.0 to demonstrate hardware-accelerated video encoding using NVIDIA GPUs. It decodes using avdec_h264 (CPU) and encodes using nvv4l2h264enc, reading an MP4 file, decoding, encoding, parsing, muxing into FLV, and saving to a file. ```Shell gst-launch-1.0 filesrc location=./face.mp4 ! qtdemux ! h264parse ! avdec_h264 ! nvv4l2h264enc ! h264parse ! flvmux ! filesink location=./new_face.flv ``` -------------------------------- ### GStreamer Pipeline - Soft Encode - C++ Context Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md A GStreamer pipeline string example used within the VideoPipe project (e.g., vp_file_des_node) for software-based video encoding. It takes appsrc input, converts video format, encodes using x264enc (CPU), muxes into MP4, and saves to a file. ```GStreamer appsrc ! videoconvert ! x264enc bitrate=%d ! mp4mux ! filesink location=%s ``` -------------------------------- ### Examples: Convert Weights (.wts) to TensorRT Engine (.engine) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_yolov8/README.md Provides specific command line examples demonstrating how to use the `trt_yolov8_wts_2_engine` executable to convert weights files (.wts) for various YOLOv8 models and tasks into TensorRT engine files (.engine). Examples cover detection, segmentation, pose estimation, and classification. ```Shell ./build/samples/trt_yolov8_wts_2_engine -det yolov8n.wts yolov8n.engine n ./build/samples/trt_yolov8_wts_2_engine -det yolov8s.wts yolov8s.engine s ./build/samples/trt_yolov8_wts_2_engine -seg yolov8n-seg.wts yolov8n-seg.engine n ./build/samples/trt_yolov8_wts_2_engine -seg yolov8s-seg.wts yolov8s-seg.engine s ./build/samples/trt_yolov8_wts_2_engine -pose yolov8n-pose.wts yolov8n-pose.engine n ./build/samples/trt_yolov8_wts_2_engine -pose yolov8s-pose.wts yolov8s-pose.engine s ./build/samples/trt_yolov8_wts_2_engine -cls yolov8n-cls.wts yolov8n-cls.engine n ./build/samples/trt_yolov8_wts_2_engine -cls yolov8s-cls.wts yolov8s-cls.engine s ``` -------------------------------- ### GStreamer Pipeline - Hardware Encode (NVIDIA) - C++ Context Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md A GStreamer pipeline string example for hardware-accelerated video encoding using NVIDIA GPUs. It replaces the CPU-based x264enc with nvv4l2h264enc (from DeepStream SDK or nvcodec) for improved performance, taking appsrc input, converting, encoding, muxing, and saving to a file. ```GStreamer appsrc ! videoconvert ! nvv4l2h264enc bitrate=%d ! mp4mux ! filesink location=%s ``` -------------------------------- ### Install CUDA Runfile (Linux) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Executes the CUDA installer runfile to install the CUDA toolkit and driver on a Linux system. This is a prerequisite for using TensorRT. ```shell ./cuda_11.1.0_455.23.05_linux.run ``` -------------------------------- ### Create and Enter Build Directory (Shell) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/paddle_ocr/README.md Creates a new directory named 'build' and changes the current directory into it. This is a standard first step for out-of-source builds using CMake. ```Shell mkdir build && cd build ``` -------------------------------- ### Configure OpenCV Build - CMake - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md Configures the OpenCV 4.6.0 build using CMake with various options enabled, including TBB, fast math, CUDA (with specific architecture 6.1), CUDNN, V4L, OpenGL, and crucially, GSTREAMER support. It also points to the extra contrib modules and disables examples. ```Shell step 2: cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_TBB=ON \ -D ENABLE_FAST_MATH=1 \ -D CUDA_FAST_MATH=1 \ -D WITH_CUBLAS=1 \ -D WITH_CUDA=ON \ -D BUILD_opencv_cudacodec=OFF \ -D WITH_CUDNN=ON \ -D OPENCV_DNN_CUDA=ON \ -D CUDA_ARCH_BIN=6.1 \ -D WITH_V4L=ON \ -D WITH_QT=OFF \ -D WITH_OPENGL=ON \ -D WITH_GSTREAMER=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_PC_FILE_NAME=opencv.pc \ -D OPENCV_ENABLE_NONFREE=ON \ -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.6.0/modules \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D INSTALL_C_EXAMPLES=OFF \ -D BUILD_EXAMPLES=OFF .. ``` -------------------------------- ### Examples: Convert PyTorch (.pt) to Weights (.wts) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_yolov8/README.md Provides specific command line examples demonstrating how to use the `gen_wts.py` script to convert various YOLOv8 models (nano, small) for different tasks (detect, seg, pose, cls) from the PyTorch format (.pt) to the weights format (.wts). ```Shell python3 samples/gen_wts.py -w yolov8n.pt -o yolov8n.wts -t detect python3 samples/gen_wts.py -w yolov8n-seg.pt -o yolov8n-seg.wts -t seg python3 samples/gen_wts.py -w yolov8n-pose.pt -o yolov8n-pose.wts python3 samples/gen_wts.py -w yolov8n-cls.pt -o yolov8n-cls.wts -t cls python3 samples/gen_wts.py -w yolov8s.pt -o yolov8s.wts -t detect python3 samples/gen_wts.py -w yolov8s-seg.pt -o yolov8s-seg.wts -t seg python3 samples/gen_wts.py -w yolov8s-pose.pt -o yolov8s-pose.wts python3 samples/gen_w8s-cls.pt -o yolov8s-cls.wts -t cls ``` -------------------------------- ### Example User-Defined Allocator Function Signatures (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Example signatures for user-defined memory allocation and deallocation functions required by `memory_pool::set_allocator`. The allocation function must return a valid pointer or handle failure appropriately. ```C++ void *allocate(std::size_t size); void free(void *pointer); ``` -------------------------------- ### Build RTSP Server with CMake Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/rtsp_server/README.md Standard CMake commands to configure and build the RTSP server project. Requires CMake and GStreamer development packages installed. ```Shell mkdir build && cd build cmake .. make -j8 ``` -------------------------------- ### Parsing XML with RapidXml in C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Demonstrates how to initialize an xml_document and parse a zero-terminated string using the parse function. It shows the basic setup including the namespace declaration and default parse flags. ```C++ using namespace rapidxml; xml_document<> doc; // character type defaults to char doc.parse<0>(text); // 0 means default parse flags ``` -------------------------------- ### Create TensorRT Symlink (Linux) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Creates a symbolic link from the specific TensorRT version directory to a generic 'tensorRT' path under /usr/local. This simplifies referencing the TensorRT installation directory. ```shell ln -s /usr/local/TensorRT-7.2.1.6 /usr/local/tensorRT ``` -------------------------------- ### Prepare OpenCV Build Directory - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md Changes the current directory to the OpenCV 4.6.0 source path, creates a 'build' directory, and then changes into the newly created build directory. This is the standard first step before running CMake to configure the build. ```Shell step 1: cd `the path of opencv 4.6.0` mkdir build && cd build ``` -------------------------------- ### Compile OpenCV - Make - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/doc/env.md Compiles the configured OpenCV project using the 'make' command with parallel jobs enabled (-j8). This step builds the libraries and executables based on the configuration set by CMake. ```Shell step 3: make -j8 ``` -------------------------------- ### Getting RapidXML xml_node Document (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves a pointer to the xml_document instance that contains this node as a child. Returns 0 if the node does not have a parent document. ```C++ xml_document* document() const; ``` -------------------------------- ### Getting First Attribute in RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the first attribute of the current node. Optionally matches by name, size, and case sensitivity. ```C++ xml_attribute* first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Accessing RapidXml DOM Tree in C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Illustrates how to navigate the parsed XML document tree. It shows how to get the first node, find a specific node by name, access node names and values, and iterate through a node's attributes. ```C++ cout << "Name of my first node is: " << doc.first_node()->name() << "\n"; xml_node<> *node = doc.first_node("foobar"); cout << "Node foobar has value " << node->value() << "\n"; for (xml_attribute<> *attr = node->first_attribute(); attr; attr = attr->next_attribute()) { cout << "Node foobar has attribute " << attr->name() << " "; cout << "with value " << attr->value() << "\n"; } ``` -------------------------------- ### Push UDP Stream to Port 9005 (GStreamer) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/rtsp_server/README.md GStreamer pipeline (gst-launch-1.0) to push the face2.mp4 video file as an RTP/H.264 UDP stream to localhost port 9005. This port is configured in the RTSP server example to be served as 'rtsp2'. ```GStreamer gst-launch-1.0 filesrc location=face2.mp4 ! qtdemux ! h264parse ! avdec_h264 ! x264enc ! rtph264pay ! udpsink host=localhost port=9005 ``` -------------------------------- ### Modifying RapidXml DOM Tree (Adding Elements) in C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Shows how to create new nodes and attributes using the document's memory pool and append them to the document or existing nodes. This example builds a simple HTML 'a' tag. ```C++ xml_document<> doc; xml_node<> *node = doc.allocate_node(node_element, "a", "Google"); doc.append_node(node); xml_attribute<> *attr = doc.allocate_attribute("href", "google.com"); node->append_attribute(attr); ``` -------------------------------- ### Push UDP Stream to Port 9000 (GStreamer) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/rtsp_server/README.md GStreamer pipeline (gst-launch-1.0) to push the face2.mp4 video file as an RTP/H.264 UDP stream to localhost port 9000. This port is configured in the RTSP server example to be served as 'rtsp1'. ```GStreamer gst-launch-1.0 filesrc location=face2.mp4 ! qtdemux ! h264parse ! avdec_h264 ! x264enc ! rtph264pay ! udpsink host=localhost port=9000 ``` -------------------------------- ### Getting Name of xml_base Node C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the name of the XML node or attribute. The interpretation depends on the specific node type. The returned pointer may not be zero-terminated if the parse_no_string_terminators option was used; use name_size() to get the length. Returns a pointer to the name string or an empty string if no name exists. ```C++ Ch* name() const; ``` -------------------------------- ### Get RapidXML parse_error Description (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves a human-readable description of the parse error. This function is part of the `std::exception` interface from which `parse_error` derives. ```C++ virtual const char* what() const; ``` -------------------------------- ### Getting Last Attribute in RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the last attribute of the current node. Optionally matches by name, size, and case sensitivity. ```C++ xml_attribute* last_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Getting Next Sibling Node in RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the next sibling node of the current node. Optionally matches by name, size, and case sensitivity. Behaviour is undefined if the node has no parent. ```C++ xml_node* next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Get Node Parent (RapidXML C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves a pointer to the parent node of the current node. Returns a null pointer (0) if the node does not have a parent (e.g., the document node). ```C++ xml_node* parent() const; ``` -------------------------------- ### Getting RapidXML xml_node Type (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the type of the XML node. The node type determines the interpretation of the node's name and value. ```C++ node_type type() const; ``` -------------------------------- ### Getting Parent Document of xml_attribute C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves a pointer to the xml_document that contains this attribute. Returns a pointer to the document, or 0 if the attribute has no parent document. ```C++ xml_document* document() const; ``` -------------------------------- ### Push UDP Stream to Port 8000 (GStreamer) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/rtsp_server/README.md GStreamer pipeline (gst-launch-1.0) to read an H.264 file (face2.mp4), process it, and send it as an RTP/H.264 UDP stream to localhost port 8000. This port is configured in the RTSP server example to be served as 'rtsp0'. ```GStreamer gst-launch-1.0 filesrc location=face2.mp4 ! qtdemux ! h264parse ! avdec_h264 ! x264enc ! rtph264pay ! udpsink host=localhost port=8000 ``` -------------------------------- ### Getting Next xml_attribute C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the next attribute in the list, optionally filtering by name. Parameters allow specifying the name to match, its size, and whether the comparison is case-sensitive. Returns a pointer to the found attribute or 0 if none is found. ```C++ xml_attribute* next_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Getting First Child Node in RapidXML (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the first child node of the current node, with an option to filter by name. The name comparison can be case-sensitive or non-case-sensitive (for ASCII). Returns 0 if no matching child is found. ```C++ xml_node* first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Getting Previous Sibling Node in RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the previous sibling node of the current node. Optionally matches by name, size, and case sensitivity. Behaviour is undefined if the node has no parent. ```C++ xml_node* previous_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Get RapidXML parse_error Location (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves a pointer to the character data within the parsed string where the error was detected. The character type `Ch` matches that used by the `xml_document`. ```C++ Ch* where() const; ``` -------------------------------- ### Getting Value of xml_base Node C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the value of the XML node or attribute. The interpretation depends on the specific type. Returns a pointer to the value string or an empty string if no value exists. ```C++ Ch* value() const; ``` -------------------------------- ### Getting Name Size of xml_base Node C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the size of the node or attribute name in characters. This function correctly reports the size regardless of whether the name string is zero-terminated. Returns the size of the name. ```C++ std::size_t name_size() const; ``` -------------------------------- ### Get Node Value Size (RapidXML C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the size of the node's value in characters, excluding any null terminator. This function is reliable regardless of whether the value string is null-terminated or not. ```C++ std::size_t value_size() const; ``` -------------------------------- ### Getting Previous xml_attribute C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the previous attribute in the list, optionally filtering by name. Parameters allow specifying the name to match, its size, and whether the comparison is case-sensitive. Returns a pointer to the found attribute or 0 if none is found. ```C++ xml_attribute* previous_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Build tinyexpr library and sample (Shell) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/tinyexpr/README.md These commands demonstrate the standard build process for the tinyexpr library and its sample application. It involves creating a build directory, navigating into it, configuring the build using CMake, and then compiling the project using Make. ```Shell mkdir build && cd build cmake .. make ``` -------------------------------- ### Getting Last Child Node in RapidXML (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Retrieves the last child node of the current node, with an option to filter by name. Behaviour is undefined if the node has no children; use first_node() to check for children first. Returns 0 if no matching child is found. ```C++ xml_node* last_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; ``` -------------------------------- ### Initializing the Videopipe Logger (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/utils/logger/README.md Explains the critical step of initializing the Videopipe logger by calling `VP_LOGGER_INIT()`. This function must be called at the beginning of the `main()` function to set up the logging system. ```C++ // important! call at the begining of main() VP_LOGGER_INIT(); ``` -------------------------------- ### Standard VideoPipe Compilation Steps Source: https://github.com/sherlockchou86/videopipe/blob/master/README.md These commands outline the standard procedure for cloning the VideoPipe repository, navigating into the project directory, creating and entering a build directory, configuring the project with CMake (defaulting to CPU build), and compiling the project using Make. ```Bash git clone https://github.com/sherlockchou86/VideoPipe.git cd VideoPipe mkdir build && cd build cmake .. make -j8 ``` -------------------------------- ### Run a Compiled Sample Executable Source: https://github.com/sherlockchou86/videopipe/blob/master/README.md This command shows how to execute a compiled sample program from the VideoPipe build directory. It assumes the command is run from the location where the 'vp_data' directory (containing models and test files) is placed. ```Bash [path to VideoPipe]/build/bin/1-1-1_sample ``` -------------------------------- ### Compile and Run t-SNE Test - Shell Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/bhtsne/README.md These shell commands demonstrate how to compile the t-SNE test program using g++ with optimization level O2 and then execute the compiled binary. ```Shell g++ tsne_test.cpp -o bh_tsne_test -O2 ``` ```Shell ./bh_tsne_test ``` -------------------------------- ### Build and Run 1-1-N Sample Pipeline with VideoPipe C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/README.md Demonstrates how to construct and run a VideoPipe pipeline in C++. It sets up a pipeline with a file source, face detection, face recognition, OSD for drawing results, and two output destinations (screen display and RTMP stream). The code links the nodes sequentially and then splits the pipeline for the two outputs. Requires VideoPipe library and models. Remember to update file paths for video input and models. ```c++ #include "../nodes/vp_file_src_node.h" #include "../nodes/infers/vp_yunet_face_detector_node.h" #include "../nodes/infers/vp_sface_feature_encoder_node.h" #include "../nodes/osd/vp_face_osd_node_v2.h" #include "../nodes/vp_screen_des_node.h" #include "../nodes/vp_rtmp_des_node.h" #include "../utils/analysis_board/vp_analysis_board.h" /* * Name: 1-1-N Sample * Complete code located at: samples/1-1-N_sample.cpp * Functionality: 1 video input, 1 video analysis task (face detection and recognition), 2 outputs (screen display/RTMP stream) */ int main() { VP_SET_LOG_INCLUDE_CODE_LOCATION(false); VP_SET_LOG_INCLUDE_THREAD_ID(false); VP_LOGGER_INIT(); // 1. Create nodes // Video Source Node auto file_src_0 = std::make_shared("file_src_0", 0, "./test_video/10.mp4", 0.6); // 2. Model Inference Nodes // First-level inference: Face detection auto yunet_face_detector_0 = std::make_shared("yunet_face_detector_0", "./models/face/face_detection_yunet_2022mar.onnx"); // Second-level inference: Face recognition auto sface_face_encoder_0 = std::make_shared("sface_face_encoder_0", "./models/face/face_recognition_sface_2021dec.onnx"); // 3. OSD Node // Draw results on frames auto osd_0 = std::make_shared("osd_0"); // Screen Display Node auto screen_des_0 = std::make_shared("screen_des_0", 0); // RTMP Stream Node auto rtmp_des_0 = std::make_shared("rtmp_des_0", 0, "rtmp://192.168.77.60/live/10000"); // Build the pipeline by linking the nodes yunet_face_detector_0->attach_to({file_src_0}); sface_face_encoder_0->attach_to({yunet_face_detector_0}); osd_0->attach_to({sface_face_encoder_0}); // Split the pipeline automatically to display results on screen and stream via RTMP screen_des_0->attach_to({osd_0}); rtmp_des_0->attach_to({osd_0}); // Start the pipeline file_src_0->start(); // Visualize the pipeline vp_utils::vp_analysis_board board({file_src_0}); board.display(); } ``` -------------------------------- ### Run CMake Configuration (Shell) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Executes CMake from within the 'build' directory, pointing to the parent directory ('..') where the project's CMakeLists.txt file resides. This configures the build system based on the CMake scripts. ```shell cmake .. ``` -------------------------------- ### Create Build Directory and Navigate (Shell) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Creates a new directory named 'build' in the current location and changes the current working directory into it. This is a standard first step for out-of-source CMake builds. ```shell mkdir build && cd build ``` -------------------------------- ### Configuring Videopipe Logger Settings (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/utils/logger/README.md Provides macros for configuring various aspects of the Videopipe logger, including log level, output directories, Kafka integration, console/file/Kafka output toggles, and inclusion of metadata like level, code location, and thread ID. ```C++ // log level VP_SET_LOG_LEVEL(_log_level); // log file dir VP_SET_LOG_DIR(_log_dir); // log kafka servers and topic VP_SET_LOG_KAFKA_SERVERS_AND_TOPIC(_kafka_servers_and_topic); // log to console or not VP_SET_LOG_TO_CONSOLE(_log_to_console); // log to file or not VP_SET_LOG_TO_FILE(_log_to_file); // log to kafka or not VP_SET_LOG_TO_KAFKA(_log_to_kafka); // include log level or not VP_SET_LOG_INCLUDE_LEVEL(_include_level); // include code location or not (where the log occurs) VP_SET_LOG_INCLUDE_CODE_LOCATION(_include_code_location); // include thread id or not (std::this_thread::get_id()) VP_SET_LOG_INCLUDE_THREAD_ID(_include_thread_id); // warn if log cache in memory exceed this value VP_SET_LOG_CACHE_WARN_THRES(_log_cache_warn_threshold); ``` -------------------------------- ### Build Project with Make (Shell) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Compiles the project using the Make build system, which was configured by CMake. The `-j8` flag enables parallel compilation using 8 jobs for faster build times. ```shell make -j8 ``` -------------------------------- ### RTSP Server Run Syntax Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/rtsp_server/README.md Command-line syntax for executing the compiled RTSP server. Options include specifying the main RTSP port (-p) and mapping stream names to internal UDP input ports (-s). ```Shell ./build/run_rtsp_server [-p] [rtsp_port] [-s] [stream_name1:inner_port1/stream_name2:inner_port2/...] ``` -------------------------------- ### Build trt_yolov8 Project using CMake Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_yolov8/README.md Provides the standard sequence of shell commands to build the trt_yolov8 project. This involves creating a build directory, navigating into it, configuring the build with CMake, and compiling the project using make with parallel jobs. ```Shell mkdir build && cd build cmake .. make -j8 ``` -------------------------------- ### Printing XML with Flags (RapidXML C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Prints an XML node or document to a given output stream with customizable formatting options specified by flags. Requires an output stream, the XML node/document, and an optional integer for flags. ```C++ std::basic_ostream& rapidxml::print(std::basic_ostream< Ch > &out, const xml_node< Ch > &node, int flags=0); ``` -------------------------------- ### Writing Log Messages at Different Levels (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/utils/logger/README.md Shows the four main macros provided by the Videopipe logger for writing messages at different severity levels: `VP_ERROR`, `VP_WARN`, `VP_INFO`, and `VP_DEBUG`. ```C++ // error VP_ERROR(message); // warn VP_WARN(message); // info VP_INFO(message); // debug VP_DEBUG(message); ``` -------------------------------- ### Constructing RapidXML xml_document (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Constructs an empty XML document. This is the default constructor for the xml_document class. ```C++ xml_document(); ``` -------------------------------- ### Generate TensorRT Engine from ONNX (Shell) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Uses the `trtexec` tool provided by TensorRT to build an optimized engine file (`.trt`) from an ONNX model file (`.onnx`). The `--buildOnly=true` flag ensures only the build step is performed. ```shell trtexec --onnx=./vehicle.onnx --saveEngine=vehicleXXX.trt --buildOnly=true ``` -------------------------------- ### Constructing xml_base C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Default constructor for the xml_base class. ```C++ xml_base(); ``` -------------------------------- ### Convert Weights (.wts) to TensorRT Engine (.engine) using C++ Executable Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_yolov8/README.md Describes the command line syntax for the `trt_yolov8_wts_2_engine` executable, which converts a weights file (.wts) into a TensorRT engine file (.engine). It requires specifying the task type, input weights file, output engine file, and model size. ```Shell ./trt_yolov8_wts_2_engine [-det/-seg/-pose/-cls] [.wts] [.engine] [n/s/m/l/x/n2/s2/m2/l2/x2/n6/s6/m6/l6/x6] ``` -------------------------------- ### RapidXML parse_error Constructor (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Constructs a `parse_error` exception object. Takes a description string and a pointer to the location in the source text where the error occurred. ```C++ parse_error(const char *what, void *where); ``` -------------------------------- ### Constructing rapidxml::memory_pool (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Constructs an empty memory pool with default allocator functions. ```C++ memory_pool(); ``` -------------------------------- ### Source Bash Profile (Linux) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Reloads the user's .bashrc file to apply the updated environment variables (LD_LIBRARY_PATH and CPATH) in the current shell session. ```shell source ~/.bashrc ``` -------------------------------- ### Adding Manual Fields to Log Message (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/utils/logger/README.md Demonstrates how to manually add important fields like the host node name and task type to a log message using `VP_INFO` and `vp_utils::string_format` for structured logging. ```C++ VP_INFO(vp_utils::string_format("[%s] [record] save dir not exists, now creating save dir: `%s`", host_node_name, save_dir)); ``` -------------------------------- ### Add TensorRT and CUDA Library Paths (Linux) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Appends the TensorRT and CUDA library directories to the LD_LIBRARY_PATH environment variable. This allows the system to find the necessary shared libraries at runtime. ```shell export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/tensorRT/lib:/usr/local/cuda/lib64:/usr/local/lib ``` -------------------------------- ### Convert PyTorch (.pt) to Weights (.wts) using Python Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_yolov8/README.md Describes the command line syntax for the `gen_wts.py` script used to convert a PyTorch YOLOv8 model file (.pt) into a weights file (.wts). It specifies the required arguments for input file, output file, and task type (detect, seg, cls). ```Shell python3 samples/gen_wts.py [-w] [.pt] [-o] [.wts] [-t] [detect/seg/cls] ``` -------------------------------- ### Printing RapidXml DOM Tree to Output in C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Provides multiple methods for serializing the XML document or node to various outputs, including standard streams using operator<<, the print function with streams and flags, printing to a std::string using an iterator, and printing to a fixed-size character buffer. ```C++ using namespace rapidxml; xml_document<> doc; // character type defaults to char // ... some code to fill the document // Print to stream using operator << std::cout << doc; // Print to stream using print function, specifying printing flags print(std::cout, doc, 0); // 0 means default printing flags // Print to string using output iterator std::string s; print(std::back_inserter(s), doc, 0); // Print to memory buffer using output iterator char buffer[4096]; // You are responsible for making the buffer large enough! char *end = print(buffer, doc, 0); // end contains pointer to character after last printed character *end = 0; // Add string terminator after XML ``` -------------------------------- ### Add TensorRT and CUDA Include Paths (Linux) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/trt_vehicle/README.md Appends the TensorRT and CUDA include directories to the CPATH environment variable. This is required for the compiler to find header files during the build process. ```shell export CPATH=$CPATH:/usr/local/cuda/include:/usr/local/tensorRT/include ``` -------------------------------- ### Configure CMake for Default CPU Build Source: https://github.com/sherlockchou86/videopipe/blob/master/README.md Running CMake without specific hardware acceleration options configures the VideoPipe project for a default build that utilizes the CPU for processing. This is the standard configuration if you do not require CUDA, TensorRT, or other optional hardware backends. ```Bash cmake .. ``` -------------------------------- ### Constructing RapidXML xml_node (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Constructs an empty XML node with the specified type. It is recommended to use the memory pool of an appropriate document to allocate nodes manually for proper memory management. ```C++ xml_node(node_type type); ``` -------------------------------- ### Configure CMake with CUDA and TensorRT Enabled Source: https://github.com/sherlockchou86/videopipe/blob/master/README.md This command configures the VideoPipe project build using CMake, specifically enabling support for CUDA and TensorRT by setting the corresponding options to ON. This is necessary if you plan to use inference backends that rely on these technologies. ```Bash cmake -DVP_WITH_CUDA=ON -DVP_WITH_TRT=ON .. ``` -------------------------------- ### Printing XML with Stream Operator (RapidXML C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Prints a formatted XML node or document to a given output stream using default printing flags. This is a convenient overload of the stream insertion operator. Requires an output stream and the XML node/document. ```C++ std::basic_ostream& rapidxml::operator<<(std::basic_ostream< Ch > &out, const xml_node< Ch > &node); ``` -------------------------------- ### Allocate String in RapidXML Memory Pool (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Allocates a character array of a specified size from the memory pool. Optionally initializes the allocated memory by copying a source string. Throws `std::bad_alloc` on failure unless `RAPIDXML_NO_EXCEPTIONS` is defined, in which case it calls `rapidxml::parse_error_handler()`. ```C++ Ch* allocate_string(const Ch *source=0, std::size_t size=0); ``` -------------------------------- ### Clone RapidXML Node (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Clones an `xml_node` and its entire hierarchy (children and attributes) using the memory pool. Names and values are shared, not copied. An optional result node can be provided to clone into, useful for cloning entire documents. ```C++ xml_node* clone_node(const xml_node< Ch > *source, xml_node< Ch > *result=0); ``` -------------------------------- ### Prepend Attribute - RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Prepends a new attribute to the beginning of the node's attribute list. Parameters: attribute: The attribute to prepend. ```C++ void prepend_attribute(xml_attribute< Ch > *attribute); ``` -------------------------------- ### RapidXML xml_document Class Definition (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Defines the rapidxml::xml_document class template, which inherits from xml_node and memory_pool. This class represents the root of an XML document and provides memory management capabilities. ```C++ class template rapidxml::xml_document ``` -------------------------------- ### Prepending Child Node in RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Adds a new child node to the beginning of the current node's children list. The prepended child becomes the first child, and all existing children are moved one position back. ```C++ void prepend_node(xml_node< Ch > *child); ``` -------------------------------- ### RapidXml Parse Flag Combination: parse_fastest (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html A combination of parse flags (parse_non_destructive | parse_no_data_nodes) designed for the fastest possible parsing speed without sacrificing important data. Refer to the xml_document::parse() function for usage. ```C++ const int parse_fastest = parse_non_destructive | parse_no_data_nodes; ``` -------------------------------- ### Insert Attribute - RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Inserts a new attribute at a specified position within the node's attribute list. All attributes at or after the insertion point are shifted back. Parameters: where: The attribute before which the new attribute should be inserted, or 0 to insert at the end. attribute: The attribute to insert. ```C++ void insert_attribute(xml_attribute< Ch > *where, xml_attribute< Ch > *attribute); ``` -------------------------------- ### Allocating rapidxml XML Node (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Allocates a new XML node from the pool, optionally assigning a name and value. Throws std::bad_alloc on failure unless exceptions are disabled, in which case it calls rapidxml::parse_error_handler(). ```C++ xml_node* allocate_node(node_type type, const Ch *name=0, const Ch *value=0, std::size_t name_size=0, std::size_t value_size=0); ``` -------------------------------- ### RapidXml Parse Flag Combination: parse_full (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html A combination of parse flags (parse_declaration_node | parse_comment_nodes | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags) intended for parsing a full XML structure including declarations, comments, doctype, processing instructions, and validating closing tags. Refer to the xml_document::parse() function for usage. ```C++ const int parse_full = parse_declaration_node | parse_comment_nodes | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags; ``` -------------------------------- ### Define Parse Error Handler - RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html This function must be defined by the user when RAPIDXML_NO_EXCEPTIONS is defined. It is called to report parsing errors and must not return. A simple implementation might print the error and abort. Parameters: what: Human-readable description of the error. where: Pointer to the character data where the error occurred. ```C++ void rapidxml::parse_error_handler(const char *what, void *where); ``` ```C++ void rapidxml::parse_error_handler(const char *what, void *where) { std::cout << "Parse error: " << what << "\n"; std::abort(); } ``` -------------------------------- ### Print XML Node - RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Prints the XML representation of a node (or document) to a given output iterator. Parameters: out: The output iterator to print to. node: The node (or document) to be printed. flags: Flags controlling the printing format. Returns: An output iterator pointing to the position immediately after the last character printed. ```C++ OutIt rapidxml::print(OutIt out, const xml_node< Ch > &node, int flags=0); ``` -------------------------------- ### Allocating String for Node Name/Value in RapidXml C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Explains the need to manage string lifetimes when modifying the DOM tree. Demonstrates using the document's allocate_string function to create strings that persist as long as the document. ```C++ xml_document<> doc; char *node_name = doc.allocate_string(name); // Allocate string and copy name into it xml_node<> *node = doc.allocate_node(node_element, node_name); // Set node name to node_name ``` -------------------------------- ### RapidXML Parse Flag: Create DOCTYPE Node (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html A parse flag constant (0x80) that instructs the RapidXML parser to create a DOCTYPE node if present in the source text. By default, the DOCTYPE node is not created. Can be combined with other flags using the bitwise OR operator. ```C++ const int parse_doctype_node = 0x80; ``` -------------------------------- ### RapidXml Parse Flag: parse_default (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Represents the default behavior of the parser. This flag is always 0, allowing other flags to be combined using the bitwise OR operator (|) without needing to explicitly disable default settings. The meaning of other flags is often a negation of the default behavior. Refer to the xml_document::parse() function for usage. ```C++ const int parse_default = 0; ``` -------------------------------- ### Set Custom Allocator for RapidXML Memory Pool (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Sets user-defined memory allocation and deallocation functions for the pool. This function can only be called when the pool is empty. Custom allocation functions must handle failure by throwing, stopping the program, or using `longjmp`. ```C++ void set_allocator(alloc_func *af, free_func *ff); ``` -------------------------------- ### Allocating rapidxml XML Attribute (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Allocates a new XML attribute from the pool, optionally assigning a name and value. Throws std::bad_alloc on failure unless exceptions are disabled, in which case it calls rapidxml::parse_error_handler(). ```C++ xml_attribute* allocate_attribute(const Ch *name=0, const Ch *value=0, std::size_t name_size=0, std::size_t value_size=0); ``` -------------------------------- ### Parsing XML String with RapidXML xml_document (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Parses a zero-terminated XML string into the document according to given flags. The input string may be modified unless parse_non_destructive is used and must persist for the document's lifetime. Throws parse_error on failure. ```C++ void parse(Ch *text); ``` -------------------------------- ### Inserting Child Node in RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Inserts a new child node at specified place inside the node. All children after and including the specified node are moved one position back. ```C++ void insert_node(xml_node< Ch > *where, xml_node< Ch > *child); ``` -------------------------------- ### Remove All Attributes - RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Removes all attributes from the node. ```C++ void remove_all_attributes(); ``` -------------------------------- ### RapidXML Parse Flag: Create Comment Nodes (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html A parse flag constant (0x40) that instructs the RapidXML parser to create comment nodes if present in the source text. By default, comment nodes are not created. Can be combined with other flags using the bitwise OR operator. ```C++ const int parse_comment_nodes = 0x40; ``` -------------------------------- ### RapidXML Parse Flag: Create Declaration Node (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html A parse flag constant (0x20) that instructs the RapidXML parser to create an XML declaration node if present in the source text. By default, the declaration node is not created. Can be combined with other flags using the bitwise OR operator. ```C++ const int parse_declaration_node = 0x20; ``` -------------------------------- ### Constructing xml_attribute C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Constructs an empty attribute of the specified character type. It is recommended to use the memory pool of the associated xml_document when manually allocating attributes. ```C++ xml_attribute(); ``` -------------------------------- ### Setting Node Type in RapidXML C++ Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Sets the type of the current node. ```C++ void type(node_type type); ``` -------------------------------- ### Set Node Name (Zero-Terminated String) (RapidXML C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Sets the node's name using a pointer to a null-terminated character array. The function automatically calculates the string length. Similar to the non-terminated version, the node does not own the string memory. ```C++ void name(const Ch *name); ``` -------------------------------- ### Set Node Name (Non-Terminated String) (RapidXML C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Sets the node's name using a pointer to a character array and its explicit size. The string does not need to be null-terminated. The node does not own the string memory; lifetime management is the user's responsibility, often handled by the document's memory pool. ```C++ void name(const Ch *name, std::size_t size); ``` -------------------------------- ### RapidXml Parse Flag: parse_pi_nodes (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Parse flag instructing the parser to create PI nodes. By default, PI nodes are not created. Can be combined with other flags using the bitwise OR operator (|). Refer to the xml_document::parse() function for usage. ```C++ const int parse_pi_nodes = 0x100; ``` -------------------------------- ### Set Node Value (Zero-Terminated String) (RapidXML C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Sets the node's value using a pointer to a null-terminated character array. The function automatically calculates the string length. Similar to the non-terminated version, the node does not own the string memory. ```C++ void value(const Ch *value); ``` -------------------------------- ### Clearing RapidXML xml_document (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Clears the document by deleting all nodes and attributes and clearing the associated memory pool. All memory allocated by the document's pool is released. ```C++ void clear(); ``` -------------------------------- ### Destroying rapidxml::memory_pool (C++) Source: https://github.com/sherlockchou86/videopipe/blob/master/third_party/cereal/external/rapidxml/manual.html Destroys the memory pool and frees all allocated memory, invalidating nodes and attributes obtained from it. ```C++ ~memory_pool(); ```