示例#1
0
 /// <summary>
 /// Convert to video frame to <paramref name="dstFormat"/> after Mat.ToImage&lt;Bgr, byte&gt;"
 /// </summary>
 /// <param name="mat"></param>
 /// <param name="dstFormat">video frame format</param>
 /// <returns></returns>
 public static VideoFrame ToVideoFrame(this Mat mat, AVPixelFormat dstFormat = AVPixelFormat.AV_PIX_FMT_BGR24)
 {
     if (dstFormat != AVPixelFormat.AV_PIX_FMT_BGR24)
     {
         using (PixelConverter converter = new PixelConverter(dstFormat, mat.Width, mat.Height))
         {
             return(converter.ConvertFrame(MatToVideoFrame(mat)));
         }
     }
     return(MatToVideoFrame(mat));
 }
示例#2
0
 /// <summary>
 /// convert to <see cref="PixelFormat.Format32bppArgb"/> or <see cref="PixelFormat.Format24bppRgb"/> bitmap
 /// </summary>
 /// <param name="frame"></param>
 /// <returns></returns>
 public static Bitmap ToBitmap(this VideoFrame frame)
 {
     if ((AVPixelFormat)frame.AVFrame.format == AVPixelFormat.AV_PIX_FMT_BGRA || (AVPixelFormat)frame.AVFrame.format == AVPixelFormat.AV_PIX_FMT_BGR24)
     {
         return(BgraToBitmap(frame));
     }
     using (VideoFrame dstFrame = new VideoFrame(frame.AVFrame.width, frame.AVFrame.height, AVPixelFormat.AV_PIX_FMT_BGRA))
         using (PixelConverter converter = new PixelConverter(dstFrame))
         {
             return(BgraToBitmap(converter.ConvertFrame(frame)));
         }
 }
示例#3
0
 private static Mat VideoFrameToMat(VideoFrame frame)
 {
     if ((AVPixelFormat)frame.AVFrame.format != AVPixelFormat.AV_PIX_FMT_BGRA)
     {
         using (VideoFrame dstFrame = new VideoFrame(frame.AVFrame.width, frame.AVFrame.height, AVPixelFormat.AV_PIX_FMT_BGRA))
             using (PixelConverter converter = new PixelConverter(dstFrame))
             {
                 return(BgraToMat(converter.ConvertFrame(frame)));
             }
     }
     return(BgraToMat(frame));
 }