views:

713

answers:

9

What is the easiest-to-code-in technology that would give me real time access to a video's frames, and allow me to modify them. I am aware of DirectShow, but it's programming model seems to be quite complicated. Is there a framework that makes programming such a frame filter easier?

A: 

There was a class called AviFile in a few C++ packages from MS a while back. I'm not sure what happenend to that.

The best way to go about this problem is to use DirectShow if you are sticking with windows.

The AVI File format (which is well documentent and you can find under google) is a bit similar to:

AVIRIFF  size speed imgWidth imgHeight frameTotal imgCodec audioCodec frame size 
  FRAME
  SOUND
  FRAME 
  SOUND
monksy
+4  A: 

You can take a look at ffmpeg command and open-source project, which uses libavcodec library.

mouviciel
+1  A: 

Hy Opencv is what you need. Its a Framework which can you can manipulate image,video and alot more thing check out http://opencv.willowgarage.com/wiki/

streetparade
A: 

Consider creating a VLC plug-in

Runs on Linux and Windows, supports real-time live video, streaming from file, loads of codecs etc.

Stuart
A: 

the simplest solution is using the AVIFile API. the are many samples available.

geva30
A: 

You can use FFMpeg.

Check the FFmpeg documentation

Himadri
+3  A: 

Give me real time access to a video's frames, and allow me to modify them

Are you looking to get the uncompressed video frames and modify them before they are rendered? Or do you want to modify the video frames, saving them back to a media file?

The first one would be slightly easier. Even though DirectShow may seem complicated at first, it really is an elegant framework. I would strong suggest looking at the DirectShow.NET samples. To get access to the frames of the video, you'd simply configure and add a SampleGrabber filter to the DirectShow graph, do a graph.RenderFile(mymediafile, null), and you will receive a callback for each frame. You can modify the pixel data and it will appear on the rendered video. This should not take more than 1 page of code. I have an example source code on using SampleGrabber, but it's made for web cameras. Playing media is much easier (graph.RenderFile!).

If you need to write this stuff to a file, you'd do something similar to what is described above, but instead of using a video renderer, you'd have to configure the graph to use video encoders and muxers. Probably not fun for someone new to DirectShow ;).

If you just wish to get frames there is a VERY simple interface in directshow called IMediaDet. I have written a simple class to easily extract out any frames from a media file. It's geared towards WPF, but you can gut it to work with straight GDI.

Jeremiah Morrill
I want to get the frames, modify them, and then render them to screen. Concerning your WPF implementation, is there any performance hit I should worry about?
luvieere
My MediaDetector class is really only good for extracting out thumbnails from media. For video playback it is not recommended.The SampleGrabber webcam example I have is very performant. You get a callback exposing the actual framebuffer that will be sent to the renderer.Would the use of WPF allow you to not have to use DShow at all? WPF you can easily composite things over video using MediaElement.
Jeremiah Morrill
+2  A: 

I have no idea what exactly you are trying to achieve so this may not help you, but if you just need to alter the frames of a video on the fly, I would highly recommend looking into AviSynth. It is a video frameserver that uses a scripting language to alter video. There is also an SDK for it that you can use to write binary plugins. There are a lot of plugins already available to accomplish various tasks. An example script would look like this:

AviSource("C:\video.avi")
Crop(20,0,-20,0) //Crops 20px from the left and right of video 
BicubicResize(640,480) //Resize to 640x480 using bicubic filter
# increase the gamma
Levels(0, 1.2, 255, 0, 255)

These scripts could then be opened in a media player or encoder such as Virtualdub.

Eric
+2  A: 

OK, since you asked for "easy", I have to mention HTML5 <video>. See the demo and explanation at these links:

Nickolay
Wow... that's some neat stuff, thank you
luvieere