⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib_xvid.~pas

📁 xvid库调用来压缩视频编码实例
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
    // Deprecated, use the stats field instead. }
    // Will disapear before 1.0 }
    length: Integer; // [out] after: length of encoded frame
    kblks: Integer; // [out] number of blocks compressed as Intra
    mblks: Integer; // [out] number of blocks compressed as Inter
    ublks: Integer; // [out] number of blocks marked not_coded
    sse_y: Integer; // [out] Y plane's sse
    sse_u: Integer; // [out] U plane's sse
    sse_v: Integer; // [out] V plane's sse
    // End of duplicated data, kept only for binary compatibility*/ }

    bquant_ratio: Integer; // [in]
    bquant_offset: Integer; // [in]

    stats: XVID_ENC_STATS_T; // [out] frame statistics
  end;

  //****************************************************************************
  {-xvid plugin system -- external }

  {-the application passes xvid an array of "xvid_plugin_t" at XVID_ENC_CREATE. the array }
  {-indicates the plugin function pointer and plugin-specific data. }
  {-xvidcore handles the rest. example: }

  {-xvid_enc_create_t create; }
  {-xvid_enc_plugin_t plugins[2]; }

  {-plugins[0].func = xvid_psnr_func; }
  {-plugins[0].param = NULL; }
  {-plugins[1].func = xvid_cbr_func; }
  {-plugins[1].param =  and cbr_data; }

  {-create.num_plugins = 2; }
  {-create.plugins = plugins; }

  //****************************************************************************

type
  XVID_PLUGIN_FUNC = function(HANDLE: pointer; OPT: Integer; PARAM1, PARAM2: Pointer): Integer;

  Pxvid_enc_plugin_t = ^xvid_enc_plugin_t;
  xvid_enc_plugin_t = packed record
    func: XVID_PLUGIN_FUNC;
    param: Pointer;
  end;

  { single-pass rate control }
  { two-pass rate control: first pass }
  { two-pass rate control: second pass }

  { lumimasking }

  { write psnr values to stdout }
  { dump before and after yuvpgms }

  { single pass rate control }
  { CBR and Constant quantizer modes }
type
  xvid_plugin_single_t = packed record
    version: Integer;
    bitrate: Integer; // [in] bits per second
    reaction_delay_factor: Integer; // [in]
    averaging_period: Integer; // [in]
    buffer: Integer; // [in]
  end;

  xvid_plugin_2pass1_t = packed record
    version: Integer;
    filename: PChar;
  end;

const
  XVID_PAYBACK_BIAS = 0; // payback with bias
  XVID_PAYBACK_PROP = 1; // payback proportionally

type
  xvid_plugin_2pass2_t = packed record
    version: Integer;
    bitrate: Integer; // [in] bits per second
    filename: PChar; // [in] first pass stats filename

    keyframe_boost: Integer; // [in] keyframe boost percentage: [0..100]
    curve_compression_high: Integer; // [in] percentage of compression performed on the high part of the curve (above average) }
    curve_compression_low: Integer; // [in] percentage of compression performed on the low part of the curve (below average) }
    overflow_control_strength: Integer; // [in] Payback delay expressed in number of frames }
    max_overflow_improvement: Integer; // [in] percentage of allowed range for a frame that gets bigger because of overflow bonus }
    max_overflow_degradation: Integer; // [in] percentage of allowed range for a frame that gets smaller because of overflow penalty }

    kfreduction: Integer; // [in] maximum bitrate reduction applied to an iframe under the kfthreshold distance limit }
    kfthreshold: Integer; // [in] if an iframe is closer to the next iframe than this distance, a quantity of bits }
    // is substracted from its bit allocation. The reduction is computed as multiples of
    // kfreduction/kthreshold. It reaches kfreduction when the distance == kfthreshold,
    // 0 for 1<distance<kfthreshold }

    container_frame_overhead: Integer; // [in] How many bytes the controller has to compensate per frame due to container format overhead }
  end;

  //****************************************************************************
  // ENCODER API
  //****************************************************************************

  //----------------------------------------------------------------------------
  // Encoder operations
  //----------------------------------------------------------------------------
const
  XVID_ENC_CREATE = 0; // create encoder instance; returns 0 on success
  XVID_ENC_DESTROY = 1; // destroy encoder instance; returns 0 on success
  XVID_ENC_ENCODE = 2; //* encode a frame: returns number of ouput bytes
  // * 0 means this frame should not be written (ie. encoder lag)
//----------------------------------------------------------------------------
// Encoder entry point
//----------------------------------------------------------------------------
{type

  xvid_encore = function(handle: Pointer;
    opt: Integer;
    param1: Pointer;
    param2: Pointer): Integer; cdecl;
}
  // Quick API reference
  //
  // XVID_ENC_CREATE operation
  // - handle: ignored
  // - opt: XVID_ENC_CREATE
  // - param1: address of a xvid_enc_create_t structure
  // - param2: ignored
  //
  // XVID_ENC_ENCODE operation
  // - handle: an instance returned by a CREATE op
  // - opt: XVID_ENC_ENCODE
  // - param1: address of a xvid_enc_frame_t structure
  // - param2: address of a xvid_enc_stats_t structure (optional)
  // its return value is asynchronous to what is written to the buffer
  // depending on the delay introduced by bvop use. It's display
  // ordered.
  //
  // XVID_ENC_DESTROY operation
  // - handle: an instance returned by a CREATE op
  // - opt: XVID_ENC_DESTROY
  // - param1: ignored
  // - param2: ignored

  //----------------------------------------------------------------------------
  // "Global" flags
  //
  // These flags are used for xvid_enc_create_t->global field during instance
  // creation (operation XVID_ENC_CREATE)
  //----------------------------------------------------------------------------

const
  XVID_GLOBAL_PACKED = (1 shl 0); // packed bitstream
  XVID_GLOBAL_CLOSED_GOP = (1 shl 1); // closed_gop: was DX50BVOP dx50 bvop compatibility
  XVID_GLOBAL_EXTRASTATS_ENABLE = (1 shl 2);
{$IFDEF 0}
  XVID_GLOBAL_VOL_AT_IVOP = (1 shl 3); // write vol at every ivop: WIN32/divx compatibility
  XVID_GLOBAL_FORCE_VOL = (1 shl 4); // when vol-based parameters are changed, insert an ivop NOT recommended
{$ENDIF}

  //----------------------------------------------------------------------------
  // "VOL" flags
  //
  // These flags are used for xvid_enc_frame_t->vol_flags field during frame
  // encoding (operation XVID_ENC_ENCODE)
  //----------------------------------------------------------------------------

const
  XVID_VOL_MPEGQUANT = (1 shl 0); // enable MPEG type quantization
  XVID_VOL_EXTRASTATS = (1 shl 1); // enable plane sse stats
  XVID_VOL_QUARTERPEL = (1 shl 2); // enable quarterpel: frames will encoded as quarterpel
  XVID_VOL_GMC = (1 shl 3); // enable GMC; frames will be checked for gmc suitability
  XVID_VOL_REDUCED_ENABLE = (1 shl 4); // enable reduced resolution vops: frames will be checked for rrv suitability
  XVID_VOL_INTERLACING = (1 shl 5); // enable interlaced encoding

  //----------------------------------------------------------------------------
  // "VOP" flags
  //
  // These flags are used for xvid_enc_frame_t->vop_flags field during frame
  // encoding (operation XVID_ENC_ENCODE)
  //----------------------------------------------------------------------------

  // Always valid
const
  XVID_VOP_DEBUG = (1 shl 0); // print debug messages in frames
  XVID_VOP_HALFPEL = (1 shl 1); // use halfpel interpolation
  XVID_VOP_INTER4V = (1 shl 2); // use 4 motion vectors per MB
  XVID_VOP_TRELLISQUANT = (1 shl 3); // use trellis based R-D 'optimal' quantization
  XVID_VOP_CHROMAOPT = (1 shl 4); // enable chroma optimization pre-filter
  XVID_VOP_CARTOON = (1 shl 5); // use 'cartoon mode'
  XVID_VOP_GREYSCALE = (1 shl 6); // enable greyscale only mode (even for color input material chroma is ignored)
  XVID_VOP_HQACPRED = (1 shl 7); // high quality ac prediction
  XVID_VOP_MODEDECISION_RD = (1 shl 8); // enable DCT-ME and use it for mode decision
  XVID_VOP_FAST_MODEDECISION_RD = (1 shl 12); // use simplified R-D mode decision

  // Only valid for vol_flags or =XVID_VOL_INTERLACING
const
  XVID_VOP_TOPFIELDFIRST = (1 shl 9); // set top-field-first flag
  XVID_VOP_ALTERNATESCAN = (1 shl 10); // set alternate vertical scan flag

  // only valid for vol_flags or =XVID_VOL_REDUCED_ENABLED
  XVID_VOP_REDUCED = (1 shl 11); // reduced resolution vop

  //----------------------------------------------------------------------------
  // "Motion" flags
  //
  // These flags are used for xvid_enc_frame_t->motion field during frame
  // encoding (operation XVID_ENC_ENCODE)
  //----------------------------------------------------------------------------

  // Motion Estimation Search Patterns
const
  XVID_ME_ADVANCEDDIAMOND16 = (1 shl 0); // use advdiamonds instead of diamonds as search pattern
  XVID_ME_ADVANCEDDIAMOND8 = (1 shl 1); // use advdiamond for XVID_ME_EXTSEARCH8
  XVID_ME_USESQUARES16 = (1 shl 2); // use squares instead of diamonds as search pattern
  XVID_ME_USESQUARES8 = (1 shl 3); // use square for XVID_ME_EXTSEARCH8

  // SAD operator based flags
  XVID_ME_HALFPELREFINE16 = (1 shl 4);
  XVID_ME_HALFPELREFINE8 = (1 shl 6);
  XVID_ME_QUARTERPELREFINE16 = (1 shl 7);
  XVID_ME_QUARTERPELREFINE8 = (1 shl 8);
  XVID_ME_GME_REFINE = (1 shl 9);
  XVID_ME_EXTSEARCH16 = (1 shl 10); // extend PMV by more searches
  XVID_ME_EXTSEARCH8 = (1 shl 11); // use diamond/square for extended 8x8 search
  XVID_ME_CHROMA_PVOP = (1 shl 12); // also use chroma for P_VOP/S_VOP ME
  XVID_ME_CHROMA_BVOP = (1 shl 13); // also use chroma for B_VOP ME
  XVID_ME_FASTREFINE16 = (1 shl 25); // use low-complexity refinement functions
  XVID_ME_FASTREFINE8 = (1 shl 29); // low-complexity 8x8 sub-block refinement

  // Rate Distortion based flags
  // Valid when XVID_VOP_MODEDECISION_RD is enabled
  XVID_ME_HALFPELREFINE16_RD = (1 shl 14); // perform RD-based halfpel refinement
  XVID_ME_HALFPELREFINE8_RD = (1 shl 15); // perform RD-based halfpel refinement for 8x8 mode
  XVID_ME_QUARTERPELREFINE16_RD = (1 shl 16); // perform RD-based qpel refinement
  XVID_ME_QUARTERPELREFINE8_RD = (1 shl 17); // perform RD-based qpel refinement for 8x8 mode
  XVID_ME_EXTSEARCH_RD = (1 shl 18); // perform RD-based search using square pattern enable XVID_ME_EXTSEARCH8 to do this in 8x8 search as well
  XVID_ME_CHECKPREDICTION_RD = (1 shl 19); // always check vector equal to prediction

  // Other
  XVID_ME_DETECT_STATIC_MOTION = (1 shl 24); // speed-up ME by detecting stationary scenes
  XVID_ME_SKIP_DELTASEARCH = (1 shl 26); // speed-up by skipping b-frame delta search
  XVID_ME_FAST_MODEINTERPOLATE = (1 shl 27); // speed-up by partly skipping interpolate mode
  XVID_ME_BFRAME_EARLYSTOP = (1 shl 28); // speed-up by early exiting b-search

  // Unused
  XVID_ME_UNRESTRICTED16 = (1 shl 20); // unrestricted ME, not implemented
  XVID_ME_OVERLAPPING16 = (1 shl 21); // overlapping ME, not implemented
  XVID_ME_UNRESTRICTED8 = (1 shl 22); // unrestricted ME, not implemented
  XVID_ME_OVERLAPPING8 = (1 shl 23); // overlapping ME, not implemented

  //----------------------------------------------------------------------------
  // xvid_enc_create_t structure definition
  //
  // This structure is passed as param1 during an instance creation (operation
  // XVID_ENC_CREATE)
  //----------------------------------------------------------------------------

type
  xvid_enc_create_t = packed record
    version: Integer;
    profile: Integer; // [in] profile@level; refer to XVID_PROFILE_xxx
    width: Integer; // [in] frame dimensions; width, pixel units
    height: Integer; // [in] frame dimensions; height, pixel units

    num_zones: Integer; // [in:opt] number of bitrate zones
    zones: PXVID_ENC_ZONE_T; // ^^ zone array

    num_plugins: Integer; // [in:opt] number of plugins
    plugins: PXVID_ENC_PLUGIN_T; // ^^ plugin array

    num_threads: Integer; // [in:opt] number of threads
    max_bframes: Integer; // [in:opt] max sequential bframes (0=disable bframes)

    global: Integer; // [in:opt] global flags; controls encoding behavior
    // --- vol-based stuff; included here for convenience
    fincr: Integer; // [in:opt] framerate increment; set to zero for variable framerate
    fbase: Integer; // [in] framerate base frame_duration = fincr/fbase seconds
    // ----------------------------------------------
    // --- vop-based; included here for convenience
    max_key_interval: Integer; // [in:opt] the maximum interval between key frames

    frame_drop_ratio: Integer; // [in:opt] frame dropping: 0=drop none... 100=drop all

    bquant_ratio: Integer; // [in:opt] bframe quantizer multipier/offeset; used to decide bframes quant when bquant==-1
    bquant_offset: Integer; // bquant = (avg(past_ref_quant,future_ref_quant)*bquant_ratio + bquant_offset) / 100

    min_quant: array[0..3 - 1] of Integer; // [in:opt]
    max_quant: array[0..3 - 1] of Integer; // [in:opt]
    // ----------------------------------------------

    handle: Pointer; // [out] encoder instance handle
  end;

  //----------------------------------------------------------------------------
  // xvid_enc_frame_t structure definition
  //
  // This structure is passed as param1 during a frame encoding (operation
  // XVID_ENC_ENCODE)
  //----------------------------------------------------------------------------

  // out value for the frame structure->type field
  // unlike stats output in param2, this field is not asynchronous and tells
  // the client app, if the frame written into the stream buffer is an ivop
  // usually used for indexing purpose in the container
const
  XVID_KEYFRAME = (1 shl 1);

  // The structure
type
  xvid_enc_frame_t = packed record
    version: Integer;
    // VOL related stuff
    // unless XVID_FORCEVOL is set, the encoder will not react to any changes
    // here until the next VOL (keyframe).

    vol_flags: Integer; // [in] vol flags
    quant_intra_matrix: PByte; // [in:opt] custom intra qmatrix
    quant_inter_matrix: PByte; // [in:opt] custom inter qmatrix

    par: Integer; // [in:opt] pixel aspect ratio (refer to XVID_PAR_xxx above)
    par_width: Integer; // [in:opt] aspect ratio width
    par_height: Integer; // [in:opt] aspect ratio height

    // Other fields that can change on a frame base
    fincr: Integer; // [in:opt] framerate increment, for variable framerate only
    vop_flags: Integer; // [in] (general)vop-based flags
    motion: Integer; // [in] ME options

    input: XVID_IMAGE_T; // [in] input image (read from)

    coding_type: Integer; // [in:opt] coding type
    quant: Integer; // [in] frame quantizer; if <=0, automatic (ratecontrol)
    bframe_threshold: Integer;
    bitstream: Pointer; // [in:opt] bitstream ptr (written to)
    length: Integer; // [in:opt] bitstream length (bytes)

    out_flags: Integer; // [out] bitstream output flags
  end;

const
  XviDCoreDll = 'xvidcore.dll';

type

  TxvidInitException = class(Exception)
  end;

  TxvidEncodeException = class(Exception)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -