配置LAME MP3连接codeR DirectShow中的应用程序中使用IAudioEn coderProperties应用程序、codeR、LAME、coderProperties

2023-09-04 12:15:22 作者:旧城不暖少年心

我书面方式在.NET应用程序的DirectShow捕捉音频流从任何捕获设备,连接codeS它的MP3使用LAME DirectShow过滤器,最后流写入到文件中。 这是我的DirectShow图形: 捕捉源 - > LAME音频EN codeR(音频COM pressor) - > WAV DEST(波复用器,从SDK sourcres编译) - >文件写入

I'm writting a .NET DirectShow application which captures audio stream from any capture device, encodes it in mp3 using the LAME directshow filter and finally writes the stream into a file. This is my directshow graph: capture source -> LAME AUDIO ENCODER (Audio compressor) -> WAV DEST (Wave muxer, compiled from SDK sourcres) -> File writer.

现在的问题是,我想配置EN codeR(码率,声道,VBR / CBR等)编程,而不是使用属性页面(ISpecifyPropertyPages)可在LAME EN codeR。

The problem is that I'd like to configure the encoder (bitrate, channels, VBR/CBR, etc) programmatically and not using the properties pages (ISpecifyPropertyPages) available on the LAME encoder.

检索LAME源后,似乎必须使用特定IAudioEn coderProperties接口进行配置。

After retrieving LAME sources, it appears that the configuration must be done using the specific IAudioEncoderProperties interface.

我试图用这种声明来封此COM接口,在我的.net应用程序:

I tried to marshal this COM interface in my .NET application using this declaration:


 
 [ComImport]
 [SuppressUnmanagedCodeSecurity]
 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
 [Guid("ca7e9ef0-1cbe-11d3-8d29-00a0c94bbfee")]
 public interface IAudioEncoderProperties
 {
   // Get target compression bitrate in Kbits/s
   int get_Bitrate(out int dwBitrate);

   // Set target compression bitrate in Kbits/s
   // Not all numbers available! See spec for details!
   int set_Bitrate(int dwBitrate);
 }

请注意,并不是所有的方法都重新定义。

Note that not all methods are redefined.

我可以用成功投我的音乐​​融为一体pressor过滤器(LAME的EN codeR):

I can successfully cast my audio compressor filter (the LAME encoder) using:

IAudioEncoderProperties prop = mp3Filter as AudioEncoderProperties;

但是,当我打电话get_Bitrate方法的返回值是0,并调用set_Bitrate方法似乎对输出文件中没有发生。 我尝试使用属性页面配置我的过滤器和它的作品。

But when I call get_Bitrate method the returned value is 0 and calling the set_Bitrate method seems to have no incidence on the output file. I tried configuring my filter using the properties pages and it works.

所以,我想知道是否有人已经使用了LAME EN codeR成一个DirectShow应用程序(.NET或没有),可以给我一些帮助?

So, I'd like to know if anybody has already used the LAME encoder into a DirectShow application (.NET or not) and could bring me some help?

问候。

- Sypher

-- Sypher

推荐答案

也许我迟到了,但我跑了同样的问题。解决的办法是声明的方法在你的界面完全相同的顺序,因为它们是在LAME源的声明。

Maybe I am late, but I ran in the same problem. The solution is to declare methods in your interface in exactly same order as they are declared in LAME sources.

[ComImport]
[SuppressUnmanagedCodeSecurity]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("ca7e9ef0-1cbe-11d3-8d29-00a0c94bbfee")]
public interface IAudioEncoderProperties
{
    /// <summary>
    /// Is PES output enabled? Return TRUE or FALSE
    /// </summary>      
    int get_PESOutputEnabled([Out] out int dwEnabled);

    /// <summary>
    /// Enable/disable PES output
    /// </summary>      
    int set_PESOutputEnabled([In] int dwEnabled);

    /// <summary>
    /// Get target compression bitrate in Kbits/s
    /// </summary>      
    int get_Bitrate([Out] out int dwBitrate);

    /// <summary>
    /// Set target compression bitrate in Kbits/s
    /// Not all numbers available! See spec for details!
    /// </summary>      
    int set_Bitrate([In] int dwBitrate);

    ///... the rest of interface
}