user1245145
user1245145

Reputation: 43

create video from streamed images c#

How can I build video from stream image (only image without sound) in C#?

Here is some code of my application:

static int ii = 1;
public void drawBitmap(byte[] data)
{
    MemoryStream ms = new MemoryStream(data);
    try
    {
        Bitmap b = new Bitmap(ms);
        b.Save(@"c:\test\" + (ii++) + ".jpg");
        Image i = (Image)b;
        pictureBox1.Image = i;
        ii++;
    }
    catch (Exception e)
    {
    }
}

Upvotes: 4

Views: 17307

Answers (2)

Johan Asp
Johan Asp

Reputation: 51

I used the wrapper mentioned above, like this:

private static void hejHopp()
{
    //http://www.codeproject.com/Articles/7388/A-Simple-C-Wrapper-for-the-AviFile-Library

    //myReadyNAS device, got files via FTP from my webcam
    var jpgFileList = Directory.EnumerateFiles(sourcePath,"*.jpg");

    //load the first image
    Bitmap bitmap = (Bitmap)Image.FromFile(jpgFileList.First());

    //create a new AVI file
    AviManager aviManager = new AviManager(sourcePath + "\\tada.avi", false);

    //add a new video stream and one frame to the new file
    //set IsCompressed = false
    VideoStream aviStream =  aviManager.AddVideoStream(false, 2, bitmap);

    jpgFileList.Skip(1).ToList().ForEach(file =>
    {
        bitmap = (Bitmap)Bitmap.FromFile(file);
        aviStream.AddFrame(bitmap);
        bitmap.Dispose();
    });

    aviManager.Close();
}

Upvotes: 5

Richard
Richard

Reputation: 22016

You might want to take a look at this thread:

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/f23caf50-85a9-4074-8328-176c8bcc393e/

Same question. Some answers.

More is also available here:

http://www.codeproject.com/Articles/7388/A-Simple-C-Wrapper-for-the-AviFile-Library

Upvotes: 4

Related Questions