小编sup*_*are的帖子

在WPF中呈现非托管视频帧的最佳性能是什么?

我正在使用FFmpeg库以最小的延迟(MediaElement无法处理的东西)通过UDP接收和解码H.264/MPEG-TS .

在专用的FFmpeg线程上,我正在拉PixelFormats.Bgr32视频帧进行显示.我已经尝试过InteropBitmap:

_section = CreateFileMapping(INVALID_HANDLE_VALUE, IntPtr.Zero, PAGE_READWRITE, 0, size, null);
_buffer = MapViewOfFile(_section, FILE_MAP_ALL_ACCESS, 0, 0, size);
Dispatcher.Invoke((Action)delegate()
{
    _interopBitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(_section, width, height, PixelFormats.Bgr32, (int)size / height, 0);
    this.Source = _interopBitmap;
});
Run Code Online (Sandbox Code Playgroud)

然后每帧更新:

Dispatcher.Invoke((Action)delegate()
{
    _interopBitmap.Invalidate();
});
Run Code Online (Sandbox Code Playgroud)

但性能非常差(跳帧,高CPU使用率等).

我也试过WriteableBitmap:FFmpeg将帧放在_writeableBitmap.BackBuffer和每帧更新:

Dispatcher.Invoke((Action)delegate()
{
    _writeableBitmap.Lock();
});
try
{
    ret = FFmpegInvoke.sws_scale(...);
}
finally
{
    Dispatcher.Invoke((Action)delegate()
    {
        _writeableBitmap.AddDirtyRect(_rect);
        _writeableBitmap.Unlock();
    });
}
Run Code Online (Sandbox Code Playgroud)

遇到几乎相同的性能问题(使用各种DispatcherPriority测试).

任何帮助将不胜感激.

wpf video performance ffmpeg unmanaged-memory

7
推荐指数
1
解决办法
742
查看次数

标签 统计

ffmpeg ×1

performance ×1

unmanaged-memory ×1

video ×1

wpf ×1