2

I am trying to play a stream of bitmap images using openCVSharp to generate the Bitmaps from YUV. But I am unable to display it as a video.

I found some links regarding using it as an AVI wrapper here and some more to save on the hard disk like here and FFMPEG might work great on LINUX, but it is not so good in Windows.

I even tried with by using the following code. But it just displays the last frame in the sequence, and I do not have a URI for using MediaElement as the bitmaps are generated by my program.

image.source = ToBitmapSource(bitmapImage);

where

public static BitmapSource ToBitmapSource(System.Drawing.Bitmap bitmap){
    IntPtr ip = bitmap.GetHbitmap();
    BitmapSource bs = null;

    bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip,
    IntPtr.Zero, System.Windows.Int32Rect.Empty,
    System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

    return bs;
}

I am trying to play the video (similar to streaming) without saving it on the computer. Is direct show a must for this? I desperately need your help, my deadline is fast approaching!

Community
  • 1
  • 1
Yashodhar.Rao
  • 107
  • 3
  • 11
  • Why, can't you simply display them on the screen using XNA or SlimDX? – Ani Jul 13 '12 at 18:55
  • I have never worked with any of them, do you have any links regarding the same? – Yashodhar.Rao Jul 13 '12 at 19:00
  • I was able to find that SlimDX and XNA are high end graphics tools used for gaming, I do not need such high processing, just want to be able to display bitmaps as a video that is all – Yashodhar.Rao Jul 13 '12 at 19:02
  • What is the rate at which you generate these frames? – Ani Jul 13 '12 at 19:03
  • Well then - if your UI can render it already, then what do you want to do (why convert it to a video)? It is already being displayed, correct? – Ani Jul 13 '12 at 19:07
  • using the System.Windows.Controls.Image, I was able to just display a single frame - namely the last frame, but was never able to show it up as a video, tried providing delay between this, but in vain. – Yashodhar.Rao Jul 13 '12 at 19:09
  • Could this (http://stackoverflow.com/questions/806083/wpf-render-performance-with-bitmapsource) be the solution to your problem? – Ani Jul 13 '12 at 19:17

1 Answers1

-1

You can use a DispatcherTimer (equivalent to a Timer in Winform):

DispatcherTimer dt = new DispatcherTimer();
dt.Interval = 25;  //25 ms --> 50 frames per second
dt.Tick += delegate(object sender, EventArgs e){

             //get the image and display it

          }

dt.Start(); //to start record
Omar
  • 16,329
  • 10
  • 48
  • 66
  • I have not worked with delegate much, So, here is the error that I got for dt.Tick = delegate(object sender, EventArgs e) --- Tick can only be applied on left hand side of += or -=. I didn't get what it means – Yashodhar.Rao Jul 14 '12 at 04:48
  • well, I modified this a little based on [this](http://stackoverflow.com/questions/9977393/how-do-i-pass-an-object-into-a-timer-event/) and used it .. but it makes no difference, still no video dt.Interval = new TimeSpan(0, 0, 0, 0, 40); //25 ms --> 50 frames per second dt.Tick += (sender, e) => UpdateFrame(sender, e, BitImage); private void UpdateFrame(object sender, EventArgs e, Bitmap BitImage) { Image.Source = ConvertYUV.ToBitmapSource(BitImage); } – Yashodhar.Rao Jul 14 '12 at 07:54