Configure LAME MP3 encoder in DirectShow application using IAudioEncoderProperties

廉价感情. 提交于 2019-12-10 15:29:00

问题


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.

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.

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

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.

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

IAudioEncoderProperties prop = mp3Filter as AudioEncoderProperties;

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.

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?

Regards.

-- Sypher


回答1:


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
}


来源:https://stackoverflow.com/questions/3159082/configure-lame-mp3-encoder-in-directshow-application-using-iaudioencoderproperti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!