This commit is contained in:
parent
bc46d869a0
commit
b36c183e2d
|
@ -16,12 +16,12 @@
|
|||
<PackageReference Include="CommonServiceLocator" Version="2.0.5" />
|
||||
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.1.20201226" />
|
||||
<PackageReference Include="OpenCvSharp4.WpfExtensions" Version="4.5.1.20201226" />
|
||||
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.1.20201229" />
|
||||
<PackageReference Include="OpenCvSharp4.WpfExtensions" Version="4.5.1.20201229" />
|
||||
<PackageReference Include="zlib.net" Version="1.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' != 'net45'">
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Views\Window2.xaml.cs">
|
||||
|
@ -52,7 +52,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
|
||||
<PackageReference Include="OpenCvSharp4">
|
||||
<Version>4.5.1.20201226</Version>
|
||||
<Version>4.5.1.20201229</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
|
|
@ -272,10 +272,10 @@ namespace JianGongYun.TRTC
|
|||
public static void VedioRecordTask(TXLiteAVVideoView view, TRTCVideoStreamType streamType)
|
||||
{
|
||||
var end = false;
|
||||
ConcurrentQueue<Bitmap> bitmaps = new ConcurrentQueue<Bitmap>();
|
||||
ConcurrentQueue<Mat> bitmaps = new ConcurrentQueue<Mat>();
|
||||
view.OnRenderVideoFrameHandler += (b) =>
|
||||
{
|
||||
bitmaps.Enqueue(b.ToBitmap());
|
||||
bitmaps.Enqueue(b.ToMat());
|
||||
};
|
||||
view.OnViewRemove += () =>
|
||||
{
|
||||
|
@ -288,7 +288,6 @@ namespace JianGongYun.TRTC
|
|||
var imgTemp = Path.Combine(_recoderDir, $"{streamType}.png");
|
||||
var videoFile = Path.Combine(_recoderDir, $"{Util.TimeStr()}_{streamType}.avi");
|
||||
VideoWriter vw = new VideoWriter();
|
||||
Mat mat = default;
|
||||
bool videoWriterInit = false;
|
||||
while (!end || bitmaps.Count > 0)
|
||||
{
|
||||
|
@ -297,26 +296,26 @@ namespace JianGongYun.TRTC
|
|||
Thread.Sleep(100);
|
||||
continue;
|
||||
}
|
||||
if (bitmaps.TryDequeue(out var bitmap))
|
||||
if (bitmaps.TryDequeue(out var mat))
|
||||
{
|
||||
bitmap.Save(imgTemp, System.Drawing.Imaging.ImageFormat.Png);
|
||||
bitmap.Dispose();
|
||||
mat = Cv2.ImRead(imgTemp, ImreadModes.AnyColor);
|
||||
Cv2.ImShow(streamType.ToString(), mat);
|
||||
Cv2.WaitKey(1);
|
||||
//mat.SaveImage(imgTemp);
|
||||
//mat.Dispose();
|
||||
//mat = Cv2.ImRead(imgTemp, ImreadModes.AnyColor);
|
||||
//Cv2.ImShow(streamType.ToString(), mat);
|
||||
//Cv2.WaitKey(1);
|
||||
if (!videoWriterInit)
|
||||
{
|
||||
vw.Open(videoFile, FourCC.H264, settingWindowViewModel.EncParams.videoFps, mat.Size());
|
||||
videoWriterInit = true;
|
||||
}
|
||||
vw.Write(mat);
|
||||
mat.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
mat?.Dispose();
|
||||
vw?.Release();
|
||||
vw?.Dispose();
|
||||
if (File.Exists(imgTemp))
|
||||
|
|
|
@ -17,16 +17,10 @@ namespace JianGongYun.TRTC.Utils
|
|||
/// <returns></returns>
|
||||
public static Mat ToMat(this WriteableBitmap writeableBitmap)
|
||||
{
|
||||
using (MemoryStream outStream = new MemoryStream())
|
||||
using (var bmp = writeableBitmap.ToBitmap())
|
||||
{
|
||||
BitmapEncoder enc = new PngBitmapEncoder();
|
||||
enc.Frames.Add(BitmapFrame.Create(writeableBitmap));
|
||||
enc.Save(outStream);
|
||||
using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(outStream))
|
||||
{
|
||||
var mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bmp);
|
||||
return mat;
|
||||
}
|
||||
var mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bmp);
|
||||
return mat;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -38,11 +32,23 @@ namespace JianGongYun.TRTC.Utils
|
|||
{
|
||||
using (MemoryStream outStream = new MemoryStream())
|
||||
{
|
||||
BitmapEncoder enc = new PngBitmapEncoder();
|
||||
//System.Windows.Media.Imaging.WmpBitmapEncoder
|
||||
BitmapEncoder enc = new BmpBitmapEncoder();
|
||||
enc.Frames.Add(BitmapFrame.Create(writeableBitmap));
|
||||
enc.Save(outStream);
|
||||
return new System.Drawing.Bitmap(outStream);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToFile(this WriteableBitmap writeableBitmap, string fileName)
|
||||
{
|
||||
using (var file = File.Create(fileName))
|
||||
{
|
||||
BitmapEncoder enc = new BmpBitmapEncoder();
|
||||
enc.Frames.Add(BitmapFrame.Create(writeableBitmap));
|
||||
enc.Save(file);
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue