适用于 Delphi 等非 C 族语言的 FFmpeg 解码简化库 FFDec 发布

来源:互联网 发布:c语言入门自学书籍下载 编辑:程序博客网 时间:2024/06/05 14:56
FFmpeg is a very powerful library for video/audio encoding/decoding. But unfortunately it is very difficult to use in non-C/C++ developments. So I wrote this library a year ago to simplify it for other programming languages - especially for Delphi (but I think it would work in Free Pascal too).

The FFDec library consists of only ONE single DLL, which may be released as two versions (see below), and a Pascal header file, which loads the DLL dynamically. You can simply include the header and compile your code.

You can find the official site of FFDec on SF.net:
http://sourceforge.net/projects/ffdec/

The FFDec library wraps the original FFmpeg-APIs almost directly. The usage of FFDec functions is very similar to the libAV* functions. So you'd better get some FFmpeg knowledge before you work with FFDec. I'm sorry that I cannot provide a detailed documentation currently. However, I prefer you to read the DLL source code (it's short and simple) to get ideas of how it works.

The library is released under GPL or LGPL license depending on the embedded FFmpeg version. Both versions can be called in the same way, but the LGPL version may support less formats.

FFmpeg 是一个非常强大的视频/音频编码解码库。但是很可惜,人们很难将其应用到非 C/C++ 的工程中。因此我一年前将其重新封装为一个库并希望这一工作能够简化其在视频解码方面的应用——尤其是在 Delphi (或 Free Pascal) 中的应用。

FFDec 库由一个 DLL (有可能按照授权方式不同分为两个版本) 和一个负责动态装载 DLL 的 Pascal 头文件。用户可以直接将其加入到自己的工程中进行编译。

您可以访问在 SF.net 上 FFDec 的官方主页来取得最新的信息:
http://sourceforge.net/projects/ffdec/

FFDec 几乎是直接对 FFmpeg 的原生 API 进行了转换封装。FFDec 的库函数在应用上也与 libAV* 函数十分接近。因此在使用 FFDec 之前,您有必要先了解一下 FFmpeg 的原理。此外抱歉的是,我近期内恐怕无法提供详细的 FFDec 的文档。不过您可以通过查看 DLL 源代码(它比你想象的要简单)以取得对 FFDec 工作原理的认知。

依照集成的 FFmpeg 库的版本授权不同,FFDec 库分为 GPL 和 LGPL 版本。两个版本都可以按照统一的接口调用,只是 LGPL 版本所支持的文件格式要少一些。

Example/一个简单的范例:

uses FFDecImport;

//...

var
  decoder : HFFDecoder;
  info : AVInfo;
  packet : PAVPacket;
  buffer : array [0..10000000] of Byte;
  size : Integer;
begin
  decoder := ffOpenFile('x:/xxx.avi', @info);
  packet := ffCreateAVPacket(True);
  try
    while ffRead(decoder, packet,
      FFDEC_RAW_FRAME_TYPE_ANY) do
    begin
      if packet.stream_index
        = info.audioStreamIndex then
      begin
        if ffDecode(decoder, packet,
          @(buffer[0]), Length(buffer), size) then
        // Play the decoded audio samples ...
      end
      else if packet.stream_index
        = info.videoStreamIndex then
      begin
        if ffDecode(decoder, packet,
          @(buffer[0]), Length(buffer), size) then
        // Show the decoded
        // picture (BGR24 format) ...
      end;
    end;
  finally
    ffFreeAVPacket(packet);
    ffClose(decoder);
  end;
end;
原创粉丝点击