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

发布于 2024-09-07 15:52:26 字数 1191 浏览 10 评论 0原文

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

问题是我想以编程方式配置编码器(比特率、通道、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 方法似乎对输出文件没有影响。 我尝试使用属性页面配置我的过滤器并且它有效。

所以,我想知道是否有人已经在 DirectShow 应用程序(.NET 或非 .NET)中使用了 LAME 编码器并且可以给我带来一些帮助?

问候。

-- 西弗

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十六岁半 2024-09-14 15:52:27

也许我迟到了,但我遇到了同样的问题。解决方案是按照与 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
}

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文