admin
2025-04-25 c3c0d2742db73d8a91cdc28218a58e4863086095
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);