CnPack Forum


 
Subject: delphi调用directvobsub
bahamut8348
灌水司司长
Rank: 6Rank: 6


UID 4743
Digest Posts 14
Credits 337
Posts 79
点点分 337
Reading Access 10
Registered 2007-1-18
Status Offline
Post at 2012-2-11 09:54  Profile | Blog | P.M. 
delphi调用directvobsub

之前在网上搜过很久没有找到。下面是花了俩晚上翻译出来的:
    ps: directvobsub是mpc里的一个基于dshow的字幕插件,文件名为vsfilter.dll

// 接口定义:
const
  CLSID_IDirectVobSub:       TGUID = '{9852A670-F845-491B-9BE6-EBD841B8A613}';
  IID_ISubClock:             TGUID = '{FE6EC6A0-21CA-4970-9EF0-B296F7F38AF0}';
  IID_ISubClock2:            TGUID = '{0665B760-FBC1-46C3-A35F-E471527C96A4}';
  IID_IDirectVobSub:         TGUID = '{EBE1FB08-3957-47CA-AF13-5827E5442E56}';
  IID_IDirectVobSub2:        TGUID = '{AB52FC9C-2415-4DCA-BC1C-8DCC2EAE8150}';

type
  PEPARCompensationType = ^EPARCompensationType;
  EPARCompensationType = (
                EPCTDisabled = 0,
                EPCTDownscale = 1,
                EPCTUpscale = 2,
                EPCTAccurateSize = 3
        );

type
  ISubClock = interface(IUnknown)
  ['{FE6EC6A0-21CA-4970-9EF0-B296F7F38AF0}']
    function SetTime(rt: REFERENCE_TIME): HRESULT; stdcall;
    function GetTime(): REFERENCE_TIME; stdcall;
  end;

type
  ISubClock2 = interface(ISubClock)
  ['{0665B760-FBC1-46C3-A35F-E471527C96A4}']
    function SetAvgTimePerFrame(rt: REFERENCE_TIME): HRESULT; stdcall;
    function GetAvgTimePerFrame(out prt: REFERENCE_TIME): HRESULT; stdcall;
      // return S_OK only if *prt was set and is valid
  end;

type
  IDirectVobSub = interface(IUnknown)
  ['{EBE1FB08-3957-47ca-AF13-5827E5442E56}']
    function get_FileName(lpFileName: PWideChar): HRESULT; stdcall;
      // fn should point to a buffer allocated to at least the length of MAX_PATH (=260)
    function put_FileName(lpFileName: PWideChar): HRESULT; stdcall;
    function get_LanguageCount(out nLangs: Integer): HRESULT; stdcall;
    function get_LanguageName(iLanguage: Integer; out lpName: PWideChar): HRESULT; stdcall;
      // the returned *lpName is allocated with CoTaskMemAlloc
    function get_SelectedLanguage(out iSelected: Integer): HRESULT; stdcall;
    function put_SelectedLanguage(iSelected: Integer): HRESULT; stdcall;
    function get_HideSubtitles(out fHideSubtitles: BOOL): HRESULT; stdcall;
    function put_HideSubtitles(fHideSubtitles: BOOL): HRESULT; stdcall;
    function get_PreBuffering(out fDoPreBuffering: BOOL): HRESULT; stdcall;
    function put_PreBuffering(fDoPreBuffering: BOOL): HRESULT; stdcall;
    function get_Placement(out fOverridePlacement: BOOL; out xPerc, yPerc: Integer): HRESULT; stdcall;
    function put_Placement(fOverridePlacement: BOOL; xPerc, yPerc: Integer): HRESULT; stdcall;
    function get_VobSubSettings(out fBuffer, fOnlyShowForcedSubs, fPolygonize: BOOL): HRESULT; stdcall;
    function put_VobSubSettings(fBuffer, fOnlyShowForcedSubs, fPolygonize: BOOL): HRESULT; stdcall;
    function get_TextSettings(out lf; lflen: Integer; // depending on lflen, lf must point to LOGFONTA or LOGFONTW
      out color: COLORREF; out fShadow, fOutline, fAdvancedRenderer: BOOL): HRESULT; stdcall;
    function put_TextSettings(const lf; lflen: Integer;
      color: COLORREF; fShadow, fOutline, fAdvancedRenderer: BOOL): HRESULT; stdcall;
    function get_Flip(out fPicture, fSubtitles: BOOL): HRESULT; stdcall;
    function put_Flip(fPicture, fSubtitles: BOOL): HRESULT; stdcall;
    function get_OSD(out fOSD: BOOL): HRESULT; stdcall;
    function put_OSD(fOSD: BOOL): HRESULT; stdcall;
    function get_SaveFullPath(out fSaveFullPath: BOOL): HRESULT; stdcall;
    function put_SaveFullPath(fSaveFullPath: BOOL): HRESULT; stdcall;
    function get_SubtitleTiming(out delay, speedmul, speeddiv: Integer): HRESULT; stdcall;
    function put_SubtitleTiming(delay, speedmul, speeddiv: Integer): HRESULT; stdcall;
    function get_MediaFPS(out fEnabled: BOOL; out fps: Double): HRESULT; stdcall;
    function put_MediaFPS(fEnabled: BOOL; fps: Double): HRESULT; stdcall;
    // no longer supported
    function get_ColorFormat(out iPosition: Integer): HRESULT; stdcall;
    function put_ColorFormat(iPosition: Integer): HRESULT; stdcall;
    function get_ZoomRect(rect: PNormalizedRect): HRESULT; stdcall;
    function put_ZoomRect(rect: PNormalizedRect): HRESULT; stdcall;
    //
    function UpdateRegistry(): HRESULT; stdcall;
    //
    function HasConfigDialog(iSelected: Integer): HRESULT; stdcall;
    function ShowConfigDialog(iSelected: Integer; hWndParent: HWND): HRESULT; stdcall;
      // if available, this will popup a child dialog allowing the user to edit the style options
    //
    function IsSubtitleReloaderLocked(out fLocked: BOOL): HRESULT; stdcall;
    function LockSubtitleReloader(fLock: BOOL): HRESULT; stdcall;
    function get_SubtitleReloader(out fDisabled: BOOL): HRESULT; stdcall;
    function put_SubtitleReloader(fDisable: BOOL): HRESULT; stdcall;
    //
    function get_ExtendPicture(out
      horizontal, // 0 - disabled, 1 - mod32 extension (width = (width+31)&~31)
      vertical, // 0 - disabled, 1 - 16:9, 2 - 4:3, 0x80 - crop (use crop together with 16:9 or 4:3, eg 0x81 will crop to 16:9 if the picture was taller)
      resx2, // 0 - disabled, 1 - enabled, 2 - depends on the original resolution
      resx2minw, // resolution doubler will be used if width*height <= resx2minw*resx2minh (resx2minw*resx2minh equals to 384*288 by default)
      resx2minh: Integer): HRESULT; stdcall;
    function put_ExtendPicture(horizontal, vertical, resx2, resx2minw, resx2minh: Integer): HRESULT; stdcall;

    function get_LoadSettings(out level: Integer; // 0 - when needed, 1 - always, 2 - disabled
      out fExternalLoad, fWebLoad, fEmbeddedLoad: BOOL): HRESULT; stdcall;
    function put_LoadSettings(level: Integer; // 0 - when needed, 1 - always, 2 - disabled
      fExternalLoad, fWebLoad, fEmbeddedLoad: BOOL): HRESULT; stdcall;

    function get_SubPictToBuffer(out uSubPictToBuffer: UINT): HRESULT; stdcall;
    function put_SubPictToBuffer(uSubPictToBuffer: UINT): HRESULT; stdcall;

    function get_AnimWhenBuffering(out fAnimWhenBuffering: BOOL): HRESULT; stdcall;
    function put_AnimWhenBuffering(fAnimWhenBuffering: BOOL): HRESULT; stdcall;
  end;

type
  IDirectVobSub2 = interface(IDirectVobSub)
  ['{AB52FC9C-2415-4dca-BC1C-8DCC2EAE8150}']
    function AdviseSubClock(pSubClock: ISubClock): HRESULT; stdcall;
    function get_Forced(): BOOL; stdcall;
    function put_Forced(fForced: BOOL): HRESULT; stdcall;
    function get_TextSettings(pDefStyle: Pointer): HRESULT; stdcall;
    function put_TextSettings(pDefStyle: Pointer): HRESULT; stdcall;
    function get_AspectRatioSettings(ePARCompensationType: Pointer): HRESULT; stdcall;
    function put_AspectRatioSettings(ePARCompensationType: Pointer): HRESULT; stdcall;
  end;

IDirectVobSub2的后俩属性无法在delphi中使用,因为textsettings的参数类型为是c++中的类




调用:

var
  lpVobSub: IDirectVobSub;
  nCount, nSelected: Integer;
  lpLanguageName: PWideChar;
  lpBaseFilter: IBaseFilter;
begin
  if Failed(CoCreateInstance(CLSID_IDirectVobSub, nil, CLSCTX_INPROC_SERVER, IDirectVobSub, lpVobSub)) then
      Exit; // 创建接口对象(需注册VSFilter.dll)

  lpVobSub.QueryInterface(IBaseFilter, lpBaseFilter);
  lpGraphBuilder.AddFilter(lpBaseFilter, '...'); // 添加filter

  lpVobSub.put_FileName('...'); // 指定字幕文件名
  lpVobSub.get_LanguageCount(nCount); // 获取字幕文件总数
  lpVobSub.get_SelectedLanguage(nSelected); // 获取选中的字幕序号
  lpVobSub.get_LanguageName(nSelected, lpLanguageName); // 获取指定序号的字幕名

  CoTaskMemFree(lpLanguageName);
  lpVobSub:= nil;
end;





做人要厚道,看帖要回贴
Top
 




All times are GMT++8, the time now is 2021-4-23 17:09

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.010841 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP