.NET Forum / .NET Framework / Interop / April 2004
Help with Windows Media Encoder in C#
|
|
Thread rating:  |
Riley Phelps - 23 Mar 2004 08:21 GMT I am trying to create a .wmv using the Media Encoder SDK (v9) in C#. I am having problems wit source groups that have graphic (.bmp, .gif and .jpg) files. According to the "Using a File as a Source page in the documentation "C:\WMSDK\WMEncSDK9\wmencsdk.chm", plug-ins for .bmp and .jpg are include with the SDK. THe second paragraph also atates that "The correct plug-in is automatically chosen for a specific file,"
Below is the C# code used to enoced a single segment
Encoder = new WMEncoder()
IWMEncSourceGroupCollection SrcGrpColl = Encoder.SourceGroupCollection
IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1")
IWMEncAudioSource SrcAud = (IWMEncAudioSource)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO) SrcAud.SetInput(@"C:\audiofile.wav", "", "")
IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO) SrcVid.SetInput(bitmapfile, "", ""); //Bitmap file (.bmp, .gif or .jpg file
IWMEncProfile2 Pro = new WMEncProfile2() Pro.LoadFromFile(@"C:\profile.prx") SrcGrp.set_Profile((IWMEncProfile)Pro)
IWMEncFile2 File = (IWMEncFile2)Encoder.File
File.LocalFileName = @"C:\output.wmv" File.FileDuration = audioDuration; //Duration of audio fil
Encoder.PrepareToEncode(true) Encoder.OnStateChange += new _IWMEncoderEvents_OnStateChangeEventHandler(encoder_StateChange) Encoder.OnSourceStateChange += new _IWMEncoderEvents_OnSourceStateChangeEventHandler(encoder_SourceStateChange) Encoder.Start()
The setting for the profile (profile.prx) are
Audio: Mode - CBR, Codec - Windows Media Audio Video: Mode - CBR, Codec - Windows Media Video
Video format: NTSC(29.97/30fps
Target bit rate 256 Kbp
Audio format 48 kbps, 44 kHz, mono CB
Video size: 320x24
Frame rate: 29.97 fps, 6 sec interva
Video bit rate: 194.967Kbp
Buffer size 5 se
Video smootheness: 8
Decoder complexity: Aut
When I try a Bitmap file (.bmp), the WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED status chang does not occur. The following status and source state changes occur
WMENC_ENCODER_STARTIN WMENC_ENCODER_RUNNIN
WMENC_SOURCE_PREPARE - WMENC_AUDI WMENC_SOURCE_PREPARE - WMENC_VIDE WMENC_SOURCE_START - WMENC_AUDI WMENC_SOURCE_START - WMENC_VIDE WMENC_SOURCE_STOP - WMENC_AUDI
When I try Jpeg or Gif files, I get an exception "The input media is invalid." when PrepareToEncode is called
What do I need to do to encode graphic files into a .wmv
"Ying-Shen Yu[MSFT]" - 24 Mar 2004 07:14 GMT Hi Riley,
I tried encoding the wmv file using your code snippet. It used the JPG/.GIF file without problem.
I'd like to know if you meet the the same problem when you encode file using the Windows Media Encoder?
Thanks!
Best regards,
Ying-Shen Yu [MSFT] Microsoft community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
"Ying-Shen Yu[MSFT]" - 25 Mar 2004 14:14 GMT Hi Riley,
Thanks for your reply, The list in your screenshot is video transform plug-in, the file format plugins are not listed in this list, as document described the file format plugins are included in Windows Media Encoder SDK. There are no additional packages to install.
I'd like you try encoding a wmv file using the Windows Media Encoder, so that we can know if the file format plugins are installed properly. You may encode the test wmv file in the steps below: 1. Open the Windows Media Encoder, choose "Custom session" 2. In the Source Tab, "Source 1", set Source from to "Both device and file". 3. set the video option to "browse for file" and choose a jpg/gif file. 4. set the video option to a wave file 5. select the Output tab check off the option "Pull from encoder ...." , check the "Encode to file" and set a filename in it. 6. click "Apply" button. then start encoding.
Does it report any error message during these steps?
You may also try some other jpg/gif files (e.g. google's logo) to see if this problem is only occurred on some certain files. Also if is possible, you may do the same test on another machine to see if the code works, it will do some help to exclude the setup issue. You only need install the Windows Media Encodes 9 and Windows Media Encoder 9 SDK to do the test.
If you have any information on this issue, please feel free to reply in this thread.
Thanks!
Best regards,
Ying-Shen Yu [MSFT] Microsoft community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
"Ying-Shen Yu[MSFT]" - 29 Mar 2004 12:32 GMT Hi Riley,
I apologize for the delay, I was able to reproduce this error on my system using a 499x278 pixel jpeg file. I think this is a normal bahavior, the WME document says:
Video images with one or two odd-sized dimensions are not supported. For example, an image that is 300 by 321 pixels generates an error, but an image that is 300 by 320 pixels does not.
So changing your image size to 500x278 or 498x278 should be ok, I tested these two image sizes on my machine and they all worked fine. I didn't meet problem when I scale the image down to 320x240 either. I discussed this problem with another member in my team, but neither of us can think of a possible cause of the "hang" problem. Consider the hang problem is more difficult than the initial problem, Before assist you investigating the hang problem further, I'd first like you try encoding this 320x240 image on another system to see if this problem could be reproduced on another system too? If yes, possibly this problem is related to this image and was able to reproduced on other systems, please send me this image to help me reproduce it on my system. If the image could be encoded successfully on another system, You may try re-installing the windows media encoder and try again to see if it is caused by a installation issue.
If you have any updates on this issue, please feel free to reply this thread, thanks!
Best regards,
Ying-Shen Yu [MSFT] Microsoft community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
Sorry for the delay. I have been moving. Changing the size eliminated the exception. However, the encoding process still hangs, i.e., the the WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED status change does not occur. If possible I can send you a sample image, however I will not be able to send it to you through the newsgroup, I would have to send it to you directly. Also, if you could let me know what to look for on my system as far as configuration that might affect the encoding.
Thank you,
Riley Phelps
>-----Original Message----- >Hi Riley, [quoted text clipped - 38 lines] > >. "Ying-Shen Yu[MSFT]" - 15 Apr 2004 03:24 GMT Hi Riley,
Please feel free to send me the sample by e-mail, I'll take look into it if this problem also occurs on my machine.
By the way, regarding this thread is a bit old, other community members are less likely to see it, could we start a new thread to go on investigating this issue?
Thanks!
Best regards,
Ying-Shen Yu [MSFT] Microsoft Community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|