Configure LAME MP3 encoder in DirectShow applicati

2019-06-27 17:27发布

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条回答
聊天终结者
2楼-- · 2019-06-27 17:58

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
}
查看更多
登录 后发表回答