我写的哪些总是出问题。我的视频采集用的是VFW控件。发送端采集到视频流后用mpeg4进行压缩,然后用udp传给对方,对方接收到视频流后用mpeg4解码,然后进行播放。不过视频传送与播放时间在1小时左右或更长时间就出现内存错误,谁做过这方面的例子把代码贴一下。
VFW控件如果谁没有可以加我[email protected] 我传给你.如果你没有mpeg4的编解码库也可以加我我传给你。

解决方案 »

  1.   

    unit PingV;interface
    uses
      Windows;// Bitstream Version
    const
      XVID_BS_VERSION = 34;//****************************************************************************
    // error codes
    //****************************************************************************// all functions return values <0 indicate error
    const
      XVID_ERR_FAIL = -1; // general fault
      XVID_ERR_MEMORY = -2; // memory allocation error
      XVID_ERR_FORMAT = -3; // file format error
      XVID_ERR_VERSION = -4; // structure version not supported
      XVID_ERR_END = -5; // encoder only; end of stream reached//****************************************************************************
    // xvid_image_t
    //****************************************************************************// colorspace values
    const
      XVID_CSP_PLANAR = (1 shl 0); // 4:2:0 planar (==I420, except for pointers/strides)
      XVID_CSP_USER = XVID_CSP_PLANAR;
      XVID_CSP_I420 = (1 shl 1); // 4:2:0 planar
      XVID_CSP_YV12 = (1 shl 2); // 4:2:0 planar
      XVID_CSP_YUY2 = (1 shl 3); // 4:2:2 packed
      XVID_CSP_UYVY = (1 shl 4); // 4:2:2 packed
      XVID_CSP_YVYU = (1 shl 5); // 4:2:2 packed
      XVID_CSP_BGRA = (1 shl 6); // 32-bit bgra packed
      XVID_CSP_ABGR = (1 shl 7); // 32-bit abgr packed
      XVID_CSP_RGBA = (1 shl 8); // 32-bit rgba packed
      XVID_CSP_ARGB = (1 shl 15); // 32-bit argb packed
      XVID_CSP_BGR = (1 shl 9); // 24-bit bgr packed
      XVID_CSP_RGB555 = (1 shl 10); // 16-bit rgb555 packed
      XVID_CSP_RGB565 = (1 shl 11); // 16-bit rgb565 packed
      XVID_CSP_SLICE = (1 shl 12); // decoder only: 4:2:0 planar, per slice rendering
      XVID_CSP_INTERNAL = (1 shl 13); // decoder only: 4:2:0 planar, returns ptrs to internal buffers
      XVID_CSP_NULL = (1 shl 14); // decoder only: dont output anything
      XVID_CSP_VFLIP = (1 shl 31); // vertical flip mask// 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..4 - 1] of Pointer; // [in] image plane ptrs
        stride: array[0..4 - 1] of Integer; // [in] image stride; "bytes per row"
      end;// video-object-sequence profiles
    const
      XVID_PROFILE_S_L0 = $08; // simple
      XVID_PROFILE_S_L1 = $01;
      XVID_PROFILE_S_L2 = $02;
      XVID_PROFILE_S_L3 = $03;
      XVID_PROFILE_ARTS_L1 = $91; // advanced realtime simple
      XVID_PROFILE_ARTS_L2 = $92;
      XVID_PROFILE_ARTS_L3 = $93;
      XVID_PROFILE_ARTS_L4 = $94;
      XVID_PROFILE_AS_L0 = $F0; // advanced simple
      XVID_PROFILE_AS_L1 = $F1;
      XVID_PROFILE_AS_L2 = $F2;
      XVID_PROFILE_AS_L3 = $F3;
      XVID_PROFILE_AS_L4 = $F4;// aspect ratios
    const
      XVID_PAR_11_VGA = 1; // 1:1 vga (square), default if supplied PAR is not a valid value
      XVID_PAR_43_PAL = 2; // 4:3 pal (12:11 625-line)
      XVID_PAR_43_NTSC = 3; // 4:3 ntsc (10:11 525-line)
      XVID_PAR_169_PAL = 4; // 16:9 pal (16:11 625-line)
      XVID_PAR_169_NTSC = 5; // 16:9 ntsc (40:33 525-line)
      XVID_PAR_EXT = 15; // extended par; use par_width, par_height// frame type flags
    const
      XVID_TYPE_VOL = -1; // decoder only: vol was decoded
      XVID_TYPE_NOTHING = 0; // decoder only (encoder stats): nothing was decoded/encoded
      XVID_TYPE_AUTO = 0; // encoder: automatically determine coding type
      XVID_TYPE_IVOP = 1; // intra frame
      XVID_TYPE_PVOP = 2; // predicted frame
      XVID_TYPE_BVOP = 3; // bidirectionally encoded
      XVID_TYPE_SVOP = 4; // predicted+sprite frame
      

  2.   

    //****************************************************************************
    // xvid_global()
    //****************************************************************************// cpu_flags definitions (make sure to sync this with cpuid.asm for ia32)
    const
      XVID_CPU_FORCE = (1 shl 31); // force passed cpu flags
      XVID_CPU_ASM = (1 shl 7); // native assembly
      // ARCH_IS_IA32
      XVID_CPU_MMX = (1 shl 0); // mmx : pentiumMMX,k6
      XVID_CPU_MMXEXT = (1 shl 1); // mmx-ext : pentium2, athlon
      XVID_CPU_SSE = (1 shl 2); // sse : pentium3, athlonXP
      XVID_CPU_SSE2 = (1 shl 3); // sse2 : pentium4, athlon64
      XVID_CPU_3DNOW = (1 shl 4); // 3dnow : k6-2
      XVID_CPU_3DNOWEXT = (1 shl 5); // 3dnow-ext : athlon
      XVID_CPU_TSC = (1 shl 6); // tsc : Pentium
      // ARCH_IS_PPC
      XVID_CPU_ALTIVEC = (1 shl 0); // altivec  XVID_DEBUG_ERROR = (1 shl 0);
      XVID_DEBUG_STARTCODE = (1 shl 1);
      XVID_DEBUG_HEADER = (1 shl 2);
      XVID_DEBUG_TIMECODE = (1 shl 3);
      XVID_DEBUG_MB = (1 shl 4);
      XVID_DEBUG_COEFF = (1 shl 5);
      XVID_DEBUG_MV = (1 shl 6);
      XVID_DEBUG_RC = (1 shl 7);
      XVID_DEBUG_DEBUG = (1 shl 31);// 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;// XVID_GBL_CONVERT param1
      xvid_gbl_convert_t = packed record
        version: Integer;
        input: XVID_IMAGE_T; // [in] input image  and  colorspace
        output: XVID_IMAGE_T; // [in] output image  and  colorspace
        width: Integer; // [in] width
        height: Integer; // [in] height
        interlacing: Integer; // [in] interlacing
      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 utilitytype
      xvid_global = function(handle: Pointer;
        opt: Integer;
        param1: Pointer;
        param2: Pointer): Integer; cdecl;//****************************************************************************
    // 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 >= 0type
      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.type
      xvid_dec_create_t = packed record
        version: Integer;
        width: Integer; // [in:opt] image width
        height: Integer; // [in:opt] image width
        handle: Pointer; // [out] decore context handle
      end;// XVID_DEC_DECODE param1
    // general flags
    const
      XVID_LOWDELAY = (1 shl 0); // lowdelay mode
      XVID_DISCONTINUITY = (1 shl 1); // indicates break in stream
      XVID_DEBLOCKY = (1 shl 2); // perform luma deblocking
      XVID_DEBLOCKUV = (1 shl 3); // perform chroma deblocking
      XVID_FILMEFFECT = (1 shl 4); // adds film graintype
      xvid_dec_frame_t = packed record
        version: Integer;
        general: Integer; // [in:opt] general flags
        bitstream: Pointer; // [in] bitstream (read from)
        length: Integer; // [in] bitstream length
        output: XVID_IMAGE_T; // [in] output image (written to)
      end;// XVID_DEC_DECODE param2 :: optional
      vop = packed record
        version: Integer;
        _type: Integer; // [out] output data type
                                  // type>0 {XVID_TYPE_IVOP,XVID_TYPE_PVOP,XVID_TYPE_BVOP,XVID_TYPE_SVOP}
        general: Integer; // [out] flags
        time_base: Integer; // [out] time base
        time_increment: Integer; // [out] time increment// XXX: external deblocking stuff
        qscale: PInteger; // [out] pointer to quantizer table
        qscale_stride: Integer; // [out] quantizer scale stride
      end;  vol = 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;const
      XVID_ZONE_QUANT = (1 shl 0);
      XVID_ZONE_WEIGHT = (1 shl 1);
      

  3.   

    太长了,不贴了,
    其实关键的在这儿Vdecodeproc := GetProcAddress(XvidHandle, 'xvid_decore');//MPEG4解码代码
    Vencodeproc := GetProcAddress(XvidHandle, 'xvid_encore');//MPEG4编码代码
      

  4.   

    VFW效果太差
    VG就差不多
    DSpack也是好用的~
      

  5.   

    楼上的我现在换成了dspack,可是不太会用,能给写个例子吗
      

  6.   

    ly_liuyang(Liu Yang LYSoft http://lysoft.7u7.net)大侠,我用udp接收到流后用哪个控件显示出图像来啊,我查资料看到的有人用TImage显示,不会用这么笨的方法吧。
      

  7.   

    随便用什么,用能够显示图象的东西都行,窗体,panel