较小的mp4文件持续时间

时间:2018-11-12 19:16:33

标签: opencv

我正在以60 FPS的速度创建一个mp4文件,该测量为我提供了可变FPS的帧。为此,我添加了相同的帧,直到时间戳记变为新帧为止。甚至帧数* FPS也应该给我指定的持续时间,最终文件的持续时间较短。例如,从8分钟的持续时间开始,最终文件只有5分钟。我将opencv 3.4.3与H264编解码器一起使用。为什么会这样呢?

这是功能:

   void ExporterChannel::ProcessMFCImage(Timestamp _timestamp, const std::string& _filename, const std::string& _data)
{
  static bool first = true;
  static long long accumulated_time_error = 0;
  static long long first_timestamp;

  static structs::SensorNearData::MFC::CameraImage mfc_image_struct;
  static pb::SensorNearData::MFC::CameraImage  mfc_image_pb;

  if (first)
  {
    first = false;
    mfc_image_pb.ParseFromString(_data);
    pb2structs::convert(mfc_image_pb, mfc_image_struct);
    first_timestamp = _timestamp;
    Size frameSize(mfc_image_struct.image_width, mfc_image_struct.image_height);
    bool color_mode_rgb = (config_.color == "true");
    if (color_mode_rgb == true)
    {
      video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, true);
    }
    else
    {
      video_file.open(_filename, CV_FOURCC('H', '2', '6', '4'), FPS, frameSize, false);
    }
    // check if we succeeded
    if (!video_file.isOpened())
    {
      ExporterException("Could not open the output video file for write\n");
      return;
    }
    HandleMFCImage(mfc_image_struct);
  }
  else
  {
    if ((long long)_timestamp < (first_timestamp + STEP))
    {
      accumulated_time_error += first_timestamp + STEP - (long long)_timestamp;
    }
    else
    {
      while ((long long)_timestamp >= (first_timestamp + 2 * STEP))
      {
        HandleMFCImage(mfc_image_struct);
        first_timestamp += STEP;
      }
      accumulated_time_error += (long long)_timestamp - (first_timestamp + STEP);
      if (accumulated_time_error >= STEP)
      {
        HandleMFCImage(mfc_image_struct);
        accumulated_time_error -= STEP;
      }
    }
    mfc_image_pb.ParseFromString(_data);
    pb2structs::convert(mfc_image_pb, mfc_image_struct);
    first_timestamp = (long long)_timestamp;
    HandleMFCImage(mfc_image_struct);
  }
}

0 个答案:

没有答案