Click here to Skip to main content
16,011,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am converting a set of images into video using C# and i am using encoder for converting the images into video... and i am capturing images from a webcamera.

now capturing is working fine the problem coming is when i click on button for convert and it start executing the code block it comes an error that vshost32.exe has stop working..

my block code for that block is -->

C#
string[] files = { };

foreach (string f in files)
{
     Debug.Print(f);
}
WMEncoder encoder = new WMEncoder();

try
{

    files = System.IO.Directory.GetFiles(@"C:\Users\gaurav.STRINGNET\Desktop\New folder\video capture\video capture\bin\Debug\img\");

}
catch (Exception ex)
{
     MessageBox.Show(ex.Message);
}

foreach (string f in files)
{
      Debug.Print(f);
}

 //profile for each frame
IWMEncProfile2 pro = new WMEncProfile2();

try
{
      pro.LoadFromFile(@"C:\Users\gaurav.STRINGNET\test.prx");
}
catch (Exception ex)
{
     MessageBox.Show(ex.Message, "error1");
}

//build up the collection of frames

IWMEncSourceGroup2 frameSourceGroup;

try
{
      foreach (string filename in files)
      {
           frameSourceGroup = (         IWMEncSourceGroup2)encoder.SourceGroupCollection.Add(filename);
           frameSourceGroup.set_Profile(pro);
           //odd to have to do it this way instead of via property

          IWMEncVideoSource2 sourceVideo = (IWMEncVideoSource2)frameSourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
          sourceVideo.SetInput(filename," ", " ");
      }
}
catch (Exception ex)
{
      MessageBox.Show(ex.Message, "error 2");
}

try
{
encoder.File.LocalFileName=
@"C:\Users\gaurav.STRINGNET\output.wmv";
encoder.PrepareToEncode(true);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "error 3");
}


//--------------

Kindly help me asap its urgent and i am using Windows 7 32-Bit OS with Visual Studio 2010 and i had already downloaded and installed the Windows Encoder library for Microsoft Website..
have a nice day .. Please help me asap
Posted
Updated 8-Jan-13 10:40am
v2

1 solution

Please don't tell us it's urgent. That you need us is not urgent to us.

If you're doing a lot of work, you should try calling Application.DoEvents in your loop, or do it in a thread. If your process is busy for a long time, W7 will shut it down, even though it's working.
 
Share this answer
 
Comments
Gaurav_Chhabra 8-Jan-13 17:12pm    
Christian i didn't understand your point, which events you are telling to do in loop.. and this error just comes may be within 5-8 seconds after i click on the button for conversion..
Christian Graus 8-Jan-13 17:14pm    
You have a for each statement. This is a loop. You probably need to do it on another thread.
Gaurav_Chhabra 8-Jan-13 17:31pm    
which thread .. ?? can you please tell me
Christian Graus 8-Jan-13 17:32pm    
You need to create another thread, using BackgroundWorker, for example, for this to occur without killing your UI thread.

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