2

I have 400 sequence images. I want to create from them video file ( clip .. mpeg )

I download the 'AForge.NET' and i try to look into it to see if it possible - but i don't fine any way to do it.

How can i do it ?

Yanshof
  • 8,974
  • 14
  • 81
  • 168
  • [Which "the AForge.Net"](https://www.nuget.org/packages?q=AForge.NET)? Did you have a look at [the documentation and/or samples](http://www.aforgenet.com/framework/)? – RobIII Apr 20 '16 at 12:51
  • @Roblll => yes .. i look at the documentation. – Yanshof Apr 20 '16 at 12:52
  • 1
    ...and? Did you look at it like you look at the back of the book in the bookstore? Or did you actually *read* it and try to *comprehend* it? If so: What was not clear? With what do you need help exactly? Can you ask a *specific* question / show code you already tried? Also: have a look at [this](http://stackoverflow.com/questions/9744026/image-sequence-to-video-stream). – RobIII Apr 20 '16 at 12:54
  • 2
    Have you checked [this](http://stackoverflow.com/questions/9744026/image-sequence-to-video-stream) or [this](http://stackoverflow.com/questions/10527914/generating-video-from-a-sequence-of-images-in-c-sharp)? You could try them instead of AForge. – Leonardo Alves Machado Apr 20 '16 at 12:55
  • 2
    You could still just use [ffmpeg](http://stackoverflow.com/a/24966617/1961059) for this. – rinukkusu Apr 20 '16 at 12:56

1 Answers1

8

Look up the documentation, find the VideoFileWriter Class, look at it's members, see the WriteVideoFrame method(s), read the line: "Write new video frame into currently opened video file.". Bingo. Half way there.

If you can't connect the dots when reading the methods' signature (WriteVideoFrame(Bitmap)) or don't understand how to use the Open() overloads or Close() method (why wouldn't you, the last two are pretty common for File I/O) you can always Google "VideoFileWriter WriteVideoFrame example", find code, go from there. The meat of the function there is:

VideoFileWriter writer = new VideoFileWriter();
writer.Open("myfile.avi", width, height, 25, VideoCodec.MPEG4, 1000000);
    // ... here you'll need to load your bitmaps
    writer.WriteVideoFrame(image);
}
writer.Close();

So something like this should probably work:

using (VideoFileWriter writer = new VideoFileWriter()) 
{
    writer.Open(@"d:\myfile.avi", 640, 480, 25, VideoCodec.MPEG4);
    foreach (var file in Directory.GetFiles(@"d:\foo\bar", "*.jpg"))
    {
        writer.WriteVideoFrame(Bitmap.FromFile(file) as Bitmap);
    }
    writer.Close();
}

Which, with a few minutes of fiddling around, gave me something like this:

var size = new Size(1600, 1200);                    // The desired size of the video
var fps = 25;                                       // The desired frames-per-second
var codec = VideoCodec.MPEG4;                       // Which codec to use
var destinationfile = @"d:\myfile.avi";             // Output file
var srcdirectory = @"d:\foo\bar";                   // Directory to scan for images
var pattern = "*.jpg";                              // Files to look for in srcdirectory
var searchoption = SearchOption.TopDirectoryOnly;   // Search Top Directory Only or all subdirectories (recursively)?

using (var writer = new VideoFileWriter())          // Initialize a VideoFileWriter
{
    writer.Open(destinationfile, size.Width, size.Height, fps, codec);              // Start output of video
    foreach (var file in Directory.GetFiles(srcdirectory, pattern, searchoption))   // Iterate files
    {
        using (var original = (Bitmap)Image.FromFile(file))     // Read bitmap
        using (var resized = new Bitmap(original, size))        // Resize if necessary
            writer.WriteVideoFrame(resized);                    // Write frame
    }
    writer.Close();                                 // Close VideoFileWriter
}                                                   // Dispose VideoFileWriter

This resizes images; should not all images in the sequence be the same. If they are you can skip that step simply by changing

using (var original = (Bitmap)Image.FromFile(file))     // Read bitmap
using (var resized = new Bitmap(original, size))        // Resize if necessary
    writer.WriteVideoFrame(resized);                    // Write frame

to:

using (var mybitmap = (Bitmap)Image.FromFile(file))     // Read bitmap
    writer.WriteVideoFrame(mybitmap);                   // Write frame

Also make sure you add the correct using statements; you will, at a minimum, need the following for above examples:

using AForge.Video.FFMPEG;
using System.Drawing;
using System.IO;

Also you'll need to reference the DLL's as described here:

... you should have created a project, added a reference to the AForge.Video.FFMPEG library, set the target platform to x86 and the target framework version to 3.5 or lower now. If so, it can go on.

... we need a few more dlls from the AForge archive. You can find these in the folder “Externals\ffmpeg” inside the AForge archive. All files in this folder have to be copied to the output folder of your Visual Studio project. (After we changed the target architecture this now should be “YourProjectFolder\bin\x86\Debug”.)

If it still doesn't work then tell us what happens, exact error messages etc.

Community
  • 1
  • 1
RobIII
  • 7,384
  • 1
  • 33
  • 79