Download Delphi FFmpeg VCL Components

Interface of FFPlayer Component(Video Player)

type
  TAudioVolume = 0..SDL_MIX_MAXVOLUME;
  TPlayState = (psPlay, psPause, psResume, psStep, psStop, psEnd);
  TRepeatType = (rtNone, rtStop, rtLoop);
  TAudioDriver = (adDefault, adDirectSound, adWaveOut);
  TVideoDriver = (vdDefault, vdDirectDraw, vdGDI);

  THookEvent = procedure(Sender: TObject; ABitmap: TBitmap; const APTS: Int64) of object;
  TFileOpenEvent = procedure(Sender: TObject; const ADuration: Int64;
    const AFrameWidth, AFrameHeight: Integer; var AScreenWidth, AScreenHeight: Integer) of object;
  TPlayStateEvent = procedure(Sender: TObject; const AState: TPlayState) of object;
  TPositionEvent = procedure(Sender: TObject; const APTS: Int64) of object;

  // custom player
  TCustomPlayer = class(TComponent)
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

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

    // open the media file to play, render on the custom window specified by handle
    function Open(const AFileName: WideString; const AScreenHandle: {$IFDEF BCB}Pointer{$ELSE}HWND{$ENDIF}): Boolean;
    procedure Stop(const AWaitForStop: Boolean = False);
    procedure Pause;
    procedure Resume;
    procedure TogglePause;
    procedure ToggleAudioDisplay;
    procedure StepToNextFrame;
    // do seek by timestamp, microseconds
    procedure Seek(const APTS: Int64); overload;
    // do seek by relative value (backward/forward), seconds
    procedure Seek(const ADelta: Double); overload;
    function CurrentFrame: TBitmap; overload;
    function CurrentFrame(var APTS: Int64): TBitmap; overload;

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

    // disable audio
    property DisableAudio: Boolean read Faudio_disable write Faudio_disable;
    // disable video
    property DisableVideo: Boolean read Fvideo_disable write Fvideo_disable;
    // disable graphical display
    property DisableDisplay: Boolean read Fdisplay_disable write Fdisplay_disable;
    // force format
    property Format: string read GetFormat write SetFormat;
    // frame width
    property FrameWidth: Integer read Fframe_width write Fframe_width;
    // frame height
    property FrameHeight: Integer read Fframe_height write Fframe_height;
    // force displayed width
    property ScreenWidth: Integer read Fscreen_width write Fscreen_width;
    // force displayed height
    property ScreenHeight: Integer read Fscreen_height write Fscreen_height;

    property FileName: WideString read Finput_filename;
    property LastErrMsg: string read FLastErrMsg;
    property ScreenHandle: {$IFDEF BCB}Pointer{$ELSE}HWND{$ENDIF} read FScreenHandle;
    property FullScreen: Boolean read Fis_full_screen;

    property AudioStreamIndex: Integer read GetAudioStream write SetAudioStream;
    property VideoStreamIndex: Integer read GetVideoStream write SetVideoStream;
    property SubtitleStreamIndex: Integer read GetSubtitleStream write SetSubtitleStream;

    property AVProbe: TAVProbe read FAVProbe;

    // AspectRatio: = 0 means keeping original, < 0 means scaling to fit, > 0 means customization
    property AspectRatio: Single read FAspectRatio write SetAspectRatio;
    property AudioDriver: TAudioDriver read FAudioDriver write FAudioDriver;
    // AudioVolume: 0-128, 128 means keeping original
    property AudioVolume: TAudioVolume read FAudioVolume write FAudioVolume;
    property Mute: Boolean read FMute write FMute;
    property CurrentPTS: Int64 read FCurrentPTS;
    property Hook: Boolean read FHook write FHook;
    property PlayTime: Int64 read FPlayTime write FPlayTime;
    // repeat type on reach of PlayTime
    property RepeatType: TRepeatType read FRepeatType write FRepeatType;
    property SeekFlags: Integer read FSeekFlags write FSeekFlags;
    // seek backward
    property SeekBackware: Boolean index AVSEEK_FLAG_BACKWARD read GetSeekFlag write SetSeekFlag;
    // seeking based on position in bytes
    property SeekByByte: Boolean index AVSEEK_FLAG_BYTE read GetSeekFlag write SetSeekFlag;
    // seek to any frame, even non key-frames
    property SeekToAny: Boolean index AVSEEK_FLAG_ANY read GetSeekFlag write SetSeekFlag;
    // seeking based on frame number
    property SeekByFrame: Boolean index AVSEEK_FLAG_FRAME read GetSeekFlag write SetSeekFlag;
    property TriggerEventInMainThread: Boolean read FTriggerEventInMainThread
      write FTriggerEventInMainThread;
    property VerticalFlip: Boolean read FVerticalFlip write FVerticalFlip;
    property VideoDriver: TVideoDriver read FVideoDriver write FVideoDriver;

    // force full screen
    property is_full_screen: Boolean read Fis_full_screen write Fis_full_screen;
    // select desired audio stream
    property wanted_audio_stream: Integer read Fwanted_audio_stream write Fwanted_audio_stream;
    // select desired video stream
    property wanted_video_stream: Integer read Fwanted_video_stream write Fwanted_video_stream;
    // select desired subtitle stream
    property wanted_subtitle_stream: Integer read Fwanted_subtitle_stream write Fwanted_subtitle_stream;
    // seek to a given position in microseconds
    property start_time: Int64 read Fstart_time write Fstart_time;
    // set pixel format
    property frame_pix_fmt: TAVPixelFormat read Fframe_pix_fmt write Fframe_pix_fmt;
    property workaround_bugs: Integer read Fworkaround_bugs write Fworkaround_bugs;
    // visualize motion vectors
    property debug_mv: Integer read Fdebug_mv write Fdebug_mv;
    // non spec compliant optimizations
    property fast: Boolean read Ffast write Ffast;
    // generate pts
    property genpts: Boolean read Fgenpts write Fgenpts;
    // let decoder reorder pts
    property decoder_reorder_pts: Boolean read Fdecoder_reorder_pts write Fdecoder_reorder_pts;
    property lowres: Integer read Flowres write Flowres;
    property skip_loop_filter: TAVDiscard read Fskip_loop_filter write Fskip_loop_filter;
    property skip_frame: TAVDiscard read Fskip_frame write Fskip_frame;
    property skip_idct: TAVDiscard read Fskip_idct write Fskip_idct;
    property idct_algo: Integer read Fidct_algo write Fidct_algo;
    // set error detection threshold (0-4)
    property error_recognition: Integer read Ferror_recognition write Ferror_recognition;
    // set error concealment options (bit_mask)
    property error_concealment: Integer read Ferror_concealment write Ferror_concealment;
    // set audio-video sync. type (type=audio/video/ext)
    property av_sync_type: Tav_sync_type read Fav_sync_type write Fav_sync_type;
  published
    property About: string read FAbout write FAbout;
    property Version: string read GetVersion;
    property OnFileOpen: TFileOpenEvent read FOnFileOpen write FOnFileOpen;
    property OnHook: THookEvent read FOnHook write FOnHook;
    property OnPosition: TPositionEvent read FOnPosition write FOnPosition;
    property OnState: TPlayStateEvent read FOnState write FOnState;
  end;

  TFFPlayer = class(TCustomPlayer)
  published
    property AspectRatio;
    property AudioVolume default SDL_MIX_MAXVOLUME;
    property DisableAudio default False;
    property DisableVideo default False;
    property DisableDisplay default False;
    property Mute default False;
    property FrameWidth default 0;
    property FrameHeight default 0;
    property Hook default False;
    property ScreenWidth default 0;
    property ScreenHeight default 0;
    property SeekBackware default False;
    property SeekByByte default False;
    property SeekToAny default False;
    property SeekByFrame default False;
    property TriggerEventInMainThread default True;
  end;

// return desktop handle
function GetDesktopHandle: {$IFDEF BCB}Pointer{$ELSE}HWND{$ENDIF};

implementation

// return desktop handle
{$IFDEF BCB}
function GetDesktopHandle: Pointer;
var
  H: HWND;
begin
  H := FindWindow('ProgMan', nil);
  H := GetWindow(H, GW_CHILD);
  H := GetWindow(H, GW_CHILD);
  Result := Pointer(H);
end;
{$ELSE}
function GetDesktopHandle: HWND;
begin
  Result := FindWindow('ProgMan', nil);
  Result := GetWindow(Result, GW_CHILD);
  Result := GetWindow(Result, GW_CHILD);
end;
{$ENDIF}