locked
Video playback frame rate and performance RRS feed

  • Question

  • I am hoping to use WPF for an interactive application that plays video in realtime with 3D graphics drawn on top. Think of it like a simple video player with one video layer and one 3D graphics layer. Any pointers on relevant WPF topics would be great, or opinions on whether WPF is the right technology to choose.

    (Last time I did this by using DirectShow for video, writing a custom allocator-presenter for the VMR9, and then calling native DirectX routines to draw graphics onto the decoded video frames. It was OK, but a bit messy.)

    In the mean time, I have written a simple C# app which plays back video in a window. For my first test, I used a Type I DV AVI file (PAL), which is 720x576 at 25 fps. Unfortunately, the observed frame rate was about 5fps and CPU usage was almost 100%. MediaPlayer can play the file at 25fps with less than 20% CPU.

    For a WMV file, the performance seems a little better, but I'm not convinced that I'm seeing the video play at the correct frame rate.

    Is there something I need to do in order to observe better video playback quality and performance? Thanks.

    using System;
    using System.Windows;
    using System.Windows.Media;
    namespace Test.VideoRender
    {
    class VideoElement : FrameworkElement
    {
    public VideoElement()
    {
    mp =
    new MediaPlayer();
    mp.Open(
    new Uri("file://C:\\DVAVI.avi"));
    mp.Play();
    }
    protected override void OnRender(DrawingContext dc)
    {
    dc.DrawVideo(mp,
    new Rect(0, 0, 768, 576));
    dc.DrawRectangle(
    Brushes.Transparent, new Pen(Brushes.Red, 1.0), new Rect(10, 10, 100, 100));
    }
    private MediaPlayer mp;
    }
    class VideoWindow : Window
    {
    [
    STAThread]
    public static void Main()
    {
    new Application().Run(new VideoWindow());
    }
    public VideoWindow()
    {
    Content =
    new VideoElement();
    Width = 800;
    Height = 600;
    }
    }

    }

    Tuesday, October 3, 2006 11:31 AM

Answers

All replies