From c3c0d2742db73d8a91cdc28218a58e4863086095 Mon Sep 17 00:00:00 2001 From: admin <zzjincn@163.com> Date: 星期五, 25 四月 2025 15:11:20 +0800 Subject: [PATCH] rtmp推理处理 --- build/config.json | 4 +- .gitignore | 1 .vscode/settings.json | 3 + PreProcessFn.cpp | 101 +++++++++++++++++++++++++++++++++++++------------- 4 files changed, 79 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 974020c..8d2876e 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,4 @@ build/CMakeFiles/AIRecognize.dir/compiler_depend.ts build/CMakeFiles/AIRecognize.dir/depend.make build/CMakeFiles/AIRecognize.dir/progress.make +build/CMakeFiles/AIRecognize.dir/compiler_depend.internal diff --git a/.vscode/settings.json b/.vscode/settings.json index df71ee2..0263e13 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -80,6 +80,7 @@ "__tree": "cpp", "queue": "cpp", "stack": "cpp", - "filesystem": "cpp" + "filesystem": "cpp", + "*.tcc": "cpp" } } \ No newline at end of file diff --git a/PreProcessFn.cpp b/PreProcessFn.cpp index 86c2dce..b089513 100644 --- a/PreProcessFn.cpp +++ b/PreProcessFn.cpp @@ -332,6 +332,14 @@ return size * nmemb; } +string join(const vector<string>& sequence, const string& separator) +{ + std::string result; + for (size_t i = 0; i < sequence.size(); ++i) + result += sequence[i] + ((i != sequence.size() - 1) ? separator : ""); + return result; +} + /// @brief 瑙嗛娴佹媺鍙栧鐞� /// @param _rtspUrl 瑙嗛娴佹簮鍦板潃 /// @param queJC 鏈鐞嗙殑瑙嗛娴佸抚闃熷垪 @@ -1867,6 +1875,37 @@ //瀹氫箟鎺ュ彈甯� Mat frame; + vector<string> arguments = { + "ffmpeg " + "-hwaccel","cuvid", + "-hwaccel_output_format","cuda", + "-y", "-an", + "-f", "rawvideo", + "-vcodec", "rawvideo", + "-pix_fmt", "bgr24", + "-s", "640x480", + "-r", "15", + "-i", "-", + "-pix_fmt", "yuv420p", + "-f", "flv", + "-max_delay", "1000", + "-flvflags", "no_duration_filesize", + "-c:v","h264_nvenc", + "-b:v", "3M", + "-g:v", "15", + "-bf", "0", + "-bufsize", "50000000", + "-rtbufsize", "50000000", + "rtmp://192.168.1.8:1935/live/camera1" }; + + string ffmpeg_command = join(arguments, " "); + + // 鎵撳紑FFmpeg杩涚▼ + FILE* pipe = popen(ffmpeg_command.c_str(), "w"); + if (!pipe) { + std::cerr << "鏃犳硶鍚姩FFmpeg" << std::endl; + } + while (!asyncStop) { //std::cout << ipccode + "褰撳墠绾跨▼Rabbitmq鏁版嵁鏁伴噺2222:" << queJC2.size() << std::endl; try @@ -1885,20 +1924,9 @@ queJC2.pop(); if (frame.empty())//甯т负绌猴紝鍒欒垗寮� - continue; + continue; - // FFmpeg鎺ㄦ祦鍛戒护 - std::string ffmpeg_command = - "ffmpeg -y -f rawvideo -pixel_format bgr24 -video_size 640x480 " - "-framerate 30 -i - -c:v libx264 -pix_fmt yuv420p -f rtsp " - "rtsp://192.168.1.188:8554/live/stream"; - - // 鎵撳紑FFmpeg杩涚▼ - FILE* pipe = popen(ffmpeg_command.c_str(), "w"); - if (!pipe) { - std::cerr << "鏃犳硶鍚姩FFmpeg" << std::endl; - } - + // 灏嗗抚鍐欏叆鍒癋Fmpeg绠¢亾涓� fwrite(frame.data, 1, frame.total() * frame.elemSize(), pipe); @@ -1931,6 +1959,37 @@ //瀹氫箟鎺ュ彈甯� Mat frame; + vector<string> arguments = { + "ffmpeg " + "-hwaccel","cuvid", + "-hwaccel_output_format","cuda", + "-y", "-an", + "-f", "rawvideo", + "-vcodec", "rawvideo", + "-pix_fmt", "bgr24", + "-s", "1280x720", + "-r", fps, + "-i", "-", + "-pix_fmt", "yuv420p", + "-f", "flv", + "-max_delay", "1000", + "-flvflags", "no_duration_filesize", + "-c:v","h264_nvenc", + "-b:v", "3M", + "-g:v", "15", + "-bf", "0", + "-bufsize", "50000000", + "-rtbufsize", "50000000", + toRtsp }; + + string ffmpeg_command = join(arguments, " "); + + // 鎵撳紑FFmpeg杩涚▼ + FILE* pipe = popen(ffmpeg_command.c_str(), "w"); + if (!pipe) { + std::cerr << "鏃犳硶鍚姩FFmpeg" << std::endl; + } + while (!asyncStop) { //std::cout << ipccode + "褰撳墠绾跨▼Rabbitmq鏁版嵁鏁伴噺2222:" << queJC2.size() << std::endl; try @@ -1949,20 +2008,8 @@ queJC2.pop(); if (frame.empty())//甯т负绌猴紝鍒欒垗寮� - continue; - - // FFmpeg鎺ㄦ祦鍛戒护 - std::string ffmpeg_command = - "ffmpeg -y -f rawvideo -pixel_format bgr24 -video_size 640x480 " - "-framerate 30 -i - -c:v libx264 -pix_fmt yuv420p -f rtsp " - "rtsp://192.168.1.8:8554/live/stream"; - - // 鎵撳紑FFmpeg杩涚▼ - FILE* pipe = popen(ffmpeg_command.c_str(), "w"); - if (!pipe) { - std::cerr << "鏃犳硶鍚姩FFmpeg" << std::endl; - } - + continue; + // 灏嗗抚鍐欏叆鍒癋Fmpeg绠¢亾涓� fwrite(frame.data, 1, frame.total() * frame.elemSize(), pipe); diff --git a/build/config.json b/build/config.json index d538ed1..fa651fc 100644 --- a/build/config.json +++ b/build/config.json @@ -35,9 +35,9 @@ "name": "鎽勫儚鏈�1", "video": "rtsp://admin:zkwl13579@192.168.1.162:554/h264/ch1/main/av_stream", "skipN":1, - "push_type": "rabbitmq", + "push_type": "stream", "fps": 15, - "toRtmp": "rtsp://192.168.1.8:8554/live/camera1", + "toRtmp": "rtmp://192.168.1.8:1935/live/camera1", "interval": "20", "model": [ { -- Gitblit v1.8.0