C# WM编码器抛出COMException(0x80004005)未指定错误

C# WM编码器抛出COMException(0x80004005)未指定错误,c#,com,C#,Com,所以我在运行这个代码 public static void ConvertToWma(string inFile, string outFile, string profileName) { // Create a WMEncoder object. WMEncoder encoder = new WMEncoder(); ManualResetEvent stopped = new ManualResetEvent(false);

所以我在运行这个代码

    public static void ConvertToWma(string inFile, string outFile, string profileName)
    {
        // Create a WMEncoder object.
        WMEncoder encoder = new WMEncoder();
        ManualResetEvent stopped = new ManualResetEvent(false);
        encoder.OnStateChange += delegate(WMENC_ENCODER_STATE enumState)
        {
            if (enumState == WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED)
                stopped.Set();
        };
        // Retrieve the source group collection.
        IWMEncSourceGroupCollection srcGrpColl = encoder.SourceGroupCollection;

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

        // Add an audio source to the source group.
        IWMEncSource srcAud = srcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
        srcAud.SetInput(inFile, "", "");

        // Specify a file object in which to save encoded content.
        IWMEncFile file = encoder.File;
        file.LocalFileName = outFile;

        // Choose a profile from the collection.
        IWMEncProfileCollection proColl = encoder.ProfileCollection;
        proColl.ProfileDirectory = AssemblyInformation.GetExecutingAssemblyDirectory();
        proColl.Refresh();
        IWMEncProfile pro;

        for (int i = 0; i < proColl.Count; i++)
        {
            pro = proColl.Item(i);
            if (pro.Name == profileName)
            {
                srcGrp.set_Profile(pro);
                break;
            }
        }
        // Start the encoding process.
        // Wait until the encoding process stops before exiting the application.
        encoder.SynchronizeOperation = false;
        encoder.PrepareToEncode(true);
        encoder.Start();
        stopped.WaitOne();
    }
当encoder.PrepareToEncode执行时,我得到一个COMException 0x80004005

一些注意事项:

1该进程由ASP.NET web服务生成,因此它作为网络服务运行 2 infle和outFile是绝对的局部路径,它们的扩展是正确的,此外infle肯定存在这是过去问题的根源 3当我以自己的身份运行程序时,该程序可以工作,但在ASP.NET上下文中不工作


这对我来说是一个安全许可问题,因此,除此之外,我已将包含程序的目录和包含音频文件的目录的完全控制权授予网络服务。所以我真的不知道我还能在安全方面做些什么。有任何帮助吗?

不支持在windows服务中运行基于WM编码器SDK的应用程序。出于各种原因,它使用隐藏窗口,并且服务中没有桌面窗口。如果没有用户配置文件,DRM肯定会失败。此外,即使您让您的服务与用户桌面上的WME实例对话,Microsoft也只支持每台机器4个并发请求,因为WME中的全局锁我知道,不太好编程,但WME很旧。对于更可扩展的解决方案,请考虑Windows媒体格式SDK.


由于WM编码器的支持即将结束,您可能希望将基于WM编码器的应用程序移动到Expression Encoder SDK

我在写这篇文章的时候,正在浏览表达式编码器的API,并处理应用程序。它似乎不支持解码到普通的旧PCM,这最终是我真正想要的。我错了吗?PCM不是windows media格式。您可以编写自己的推送源DiorectShow筛选器,用于读取PCM数据并将样本推送到输出,并在任何DirectShow程序(如WME/WMP)中使用它,或者如果您计划使用Windows Media音频编解码器进行编码,则可使用Windows Media writer编写样本。