自学内容网 自学内容网

C#+EmguCV合并视频文件

        EmguCV是opencv的C#库,该库可以用来处理图像,还可以处理视频。以下是视频合并的方法,不过效率比较低。

/// <summary>
  /// 合并多个视频为新的视频()
  /// </summary>
  /// <param name="videoFiles"></param>
  /// <param name="newPath"></param>
  public bool MergeVideos(string[] videoFiles, string newPath)
  {
      try
      {
          VideoCapture vc = new VideoCapture(videoFiles[0]);
          int fps = (int)vc.GetCaptureProperty(CapProp.Fps);
          int width = (int)vc.GetCaptureProperty(CapProp.FrameWidth);//长
          int height = (int)vc.GetCaptureProperty(CapProp.FrameHeight);//宽
          int totalFrameCount = (int)vc.GetCaptureProperty(CapProp.FrameCount);//总帧数
          int fourcc = VideoWriter.Fourcc('M','J','P','G');
          VideoWriter videoWriter = new VideoWriter(newPath, fourcc, fps, new Size(width, height),true);
          int n = 0;
          foreach (string file in videoFiles)
          {
              if (n >= 1)
              {
                  vc.Dispose();
                  vc = new VideoCapture(file);
              }
              if (vc.IsOpened)
              {
                  int i = 0;
                  while (i < totalFrameCount)
                  {
                      i++;
                      Mat mat = new Mat();
                      vc.Read(mat);
                      if (mat != null)
                          videoWriter.Write(mat);
                  }
              }
              n++;
          }
          videoWriter.Dispose();
      }
      catch (Exception ex)
      {
          return false;
      }
      return true;
  }


原文地址:https://blog.csdn.net/whf227/article/details/142246742

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!