2
Answers

converting block of jpg to wmv using window media encoder

Ask a question
jacobah

jacobah

11y
1.7k
1
 
Hi
I try to convert jpg to wmv using window media encoder
I running this code (contain single jpg for Trial) I get error
"System.Runtime.InteropServices.COMException (0xC00D0BB8): The input media format is invalid."
at line: SrcVid.SetInput(@"C:\Users\jacoba\Videos\Untitled.jpg", "", "");
any idea how to SetInput for jpg (or any others image - BMP, PNG etc.)
thanks,

  1. try
  2.             {
  3.                 //get current folder
  4.                 string curentFolder = Directory.GetCurrentDirectory();
  5.                 // Create a WMEncoder object.
  6.                 WMEncoder Encoder = new WMEncoder();
  7.                 // Retrieve the source group collection.
  8.                 IWMEncSourceGroupCollection SrcGrpColl = Encoder.SourceGroupCollection;
  9.                 // Add a source group to the collection.
  10.                 IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1");
  11.                 IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
  12.                 SrcVid.SetInput(@"C:\Users\jacoba\Videos\Untitled.jpg", "", ""); //Bitmap file (.bmp, .gif or .jpg file)
  13.                 // Crop 2 pixels from each edge of the video image.
  14.                 SrcVid.CroppingBottomMargin = 2;
  15.                 SrcVid.CroppingTopMargin = 2;
  16.                 SrcVid.CroppingLeftMargin = 2;
  17.                 SrcVid.CroppingRightMargin = 2;
  18.                 // Specify a file object in which to save encoded content.
  19.                 IWMEncFile File = Encoder.File;
  20.                 File.LocalFileName = curentFolder + @"\OutputFile.wmv";
  21.                 // Choose a profile from the collection.
  22.                 IWMEncProfileCollection ProColl = Encoder.ProfileCollection;
  23.                 IWMEncProfile Pro;
  24.                 for (int i = 0; i < ProColl.Count; i++)
  25.                 {
  26.                     Pro = ProColl.Item(i);
  27.                     //Console.WriteLine(Pro.Name.ToString());
  28.                     if (Pro.Name == "Windows Media Video 8 for Broadband (PAL, 700 Kbps)")  //"Screen Video/Audio High (CBR)"
  29.                     {
  30.                         SrcGrp.set_Profile(Pro);
  31.                         break;
  32.                     }
  33.                 }
  34.                 // Fill in the description object members.
  35.                 IWMEncDisplayInfo Descr = Encoder.DisplayInfo;
  36.                 Descr.Author = "Author name";
  37.                 Descr.Copyright = "Copyright information";
  38.                 Descr.Description = "Text description of encoded content";
  39.                 Descr.Rating = "Rating information";
  40.                 Descr.Title = "Title of encoded content";
  41.                Encoder.PrepareToEncode(true);
  42.                 Encoder.Start();
  43.                 Console.WriteLine("Press Enter when the file has been encoded.");
  44.                 Console.ReadLine(); // Press Enter after the file has been encoded.
  45.             }
  46.             catch (Exception e)
  47.             {
  48.                 Console.WriteLine(e.ToString());
  49.                 Console.ReadLine();
  50.             } 

Answers (2)