使用IAudioEncoderProperties在DirectShow应用程序中配置LAME MP3编码器

时间:2010-07-01 15:07:40

标签: c# .net mp3 directshow lame

我正在编写.NET DirectShow应用程序,该应用程序从任何捕获设备捕获音频流,使用LAME directshow过滤器将其编码为mp3,最后将流写入文件。 这是我的directshow图: 捕获源 - > LAME AUDIO ENCODER(音频压缩器) - > WAV DEST(Wave muxer,从SDK sourcres编译) - >文件编写者。

问题是我想以编程方式配置编码器(比特率,通道,VBR / CBR等),而不是使用LAME编码器上可用的属性页(ISpecifyPropertyPages)。

检索LAME源后,似乎必须使用特定的IAudioEncoderProperties接口完成配置。

我尝试使用此声明在我的.NET应用程序中封送此COM接口:

 
 [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);
 }

请注意,并非所有方法都已重新定义。

我可以使用以下方法成功投射音频压缩器滤镜(LAME编码器)

IAudioEncoderProperties prop = mp3Filter as AudioEncoderProperties;

但是当我调用get_Bitrate方法时,返回的值为0并且调用set_Bitrate方法似乎没有输出文件。 我尝试使用属性页面配置我的过滤器,它可以工作。

所以,我想知道是否有人已经将LAME编码器用于DirectShow应用程序(或不是.NET)并且可以给我一些帮助吗?

问候。

- Sypher

1 个答案:

答案 0 :(得分:1)

也许我迟到了,但我遇到了同样的问题。解决方案是在接口中声明方法的顺序与在LAME源中声明的顺序完全相同。

[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
}