Hi
i try to convert jpg to wmv using window media encoder
when i running this code 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,

try
            {
                //get current folder
                string curentFolder = Directory.GetCurrentDirectory();

                // Create a WMEncoder object.
                WMEncoder Encoder = new WMEncoder();

                // Retrieve the source group collection.
                IWMEncSourceGroupCollection SrcGrpColl = Encoder.SourceGroupCollection;

                // Add a source group to the collection.
                IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1");


                IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
                SrcVid.SetInput(@"C:\Users\jacoba\Videos\Untitled.jpg", "", ""); //Bitmap file (.bmp, .gif or .jpg file)



                // Crop 2 pixels from each edge of the video image.
                SrcVid.CroppingBottomMargin = 2;
                SrcVid.CroppingTopMargin = 2;
                SrcVid.CroppingLeftMargin = 2;
                SrcVid.CroppingRightMargin = 2;

                // Specify a file object in which to save encoded content.
                IWMEncFile File = Encoder.File;
                File.LocalFileName = curentFolder + @"\OutputFile.wmv";

                // Choose a profile from the collection.
                IWMEncProfileCollection ProColl = Encoder.ProfileCollection;
                IWMEncProfile Pro;
                for (int i = 0; i < ProColl.Count; i++)
                {
                    Pro = ProColl.Item(i);
                    //Console.WriteLine(Pro.Name.ToString());
                    if (Pro.Name == "Windows Media Video 8 for Broadband (PAL, 700 Kbps)")  //"Screen Video/Audio High (CBR)"
                    {
                        SrcGrp.set_Profile(Pro);
                        break;
                    }
                }

                // Fill in the description object members.
                IWMEncDisplayInfo Descr = Encoder.DisplayInfo;
                Descr.Author = "Author name";
                Descr.Copyright = "Copyright information";
                Descr.Description = "Text description of encoded content";
                Descr.Rating = "Rating information";
                Descr.Title = "Title of encoded content";

               Encoder.PrepareToEncode(true);
                Encoder.Start();
                Console.WriteLine("Press Enter when the file has been encoded.");
                Console.ReadLine(); // Press Enter after the file has been encoded.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.ReadLine();
            }          

Recommended Answers

All 3 Replies

Hmmm, well I am no expert here, but it looks like what you are trying to do just doesn't like it. The Interop service doesn't want to accept the .jpg simple as that. Now you mention .BMP, have you actually gotten it to work with other file formats? To be honest I don't know if Interop will allow.

Another way you could do this in theory is you could edit the file's header in hex and alter the hex bits from the .jpeg to .wmv

JPG Headers are
FF D8 FF E0 xx xx 4A 46
49 46 00

and Trailer is
FF D9

While WMV Headers
30 26 B2 75 8E 66 CF 11
A6 D9 00 AA 00 62 CE 6C

So you would need to remove these hexidecimal bits (for JPEG both the header and trailer, which should be the first and last bits of the file) and add the WMV bits to the beginning.

You can read about them here, http://www.garykessler.net/library/file_sigs.html

However to be honest, if they try to open the .jpg as a .wmv, what ever you are using to view .wmvs will probably just yell about errors (cause it's not a format they know).

I have no clue if this is what you were looking for, but it's one way to go about it (it's something I have seen in these challenge/hacking events I have participated in). You could read in the file as binary bits, and then convert them and then export them similarly, but I don't have a lot of knowledge how to do it (I usually do it manually with a hex editor).

I think you missed
Eventually I want to convert a large number of images to video

Ohh I see, my apologize.

Have you ever though of doing just a .gif? Since that's an animated image, or does it need audio.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.