delphi - 使用 Windows AVIFile 函数提高 Delphi 6 应用程序的压缩率?

标签 delphi winapi video-encoding avi

我有一个 Delphi 6 应用程序,可以根据机器人传入的视频和音频流制作电影。 PC 接收一系列 JPEG 帧形式的视频流和 PCM 音频数据 block 形式的音频。我正在使用 Windows AVIFile 函数(AVIStreamCreate 等)来创建电影。对于视频压缩器的选择,我使用 AVISaveOptions() 函数,并让用户从系统上可用的压缩器中选择一种可用的压缩器。例如:Microsoft Video 1、Cinepak Code by Radius 等。请注意其他几个可用的代码,例如 Microsoft H.263 或 H.261 因 AVIERR_BADFORMAT 错误而失败,因此我无法使用它们进行测试。音频使用 GSM 6.10 压缩器进行压缩。

问题是我似乎无法接近使用 Adob​​e Premiere 等工具进行比较的压缩率。请注意,我知道 Premiere 使用与我不同的整体流程进行压缩,并使用不同的文件格式(如 MPEG 或 Quicktime 等)。但如果可以的话,我希望获得可比较的压缩率。

无论我从 AVISaveOptions() 中选择哪种压缩器,也无论我将压缩器的可用压缩质量设置调得多低(例如,Microsoft Video 1 的时间质量比和压缩质量),一分钟的视频都值得最终总是会创建一个大小约为 14MB 的 AVI 文件。为了进行比较,我使用 Adob​​e Premiere 创建的文件大小不到 1 MB,并且看起来具有相同的视觉质量(换句话说,对于我的目的来说已经足够好了。我不关心实际的效果)这里的质量损失。)。

如果我检查使用 Windows AVI API 的文件输出,我会发现我使用压缩器更改的所有设置都不会影响帧速率。它始终与输入帧速率相同。现在,如果有必要,显然我可以在输入端丢弃帧,但这会有点困惑,因为它与音频同步,如果可以的话,我想避免这种情况。

但更重要的是数据速率。无论我将压缩器设置调低到多低,我都无法将其降低到大约 2.3 kbps 以下。我使用 Premiere 创建的视频以及我播放过的其他具有良好文件大小与持续时间比率的视频均约为 1.2 kbps。

总体而言,我的 AVI 文件与我使用 Premiere 创建的或其他人发送给我的压缩良好的文件大小之间的差异是10 比 1。因此,我的压缩比比其他视频文件差 10 倍,而其他文件的视频质量没有令人不快的差异。

如何才能获得可比的压缩比?

更新:David Heffernan 的回复包含一个对我有用的快速解决方案。我之所以强调它,是因为它还包含重要许可警告。对于那些像我一样希望让用户尽可能方便地使用 XVid 编解码器的人,请阅读下面的文章。它包含有关如何在将来的 session 中重用用户的压缩器选择以及他们选择的压缩配置选项的说明,而不会再次打扰用户:

http://msdn.microsoft.com/en-us/magazine/hh580739.aspx

出于好奇,我之前输出的 AVI 文件大小与使用 XVid 编解码器创建的文件大小的变化为 12.231 MB 到 632 KB,并且视频质量非常合理。

最佳答案

真正简单的答案是安装 XVID编码器。 Windows 提供的编解码器都不适合您的用途。 XVID 既高质量又免费。

关于分发和许可影响,XVID FAQ有这样说:

Can I distribute Xvid together with my proprietary program?

If your program calls Xvid functionality upon run-time it’s a derived work and hence, the terms of the GPL apply to the work as a whole including your program. So no, you cannot distribute Xvid together with your proprietary program then. If you want to distribute, you’ll have to publish your program under the GPL as well. That also requires e.g. the provision of the full apps source code. Refer to the GPL license text for more information.

We don’t link to Xvid at all, just call through the VfW interface upon run-time – can we distribute with our proprietary software?

No. It doesn’t matter in which way you link to Xvid or what you count as linking and what not. The GPL doesn’t focus on the term ‘linking’ at all but rather requires combined/derived works to be published as a whole under the terms of the GPL. Basically any two (or more) pieces make up a combined work when they are distributed for use in combination. Hence, if your program calls upon Xvid functionality at run-time it would make up a derived work - no matter how you technically implement the calls to Xvid. If you don’t want to publish your program under the GPL then refrain from distributing it in combination with Xvid.

这对您来说意味着,如果您的程序也获得了 GPL 许可,则您只能将 XVID 与您的程序一起分发。但您完全可以建议您的用户自己获取 XVID。

关于delphi - 使用 Windows AVIFile 函数提高 Delphi 6 应用程序的压缩率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10564736/

相关文章:

ffmpeg - "copy"在 ffmpeg 命令行中做了什么?

windows - Delphi:将应用程序最小化到系统托盘

image - Delphi组合阵列图像

delphi - TGifImage 透明度问题

c# - 是否存在具有 user32.dll 中的函数、类型和常量的预先存在的 .NET 程序集或 NuGet 程序包(或类似程序包)?

java - PE header 要求

ffmpeg - avformat_write_header 产生无效的 header (导致 MPG 损坏)

delphi - 是否有一个 Delphi 库可以返回项目的所有有效源路径?

c++ - 汇编中的字符串长度例程替代 C++ 中的 strlen

ffmpeg - 一个文件中的多个并排视频流,无需转码