Wednesday, April 28, 2010

One of the most exciting tasks this week to convert and render images frame from avi video file, i start searching for the solution or for library helping me to enhance the task time , Mohamed Zaki advice me to search into  DirectShow and sending me this , after a bit of sec i found Splicer its a little video and audio composition library that leverages DirectShow.

so how to use Splicer to achieve this task :

1- Add the library ref.


Download it form my SkyDrive

2- Add these lines of code to your console app.

static void Main(string[] args)

           using (DefaultTimeline timeline = new DefaultTimeline())
                timeline.AddVideoGroup(16, 664, 246).AddTrack(); // we want 320x240 24bpp sized images
               timeline.AddVideo("Test.avi"); // 8 second video clip
               List<double>thresholds = new List<double>() ;
               for (double i = 0; i < 5000; i++)
               ImagesToDiskParticipant participant = new ImagesToDiskParticipant(16, 664, 246, Environment.CurrentDirectory, thresholds.ToArray());
               using (NullRenderer render = new NullRenderer(timeline, null, new ICallbackParticipant[] { participant }))

Here we add a video group (we don’t need any audio, we’re not capturing sound samples) and then create an ImageToDiskParticipant (this is just an example class, you would probably want to implement your own derived from the AbstractProgressParticipant class).  In this case the format for the video group will be what you end up with, our ImagesToDiskParticipant implements a simple queue where it picks out the nearest frame to the specified times.. so in this case transitions.wmv is an 8 second video clip, and we will take frame "snapshots" at 0,1,2,3,…….. and 4999 seconds aproximately. 
To make use of our participant we use one of the overloads of NullRenderer, and supply it a single-element array containing the image to disk participant.
The end result is 4999 jpeg images on disk (frame0.jpg -> frame4999.jpg)


thx and hope this post be useful for you :)

clip_image002 clip_image004 clip_image006clip_image008 clip_image010