📄 anyqv.pas
字号:
// 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)
_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;
//****************************************************************************
// versioning
//****************************************************************************
function XVID_MAKE_VERSION(a,b,c: Integer): Integer;
function XVID_VERSION_MAJOR(a: Integer): Byte;
function XVID_VERSION_MINOR(a: Integer): Byte;
function XVID_VERSION_PATCH(a: Integer): Byte;
function XVID_MAKE_API(a,b: Integer): Integer;
function XVID_API_MAJOR(a: Integer): Integer;
function XVID_API_MINOR(a: Integer): Integer;
var
XVID_VERSION : integer;
XVID_API : Integer;
CodeInited: Boolean;
ENCodehandle: Pointer;
DECodehandle: Pointer;
outbuf : array [0..352*288*3-1] of byte; // *
TmpBuf : array [0..352*288*3-1] of byte; // *
DecBuf : array [0..352*288*3-1] of byte; // -
TmpDecBuf : array [0..352*288*3-1] of byte; // -
// rcvbuf : array [0..352*288*3-1] of byte; //
// TestBuf : array [0..352*288*3-1] of byte; //
CurFRAMESize: Integer;
Vencodeproc: xvid_encore;
VDecodeproc: xvid_decore;
function InitCode(width:Integer= 176; height:Integer=144; rate:Integer=15): boolean;
function InitEnCode(width:Integer= 160; height:Integer=120; rate:Integer=15): boolean;
//function InitDeCode(width:Integer= 160; height:Integer=120; rate:Integer=15): boolean;
procedure UninitCode;
implementation
uses SysUtils, math, forms;
const
codedll = 'AnyQv.dll';
var
XvidInited: Boolean;
XvidHandle: THandle;
encparam: xvid_enc_create_t;
decparam: xvid_dec_create_t;
function XVID_MAKE_VERSION(a,b,c: Integer): Integer;
begin
Result := ((a and $ff) shl 16) or ((b and $ff) shl 8) or (c and $ff);
end;
function XVID_VERSION_MAJOR(a: Integer): Byte;
begin
result := (a shr 16) and $ff;
end;
function XVID_VERSION_MINOR(a: Integer): Byte;
begin
result := (a shr 8) and $ff;
end;
function XVID_VERSION_PATCH(a: Integer): Byte;
begin
result := (a shr 0) and $ff;
end;
function XVID_MAKE_API(a,b: Integer): Integer;
begin
result := ((a and $ff) shl 16) or ((b and $ff) shl 0);
end;
function XVID_API_MAJOR(a: Integer): Integer;
begin
result := (a shr 16) and $ff;
end;
function XVID_API_MINOR(a: Integer): Integer;
begin
result := (a shr 0) and $ff;
end;
//function xvid_global; external 'xvidcore.dll' name 'xvid_global';
//function xvid_decore; external 'xvidcore.dll' name 'xvid_decore';
//function xvid_encore; external 'xvidcore.dll' name 'xvid_encore';
function InitCodehandle(width:Integer= 176; height:Integer=144; rate:Integer=15): Boolean;
begin
result := false;
if not XvidInited then exit;
FillMemory(@encparam, sizeof(encparam),0);
encparam.version := XVID_VERSION;
encparam.profile := XVID_PROFILE_ARTS_L1;
encparam.width := width;
encparam.height := height;
encparam.max_key_interval := 300;
if Vencodeproc(nil, XVID_ENC_CREATE, @encparam, nil) <> 0 then exit;
ENCodehandle := encparam.handle;
FillMemory(@decparam, sizeof(decparam),0);
decparam.version := XVID_VERSION;
if Vdecodeproc(nil, XVID_DEC_CREATE, @decparam, nil) <> 0 then
begin
DECodehandle := nil;
exit;
end;
DECodehandle := decparam.handle;
Result := true;
end;
function InitCode(width:Integer= 176; height:Integer=144; rate:Integer=15): boolean;
var
xinit: xvid_gbl_init_t;
initproc : xvid_global;
begin
Result := CodeInited;
if Result then
begin
UninitCode;
Result := False;
end;
if XvidHandle <= 0 then
XvidHandle := LoadLibrary(pchar(ExtractFilePath(Application.ExeName)+codedll));
if XvidHandle <= 0 then
exit;
initproc := GetProcAddress(XvidHandle, 'xvid_global');
Vdecodeproc := GetProcAddress(XvidHandle, 'xvid_decore');
Vencodeproc := GetProcAddress(XvidHandle, 'xvid_encore');
xinit.version := XVID_VERSION;
xinit.cpu_flags := 0;
xinit.debug := 0;
XvidInited := initproc(nil, 0, @xinit, nil) = 0;
Result := InitCodehandle(width, height, rate);
if not Result then
UninitCode;
CodeInited := Result;
end;
function InitEnCode(width:Integer= 160; height:Integer=120; rate:Integer=15): boolean;
begin
result := false;
if not XvidInited then exit;
Vencodeproc(ENCodehandle, XVID_ENC_DESTROY, nil, nil);
FillMemory(@encparam, sizeof(encparam),0);
encparam.version := XVID_VERSION;
encparam.profile := XVID_PROFILE_ARTS_L1;
encparam.width := width;
encparam.height := height;
encparam.max_key_interval := 300;
if Vencodeproc(nil, XVID_ENC_CREATE, @encparam, nil) <> 0 then exit;
ENCodehandle := encparam.handle;
Result := true;
end;
procedure UnInitCode;
begin
CodeInited := false;
if assigned(Vencodeproc) and (ENCodehandle<>nil) then
Vencodeproc(ENCodehandle, XVID_ENC_DESTROY, nil, nil);
ENCodehandle := nil;
Vencodeproc := nil;
if assigned(Vdecodeproc) and (DECodehandle<>nil) then
Vdecodeproc(DECodehandle, XVID_DEC_DESTROY, nil, nil);
DECodehandle := nil;
VDecodeproc := nil;
if XvidHandle>0 then
FreeLibrary(XvidHandle);
XvidHandle := 0;
XvidInited := false;
end;
initialization
XVID_VERSION := XVID_MAKE_VERSION(1,0,0);
XVID_API := XVID_MAKE_API(4, 0);
XvidInited := false;
CodeInited := false;
ENCodehandle := nil;
DECodehandle := nil;
Vencodeproc := nil;
VDecodeproc := nil;
CurFRAMESize := -1;
XvidHandle := 0;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -