Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi,
I need to save an incoming image stream into a video. Currently I am displaying a series of incoming images on an image element. This is what I have:
C#
private void Received(ReceivedEventArgs e)
        {
           using (MemoryStream stream = new MemoryStream(
                        e.ReceivedBytes, e.StartIndex, e.BytesTransferred))
                    {
                            JpegBitmapDecoder decoder = new JpegBitmapDecoder(stream,
                                BitmapCreateOptions.PreservePixelFormat,           BitmapCacheOption.OnLoad);
                            Videoframe = decoder.Frames[0];
                         //anyway that I can save it to a video on local disk directly??
                    }
       }

What I want is to know is that if it is possible to save the image stream to the hard disk as a video? If so, how would I go about it? I have googled much but all of them talk about converting series of pre-stored image sequence to video using ffmpeg or such; none I found helpful. Any pointer/code snippet would be much appreciated since I am not an expert in programming.
Thank you!
Posted

 
Share this answer
 
Comments
narayaru 5-Apr-13 1:34am    
Thanks Ibrahim! I saw that link before. As I mentioned, this is about taking images from a pre-stored location and creating a video out of it. The challenge I am facing right now is to convert a continuously incoming stream of images from a network into a video. Any idea on how can i achieve that?
Hi,
I manged to solve it. Here's the code:
C#
private Bitmap bmp;
private AviManager aviManager;
private VideoStream avistream;
private bool videocaptureactivated = false;
private Bitmap bitmap;

private void Savevideo()
{
   string strpath = Environment.GetFolderPath (System.Environment.SpecialFolder.DesktopDirectory);
   string filename = string.Format("Video Capture.avi");
   string path = System.IO.Path.Combine(strpath, filename);
   aviManager = new AviManager(path, false); 
   bmp = (Bitmap)System.Drawing.Image.FromFile(@"C:\samplescreen.bmp");
   avistream = aviManager.AddVideoStream(false, framerate, bmp);
   videocaptureactivated = true;
}

private void Received(ReceivedEventArgs e)
{
   using (MemoryStream stream = new MemoryStream(
                        e.ReceivedBytes, e.StartIndex, e.BytesTransferred))
          {
            if (videocaptureactivated)
               {
                  bitmap = (Bitmap)Bitmap.FromStream(stream);
                  avistream.AddFrame(bitmap);
               }
          }
}

private void stopsave()
{
   videocaptureactivated = false;
   bitmap.Dispose();
   aviManager.Close();
}


Since the video is compiled bmp' and uncompressed, the size is huge. Next step for me is to do the compressd writing.

Thanks for the suggestion Ibrahim!
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900