admin
2025-04-25 c3c0d2742db73d8a91cdc28218a58e4863086095
rtmp推理处理
4个文件已修改
109 ■■■■ 已修改文件
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vscode/settings.json 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
PreProcessFn.cpp 101 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
build/config.json 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.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
.vscode/settings.json
@@ -80,6 +80,7 @@
        "__tree": "cpp",
        "queue": "cpp",
        "stack": "cpp",
        "filesystem": "cpp"
        "filesystem": "cpp",
        "*.tcc": "cpp"
    }
}
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;
            }
            // 将帧写入到FFmpeg管道中
            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;
            // 将帧写入到FFmpeg管道中
            fwrite(frame.data, 1, frame.total() * frame.elemSize(), pipe);
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": [
            {