type
xvid_enc_stats_t = packed record
version: Integer; // encoding parameters
frame_type: Integer; // [out] coding type
quant: Integer; // [out] frame quantizer
vol_flags: Integer; // [out] vol flags (see above)
vop_flags: Integer; // [out] vop flags (see above)
// bitrate
length: Integer; // [out] frame length
hlength: Integer; // [out] header length (bytes)
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 as 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;
//****************************************************************************
{-xvid plugin system -- internals }
{-xvidcore will call XVID_PLG_INFO and XVID_PLG_CREATE during XVID_ENC_CREATE }
{-before encoding each frame xvidcore will call XVID_PLG_BEFORE }
{-after encoding each frame xvidcore will call XVID_PLG_AFTER }
{-xvidcore will call XVID_PLG_DESTROY during XVID_ENC_DESTROY }
//****************************************************************************
// 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*/ }
//****************************************************************************
{-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: }
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;
// xvid_image_t
type
xvid_image_t = packed record
csp: Integer; // [in] colorspace; or with XVID_CSP_VFLIP to perform vertical flip
plane: array[0..3] of Pointer; // [in] image plane ptrs
stride: array[0..3] of Integer; // [in] image stride; "bytes per row"
end;
// XVID_GBL_INIT param1
type
xvid_gbl_init_t = packed record
version: Integer;
cpu_flags: Word; // [in:opt] zero = autodetect cpu; XVID_CPU_FORCE or {cpu features} = force cpu features
debug: Integer; // [in:opt] debug level
end;
// XVID_GBL_INFO param1
xvid_gbl_info_t = packed record
version: Integer;
actual_version: Integer; // [out] returns the actual xvidcore version
build: Pchar; // [out] if !null, points to description of this xvid core build
cpu_flags: Word; // [out] detected cpu features
num_threads: Integer; // [out] detected number of cpus/threads
end;
const
XVID_GBL_INIT = 0; // initialize xvidcore; must be called before using xvid_decore, or xvid_encore)
XVID_GBL_INFO = 1; // return some info about xvidcore, and the host computer
XVID_GBL_CONVERT = 2; // colorspace conversion utility
//****************************************************************************
// xvid_decore()
//****************************************************************************
const
XVID_DEC_CREATE = 0; // create decore instance; return 0 on success
XVID_DEC_DESTROY = 1; // destroy decore instance: return 0 on success
XVID_DEC_DECODE = 2; // decode a frame: returns number of bytes consumed >= 0
{type
xvid_decore = function(handle: Pointer;
opt: Integer;
param1: Pointer;
param2: Pointer): Integer; cdecl;
}
// XVID_DEC_CREATE param 1
//-image width and height may be specified here when the dimensions are
//known in advance.
vol_t = record // XVID_TYPE_VOL
general: Integer; // [out] flags
width: Integer; // [out] width
height: Integer; // [out] height
par: Integer; // [out] pixel aspect ratio (refer to XVID_PAR_xxx above)
par_width: Integer; // [out] aspect ratio width [1..255]
par_height: Integer; // [out] aspect ratio height [1..255]
end;
xvid_dec_stats_t = packed record
version: integer;
frametype: integer; // [out] output data type */
vop: vop_t;
vol: vol_t;
end;
const
XVID_ZONE_QUANT = (1 shl 0);
XVID_ZONE_WEIGHT = (1 shl 1);
type
Pxvid_enc_zone_t = ^xvid_enc_zone_t;
xvid_enc_zone_t = packed record
frame: Integer;
mode: Integer;
increment: Integer;
base: Integer;
end;
//----------------------------------------------------------------------------
// xvid_enc_stats_t structure
//
// Used in:
// - xvid_plg_data_t structure
// - optional parameter in xvid_encore() function
//
// .coding_type = XVID_TYPE_NOTHING if the stats are not given
//----------------------------------------------------------------------------
procedure TVideoForm.FormCreate(Sender: TObject);
var
i: integer;
Device: TMenuItem;
begin
xvid_Version :=XVID_MAKE_VERSION(1,1,0);
SysDev:= TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
if SysDev.CountFilters > 0 then
for i := 0 to SysDev.CountFilters - 1 do
begin
Device := TMenuItem.Create(Devices);
Device.Caption := SysDev.Filters[i].FriendlyName;
Device.Tag := i;
Device.OnClick := OnSelectDevice;
Devices.Add(Device);
end;
end;
procedure TVideoForm.OnSelectDevice(sender: TObject);
begin
Self.DoubleBuffered := True;
FilterGraph.ClearGraph;
FilterGraph.Active := false;
Filter.BaseFilter.Moniker := SysDev.GetMoniker(TMenuItem(Sender).tag);
FilterGraph.Active := true;
with FilterGraph as ICaptureGraphBuilder2 do
begin
RenderStream(@PIN_CATEGORY_PREVIEW, nil, Filter as IBaseFilter, SampleGrabber as IBaseFilter, VideoWindow as IbaseFilter);
end;
try
//XVID库初始化操作
xvid_gbl.version := xvid_Version; //Version:1.1.0
xvid_gbl.cpu_flags := Word(XVID_CPU_FORCE or XVID_CPU_ASM);//0:自动检查CPU,XVID_CPU_FORCE or XVID_CPU_ASM:强制使用ASM汇编优化
xvid_gbl.debug := 0; //调试级别