Interface of AVProbe Component

{
  function Seek(const APTS: Int64; ASeekFlags: TSeekFlags = []): Boolean;
    if sfByte in ASeekFlags then
      APTS: Position in bytes, its bound is 0 to size of the file.
    else
      APTS: Presentation Time Stamp in microsecond, its bound is 0 to
        total duration of the file.
    ASeekFlags: TSeekFlags = set of TSeekFlag
      sfBackward: // seek backward
      sfByte:     // seeking based on position in bytes
      sfAny:      // seek to any frame, even non key-frames

  function Decode(AStreamIndex: Integer = -1): Boolean;
    AStreamIndex: special video stream to seek, must set as video stream's index.
      -1 means using the first video stream.
    if Decode() successfully, use property FrameInfo to get the information.
    NOTICE: after Decode() call, the position will change to next frame.

  function CopyToBitmap(ABitmap: TBitmap): Boolean;
    if Decode() successfully, copy the decoded frame picture to ABtimap.
}

type

  TFileStreamInfo = record
    StartTime: Int64;
    Duration: Int64;
    BitRate: Integer;
    TimeStamp: Int64;
    Year: Integer;
    Track: Integer;
    Title: string;
    Author: string;
    Copyright: string;
    Comment: string;
    Album: string;
    Genre: string;
  end;

  TAudioStreamInfo = record
    Language: string;
    CodecName: string;
    StartTime: Int64;
    StartTimeScaled: Int64;
    Duration: Int64;
    DurationScaled: Int64;
    BitRate: Integer;
    Channels: Integer;
    SampleRate: Integer;
    SampleFormat: TSampleFormat;
  end;

  TVideoStreamInfo = record
    Language: string;
    CodecName: string;
    StartTime: Int64;
    StartTimeScaled: Int64;
    Duration: Int64;
    DurationScaled: Int64;
    BitRate: Integer;
    Height: Integer;
    Width: Integer;
    AspectRatio: Single;
    PixFmt: TAVPixelFormat;
    FrameRate: TAVRational;
  end;

  TSubtitleStreamInfo = record
    Language: string;
    CodecName: string;
  end;

  TCustomAVProbe = class(TComponent)
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    function AVLibLoaded: Boolean;
    function LoadAVLib(const APath: TPathFileName): Boolean;
    procedure UnloadAVLib;

    function LoadFile(const AFileName: WideString; const AFormatName: string = ''): Boolean;
    procedure CloseFile; virtual;

    function IsAudioStream(AStreamIndex: Integer): Boolean;
    function IsVideoStream(AStreamIndex: Integer): Boolean;
    function IsSubtitleStream(AStreamIndex: Integer): Boolean;

    procedure ParentKey; // internal used only
    procedure SetLicenseKey(const AKey: AnsiString; ASeed: LongWord; AHex: Boolean = True);

    property FileHandle: PAVFormatContext read FFileHandle write SetFileHandle;
    property FileName: WideString read GetFileName;
    property FileSize: Int64 read FFileSize;
    property ForceFormat: string read FForceFormat;
    property FormatName: string read GetFormatName;
    property FormatLongName: string read GetFormatLongName;

    property StreamCount: Integer read FStreamCount;
    property ProgramCount: Integer read FProgramCount;
    property Programs[Index: Integer]: TAVProgram read GetProgrames;

    property AudioStreamCount: Integer read FAudioStreamCount;
    property VideoStreamCount: Integer read FVideoStreamCount;
    property SubtitleStreamCount: Integer read FSubtitleStreamCount;

    property FileStreamInfo: TFileStreamInfo read GetFileStreamInfo;
    property AudioStreamInfos[Index: Integer]: TAudioStreamInfo read GetAudioStreamInfos;
    property VideoStreamInfos[Index: Integer]: TVideoStreamInfo read GetVideoStreamInfos;
    property SubtitleStreamInfos[Index: Integer]: TSubtitleStreamInfo read GetSubtitleStreamInfos;

    property FileInfoText: string read GetFileInfoText;
    property FirstAudioStreamIndex: Integer read FFirstAudioStreamIndex;
    property FirstVideoStreamIndex: Integer read FFirstVideoStreamIndex;
    property FirstSubtitleStreamIndex: Integer read FFirstSubtitleStreamIndex;
    property FirstAudioStreamInfo: TAudioStreamInfo read GetAudioStreamInfo;
    property FirstVideoStreamInfo: TVideoStreamInfo read GetVideoStreamInfo;
    property FirstSubtitleStreamInfo: TSubtitleStreamInfo read GetSubtitleStreamInfo;

    property LastErrMsg: string read FLastErrMsg;
  end;

  TPictureType = (
    ptUnknown = 0,
    ptI  = 1, ///< Intra
    ptP  = 2, ///< Predicted
    ptB  = 3, ///< Bi-dir predicted
    ptS  = 4, ///< S(GMC)-VOP MPEG4
    ptSI = 5, ///< Switching Intra
    ptSP = 6, ///< Switching Predicted
    ptBI = 7);

  TSeekFlag = (
    sfBackward, // seek backward
    sfByte,     // seeking based on position in bytes
    sfAny);     // seek to any frame, even non key-frames
  TSeekFlags = set of TSeekFlag;

  TFrameInfo = record
    PixFmt: TAVPixelFormat;
    Width: Integer;
    Height: Integer;
    IsKeyFrame: Boolean;
    PictureType: TPictureType;
    PTS: Int64;
    OriginalDTS: Int64;
    OriginalPTS: Int64;
    StreamIndex: Integer;
    Ready: Boolean;
    Picture: TAVPicture;
    Buffer: PByte;
    Size: Integer;
  end;

  TAVProbe = class(TCustomAVProbe)
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure CloseFile; override;

    function Seek(const APTS: Int64; ASeekFlags: TSeekFlags = []): Boolean;
    function Decode(AStreamIndex: Integer = -1): Boolean;
    function CopyToBitmap(ABitmap: TBitmap): Boolean;

    property EOF: Boolean read FEOF;
    property FrameInfo: TFrameInfo read FPicture;
    property Position: Int64 read GetPosition;
  end;