Explorar o código

update record

leon hai 3 semanas
pai
achega
cc7a91d610

+ 0 - 23
src/graph/graph.cpp

@@ -155,29 +155,6 @@ void Graph::create_from_json(const std::string& json_path)
 
                         } 
                         else if (node_type == "Recorder") 
-                        {
-                            std::string record_path = params.at("record_path").get<std::string>();
-                            auto record_node = std::make_shared<GNode::RecordNode>(node_id);
-                            record_node->set_record_path(record_path);
-                            if (params.contains("fps")) 
-                            {
-                                record_node->set_fps(params["fps"].get<int>());
-                            }
-                            if (params.contains("fourcc")) 
-                            {
-                                std::string fourcc_str = params["fourcc"].get<std::string>();
-                                if (fourcc_str.length() == 4) 
-                                {
-                                    record_node->set_fourcc(cv::VideoWriter::fourcc(fourcc_str[0], fourcc_str[1], fourcc_str[2], fourcc_str[3]));
-                                } 
-                                else 
-                                {
-                                    std::cerr << "Warning: Invalid fourcc string '" << fourcc_str << "' for node " << node_id << ". Using default." << std::endl;
-                                }
-                            }
-                            new_node = record_node;
-                        } 
-                        else if (node_type == "Rtmp") 
                         {
                             std::string gst_pipeline = params.at("gst_pipeline").get<std::string>();
                             int fps = params.value("fps", 25);

+ 0 - 1
src/graph/graph.hpp

@@ -14,7 +14,6 @@
 #include "nodes/analyze/analyzeNode.hpp"
 #include "nodes/draw/drawNode.hpp"
 #include "nodes/record/recordNode.hpp"
-#include "nodes/rtmp/rtmpNode.hpp"
 #include "nodes/httpPush/httpPush.hpp"
 
 

+ 9 - 3
src/nodes/record/recordNode.cpp

@@ -1,6 +1,6 @@
 #include "common/data.hpp"
 #include "common/meta.hpp"
-#include "nodes/record/recordNode.hpp"
+#include "nodes/record/RecordNode.hpp"
 
 namespace GNode
 {
@@ -8,16 +8,22 @@ namespace GNode
 void RecordNode::handle_data(std::shared_ptr<meta::MetaData>& meta_data)
 {
     cv::Mat image = meta_data->draw_image;
+    int width = image.cols;
+    int height = image.rows;
     if (!writer_.isOpened())
     {
-        writer_.open(record_path_, fourcc_, fps_, cv::Size(image.cols, image.rows));
+        writer_.open(gst_pipeline_, cv::CAP_GSTREAMER, 0, fps_, cv::Size(width, height), true);
         if (!writer_.isOpened())
         {
             PLOGE.printf("RecordNode : [%s] cannot open video writer", name_.c_str());
             stop();
         }
     }
+
     writer_ << image;
 }
 
-}   // namespace GNode
+}   // namespace GNode
+
+
+// appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=ultrafast ! h264parse ! flvmux streamable=true  ! queue ! rtmpsink location='rtmp://172.16.20.168:1935/live' sync=false async=false

+ 48 - 9
src/nodes/record/recordNode.hpp

@@ -1,7 +1,9 @@
 #ifndef RECORDNODE_HPP__
 #define RECORDNODE_HPP__
+
 #include "nodes/base/base.hpp"
 #include "opencv2/opencv.hpp"
+#include "opencv2/videoio.hpp"
 
 // 日志库
 #include "plog/Log.h"
@@ -14,7 +16,12 @@ class RecordNode : public BaseNode
 {
 public:
     RecordNode() = delete;
-    RecordNode(const std::string& name) : BaseNode(name, NODE_TYPE::DES_NODE) {}
+    RecordNode(const std::string& name, const std::string& gst_pipeline, int fps = 25) 
+        : BaseNode(name, NODE_TYPE::DES_NODE) 
+    {
+        fps_ = fps;
+        gst_pipeline_ = gst_pipeline;
+    }
     virtual ~RecordNode() 
     { 
         stop(); 
@@ -25,15 +32,47 @@ public:
     }
 
     void handle_data(std::shared_ptr<meta::MetaData>& meta_data) override;
-    void set_record_path(const std::string& path) { record_path_ = path; }
-    void set_fps(int fps) { fps_ = fps; }
-    void set_fourcc(int fourcc) { fourcc_ = fourcc; }
 private:
-    std::string record_path_;
-    int fps_ = 25;
-    int fourcc_ = cv::VideoWriter::fourcc('X', '2', '6', '4');
+    int fps_ = 35;
+    std::string gst_pipeline_;
     cv::VideoWriter writer_;
 };
-    
+
 }
-#endif // RECORDNODE_HPP__
+
+#endif // RTMPNODE_HPP__
+
+
+/*
+cmake -D CMAKE_BUILD_TYPE=RELEASE \
+-D BUILD_TESTS=OFF \
+-D BUILD_PERF_TESTS=OFF \
+-D BUILD_EXAMPLES=OFF \
+-D BUILD_opencv_apps=OFF \
+-D BUILD_PNG=ON \
+-D BUILD_JPEG=ON \
+-D BUILD_TIFF=ON \
+-D BUILD_WEBP=ON \
+-D OpenJPEG=ON \
+-D BUILD_OPENEXR=ON \
+-D OPENCV_GENERATE_PKGCONFIG=ON \
+-D OPENCV_EXTRA_MODULES_PATH=/workspace/compile/opencv490/opencv_contrib-4.9.0/modules \
+-D WITH_CUDA=OFF \
+-D WITH_CUDNN=OFF \
+-D BUILD_PROTOBUF=ON \
+-D OPENCV_DNN_CUDA=OFF \
+-D CUDA_FAST_MATH=OFF \
+-D WITH_CUBLAS=OFF \
+-D WITH_GSTREAMER=ON \
+-D WITH_FFMPEG=ON \
+-D WITH_QT=OFF \
+-D WITH_GTK=OFF \
+-D BUILD_JAVA=OFF \
+-D WITH_1394=OFF \
+-D CMAKE_INSTALL_PREFIX=/workspace/compile/__install/opencv490-gst ..
+
+
+
+appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast bitrate=600 key-int-max=50 ! video/x-h264,profile=baseline ! rtspclientsink location=rtsp://172.16.20.168:8554/mystream
+
+*/

+ 0 - 29
src/nodes/rtmp/rtmpNode.cpp

@@ -1,29 +0,0 @@
-#include "common/data.hpp"
-#include "common/meta.hpp"
-#include "nodes/rtmp/rtmpNode.hpp"
-
-namespace GNode
-{
-
-void RtmpNode::handle_data(std::shared_ptr<meta::MetaData>& meta_data)
-{
-    cv::Mat image = meta_data->draw_image;
-    int width = image.cols;
-    int height = image.rows;
-    if (!writer_.isOpened())
-    {
-        writer_.open(gst_pipeline_, cv::CAP_GSTREAMER, 0, fps_, cv::Size(width, height), true);
-        if (!writer_.isOpened())
-        {
-            PLOGE.printf("RtmpNode : [%s] cannot open video writer", name_.c_str());
-            stop();
-        }
-    }
-
-    writer_ << image;
-}
-
-}   // namespace GNode
-
-
-// appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=ultrafast ! h264parse ! flvmux streamable=true  ! queue ! rtmpsink location='rtmp://172.16.20.168:1935/live' sync=false async=false

+ 0 - 73
src/nodes/rtmp/rtmpNode.hpp

@@ -1,73 +0,0 @@
-#ifndef RTMPNODE_HPP__
-#define RTMPNODE_HPP__
-
-#include "nodes/base/base.hpp"
-#include "opencv2/opencv.hpp"
-#include "opencv2/videoio.hpp"
-
-// 日志库
-#include "plog/Log.h"
-#include "plog/Initializers/RollingFileInitializer.h"
-
-namespace GNode
-{
-
-class RtmpNode : public BaseNode
-{
-public:
-    RtmpNode() = delete;
-    RtmpNode(const std::string& name, const std::string& gst_pipeline, int fps = 25) 
-        : BaseNode(name, NODE_TYPE::DES_NODE) 
-    {
-        fps_ = fps;
-        gst_pipeline_ = gst_pipeline;
-    }
-    virtual ~RtmpNode() 
-    { 
-        stop(); 
-        if (writer_.isOpened())
-        {
-            writer_.release();
-        }
-    }
-
-    void handle_data(std::shared_ptr<meta::MetaData>& meta_data) override;
-private:
-    int fps_ = 35;
-    std::string gst_pipeline_;
-    cv::VideoWriter writer_;
-};
-
-}
-
-#endif // RTMPNODE_HPP__
-
-
-/*
-cmake -D CMAKE_BUILD_TYPE=RELEASE \
--D BUILD_TESTS=OFF \
--D BUILD_PERF_TESTS=OFF \
--D BUILD_EXAMPLES=OFF \
--D BUILD_opencv_apps=OFF \
--D BUILD_PNG=ON \
--D BUILD_JPEG=ON \
--D BUILD_TIFF=ON \
--D BUILD_WEBP=ON \
--D OpenJPEG=ON \
--D BUILD_OPENEXR=ON \
--D OPENCV_GENERATE_PKGCONFIG=ON \
--D OPENCV_EXTRA_MODULES_PATH=/workspace/compile/opencv490/opencv_contrib-4.9.0/modules \
--D WITH_CUDA=OFF \
--D WITH_CUDNN=OFF \
--D BUILD_PROTOBUF=ON \
--D OPENCV_DNN_CUDA=OFF \
--D CUDA_FAST_MATH=OFF \
--D WITH_CUBLAS=OFF \
--D WITH_GSTREAMER=ON \
--D WITH_FFMPEG=ON \
--D WITH_QT=OFF \
--D WITH_GTK=OFF \
--D BUILD_JAVA=OFF \
--D WITH_1394=OFF \
--D CMAKE_INSTALL_PREFIX=/workspace/compile/__install/opencv490-gst ..
-*/

+ 3 - 3
workspace/demo.json

@@ -53,10 +53,10 @@
                     "params": {}
                 },
                 {
-                    "node_id": "rtmp_0",
-                    "node_type": "Rtmp",
+                    "node_id": "rtsp_0",
+                    "node_type": "Recorder",
                     "params": {
-                        "gst_pipeline": "appsrc ! queue leaky=downstream max-size-time=200000000 ! videoconvert n-threads=2 ! vaapih264enc bitrate=2000 key-int-max=30 rate-control=cbr tune=low-power ! h264parse ! flvmux streamable=true ! queue max-size-bytes=1048576 ! rtmpsink location=rtmp://172.16.20.168:1935/live/123456 latency=0 retry=1 qos=true",
+                        "gst_pipeline": "appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast bitrate=2000 key-int-max=50 ! video/x-h264,profile=baseline ! rtspclientsink location=rtsp://172.16.20.168:8554/live",
                         "fps": 25
                     }
                 }