Jump to content

Extract frame from video (VB.NET)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
Hello everyone!
I want to extract some frames from a video file and save them in a variable so I can then use them in my project as still images. I have been looking for some way to do that but i did not find anything at all ... Is there any way of doing that? (I use VB.NET)
Thanks!

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I don't know about programming one, but you can do this with the normal Windows functions. Just open up the video file in Windows Movie Maker, move the marker to the place in the video you want, then click the little camera icon in the preview box. This will prompt you to save the image.
Otherwise, just load it up in Windows Media Player (WMP) and take a screenshot of it. In some cases the video will not be captured in the screenshot, in which case you need to switch Hardware Acceleration on/off (you can do this inside the Options menus).
If you use Winamp, you can slow the video dow to see the individual frames, for greater control. Once you have saved them as images, you can load them like this:

Dim bmp As Bitmap = Image.FromFile("C:/thepicture.jpg")

If you want to show them, you can load them into a picture box:

PictureBox1.Image = bmp

Or, you can draw them straight to the screen with Me.CreateGraphics().DrawImage().

Xav
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
Thank you but that's not what I meant. The frames must not be saved in the HDD but just loaded in the ram and all this has to be done withe my application. Anyway, thank you.

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You could always use your program to control the other software. Anyway, by now you probably have worked it out already.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
Yes i did but this wont really help me because i don't want to store the frames in the HDD but just put them in the memory for future use. And there should be some way of taking it from the memory of the "controlled" program but i think it would take me much time to find out some way of doing this. But ... if you have something in mind that would help me i would appreciate it if you tel me!
Thanks really!

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
In memory for future use? The whole point of memory is that it stores things temporarily. Once the program is shut down, it loses its objects (and hence memory allocation slots).
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
What I mean by Future use: After extracting about 50 frames i want to get some pixel information and then delete them from the memory ... I don't mean to use them after some weeks. So what i want is just compare a few frames and see if there is any movement ... maybe I wasn't clear enough at the beginning ... Sorry.

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Oh - well, if you use System.Graphics and save the images as a bitmap, you could always extract the pixels using GetPixel() and SetPixel().
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
So that means that I have to display it on a control to get the pixels ... I could try it! Otherwise ill make my own decoder! :)

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Actually, you don't even need to do that! All you need is to store the current frame as some sort of image, like a Bitmap or Image file. Then, you use this code:

Quote

Dim g As System.Graphics = Graphics.FromImage(myBitmap)

Replace 'myBitmap' with your image. Then, just use g.GetPixel() to get the pixel. I think you have to pass in two parameters when you call the method - the x and y co-ordinates of the pixel. Remember that pixels start in the top-left corner of the image, and progress to the right and downwards.

You might use a loop to put each frame in a slot of a Bitmap() array, then just access them from there.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#11
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
But can this be done for mpg files?

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I'm not sure how to extract the frames from the video file, but once you've done that, you can just load them into Bitmap or Image objects.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums