基本信息
源码名称:WPF播放实时视频流
源码大小:22.76M
文件格式:.rar
开发语言:C#
更新时间:2019-08-03
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
本系统是用C#.net开发的,提供了一个类库,Render.Core作用是将视频流转化成一帧一帧的图片,然后显示。下载了就可以运行,对实时视频或者和摄像头连用的程序挺好。
本系统是用C#.net开发的,提供了一个类库,Render.Core作用是将视频流转化成一帧一帧的图片,然后显示。下载了就可以运行,对实时视频或者和摄像头连用的程序挺好。
需要安装 DirectX 后 运行。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;
using Renderer.Core;
using System.Runtime.InteropServices;
namespace SampleApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
FrameData yuvData;
Timer timer;
WriteableBitmapSource wbSource;
D3DImageSource d3dSource;
int frameIndex;
public MainWindow()
{
InitializeComponent();
this.timer = new Timer();
this.timer.Interval = 40;
this.timer.Elapsed = new ElapsedEventHandler(timer_Elapsed);
this.d3dSource = new D3DImageSource();
this.wbSource = new WriteableBitmapSource();
this.frameIndex = 0;
try
{
this.yuvData = FrameData.LoadData("yv12.dat");
if (this.wbSource.SetupSurface(this.yuvData.FrameWidth, this.yuvData.FrameHeight, FrameFormat.YV12))
{
this.imageWB.Source = this.wbSource.ImageSource;
}
else
{
MessageBox.Show("WriteableBitmapSource不支持该种帧格式:" FrameFormat.YV12);
}
if (this.d3dSource.SetupSurface(this.yuvData.FrameWidth, this.yuvData.FrameHeight, FrameFormat.YV12))
{
this.imageD3D.Source = this.d3dSource.ImageSource;
}
else
{
MessageBox.Show("本机显卡不支持该种帧格式:" FrameFormat.YV12);
}
}
catch
{
MessageBox.Show("加载数据文件失败");
}
}
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (this.yuvData != null)
{
if (this.frameIndex >= this.yuvData.Frames)
{
this.frameIndex %= this.yuvData.Frames;
}
try
{
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(this.yuvData.FrameBuffer, this.frameIndex * this.yuvData.FrameSize);
this.wbSource.Render(ptr);
this.d3dSource.Render(ptr);
}
catch
{
}
this.frameIndex ;
}
}
private void buttonStart_Click(object sender, RoutedEventArgs e)
{
this.timer.Start();
}
private void buttonStop_Click(object sender, RoutedEventArgs e)
{
this.timer.Stop();
}
}
}