/* System wide init, do it once for all */ void xvid4_init (void) { MMSET (xvid_gbl_init2); MMSET (xvid_gbl_info); printf ("[xvid] Initializing global Xvid 4\n"); xvid_gbl_init2.version = XVID_VERSION; xvid_global (NULL, XVID_GBL_INIT, &xvid_gbl_init2, NULL); xvid_gbl_info.version = XVID_VERSION; xvid_global (NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL); if (xvid_gbl_info.build) printf ("[xvid] Build: %s\n", xvid_gbl_info.build); printf ("[xvid] SIMD supported: (%x)\n", xvid_gbl_info.cpu_flags); #define CPUF(x) if(xvid_gbl_info.cpu_flags & XVID_CPU_##x) printf("\t\t"#x"\n"); #if defined( ARCH_X86) || defined(ARCH_X86_64) CPUF (MMX); CPUF (MMXEXT); CPUF (SSE); CPUF (SSE2); CPUF (3DNOW); CPUF (3DNOWEXT); #endif #ifdef USE_ALTIVEC CPUF (ALTIVEC); #endif }
gboolean gst_xvid_init (void) { xvid_gbl_init_t xinit; gint ret; static gboolean is_init = FALSE; /* only init once */ if (is_init == TRUE) { return TRUE; } /* set up xvid initially (function pointers, CPU flags) */ gst_xvid_init_struct (xinit); if ((ret = xvid_global (NULL, XVID_GBL_INIT, &xinit, NULL)) < 0) { g_warning ("Failed to initialize XviD: %s (%d)", gst_xvid_error (ret), ret); return FALSE; } GST_LOG ("Initted XviD version %d.%d.%d (API %d.%d)", XVID_VERSION_MAJOR (XVID_VERSION), XVID_VERSION_MINOR (XVID_VERSION), XVID_VERSION_PATCH (XVID_VERSION), XVID_API_MAJOR (XVID_API), XVID_API_MINOR (XVID_API)); is_init = TRUE; return TRUE; }
static int init_xvid() { int ret; xvid_gbl_init_t xvid_gbl_init; xvid_dec_create_t xvid_dec_create; /* Reset the structure with zeros */ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t)); /* Version */ xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.cpu_flags = 0; xvid_gbl_init.debug = 0; xvid_global(NULL, 0, &xvid_gbl_init, NULL); /* Version */ xvid_dec_create.version = XVID_VERSION; /* * Image dimensions -- set to 0, xvidcore will resize when ever it is * needed */ xvid_dec_create.width = 0; xvid_dec_create.height = 0; ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL); g_ogm.xvid_dec_handle = xvid_dec_create.handle; return(ret); }
static int CIN_XVID_Init (cinematic_t* cin) { int ret; xvid_gbl_init_t xvid_gbl_init; xvid_dec_create_t xvid_dec_create; /* Reset the structure with zeros */ OBJZERO(xvid_gbl_init); OBJZERO(xvid_dec_create); /* Version */ xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.cpu_flags = 0; xvid_gbl_init.debug = 0; xvid_global(nullptr, 0, &xvid_gbl_init, nullptr); /* Version */ xvid_dec_create.version = XVID_VERSION; /* Image dimensions -- set to 0, xvidcore will resize when ever it is needed */ xvid_dec_create.width = 0; xvid_dec_create.height = 0; ret = xvid_decore(nullptr, XVID_DEC_CREATE, &xvid_dec_create, nullptr); OGMCIN.xvidDecodeHandle = xvid_dec_create.handle; return ret; }
int mpeg4_dec_init(void) { xvid_gbl_init_t xvid_gbl_init; memset( &xvid_gbl_init, 0, sizeof( xvid_gbl_init ) ); xvid_gbl_init.version = XVID_VERSION; xvid_global( NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL ); register_config_context( "decoder", "mpeg4", start_block, end_block, config_statements ); return 0; }
int evid_init(char **errstr) { // XviD global initialization xvid_gbl_init_t xvid_gbl_init; memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); xvid_gbl_init.version=XVID_VERSION; xvid_gbl_init.debug=0; xvid_gbl_init.cpu_flags=0; if(xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL)) { x_asprintf(errstr, "%s", "Error initializing XviD core.\n"); return 1; } return 0; }
/* init decoder before first run */ int dec_init(int use_assembler, int debug_level) { int ret; xvid_gbl_init_t xvid_gbl_init; xvid_dec_create_t xvid_dec_create; /* Reset the structure with zeros */ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t)); dec_handle=NULL; XDIM=0; YDIM=0; /*------------------------------------------------------------------------ * XviD core initialization *----------------------------------------------------------------------*/ /* Version */ xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; xvid_gbl_init.debug = debug_level; xvid_global(NULL, 0, &xvid_gbl_init, NULL); /*------------------------------------------------------------------------ * XviD encoder initialization *----------------------------------------------------------------------*/ /* Version */ xvid_dec_create.version = XVID_VERSION; /* * Image dimensions -- set to 0, xvidcore will resize when ever it is * needed */ xvid_dec_create.width = 0; xvid_dec_create.height = 0; ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL, 0); if(ret!=0) return ret; dec_handle = xvid_dec_create.handle; return(ret); }
int Revel_XvidEncoder::CreateXvidEncoder(void **encoderOut) { // Initialize XviD core xvid_gbl_init_t xvid_gbl_init; memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.debug = 0; xvid_gbl_init.cpu_flags = 0; xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); // Initialize XviD encoder xvid_enc_create_t xvid_enc_create; memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); xvid_enc_create.version = XVID_VERSION; xvid_enc_create.width = m_params.width; xvid_enc_create.height = m_params.height; xvid_enc_create.profile = XVID_PROFILE_AS_L4; // init plugins xvid_enc_zone_t zones[64]; const int NUM_ZONES = 0; xvid_enc_create.zones = zones; xvid_enc_create.num_zones = NUM_ZONES; xvid_enc_plugin_t plugins[7]; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 0; xvid_enc_create.num_threads = 0; xvid_enc_create.fincr = 1; xvid_enc_create.fbase = 24; xvid_enc_create.max_key_interval = xvid_enc_create.fbase * 10; xvid_enc_create.max_bframes = 0; xvid_enc_create.bquant_ratio = 150; xvid_enc_create.bquant_offset = 100; xvid_enc_create.frame_drop_ratio = 0; xvid_enc_create.global = 0; int xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); // Retrieve the encoder instance from the structure *encoderOut = xvid_enc_create.handle; return xerr; }
BOOL XviDDec::Start_XviD(int Xsize,int Ysize,int csp) { /***************************************************************************** * Memory allocation ****************************************************************************/ Clear_XviD(); width = Xsize; height = Ysize; colorspace = csp; filenr = 0; totalsize = 0; forceSkip = FALSE; buffer_size = 2*width*height; xvid_gbl_init_t xvid_gbl_init; xvid_dec_create_t xvid_dec_create; /*------------------------------------------------------------------------ * XviD core initialization *----------------------------------------------------------------------*/ /* Version */ xvid_gbl_init.version = XVID_VERSION; #ifndef _DEBUG xvid_gbl_init.cpu_flags = 0; #else xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; #endif xvid_global(NULL, 0, &xvid_gbl_init, NULL); /*------------------------------------------------------------------------ * XviD encoder initialization *----------------------------------------------------------------------*/ /* Version */ xvid_dec_create.version = XVID_VERSION; /* * Image dimensions -- set to 0, xvidcore will resize when ever it is * needed */ xvid_dec_create.width = width; xvid_dec_create.height = height; int ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL); dec_handle = xvid_dec_create.handle; if(ret) return FALSE; bInit = TRUE; bContinue = FALSE; return TRUE; }
H263Codec::H263Codec(uint32 width, uint32 height) : _width(width), _height(height) { xvid_gbl_init_t xvid_gbl_init; memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.debug = 0;//XVID_DEBUG_ERROR | XVID_DEBUG_HEADER | XVID_DEBUG_STARTCODE; xvid_global(0, XVID_GBL_INIT, &xvid_gbl_init, 0); xvid_dec_create_t xvid_dec_create; memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t)); xvid_dec_create.version = XVID_VERSION; xvid_dec_create.width = width; xvid_dec_create.height = height; if (xvid_decore(0, XVID_DEC_CREATE, &xvid_dec_create, 0) != 0) error("Could not initialize xvid decoder"); _decHandle = xvid_dec_create.handle; }
static codec_data_t *xvid_create (const char *stream_type, const char *compressor, int type, int profile, format_list_t *media_fmt, video_info_t *vinfo, const uint8_t *userdata, uint32_t ud_size, video_vft_t *vft, void *ifptr) { xvid_codec_t *xvid; xvid = MALLOC_STRUCTURE(xvid_codec_t); memset(xvid, 0, sizeof(*xvid)); xvid->m_vft = vft; xvid->m_ifptr = ifptr; xvid_gbl_init_t gbl_init; gbl_init.version = XVID_VERSION; gbl_init.cpu_flags = 0; xvid_global(NULL, 0, &gbl_init, NULL); xvid->m_decodeState = XVID_STATE_VO_SEARCH; if (media_fmt != NULL && media_fmt->fmt_param != NULL) { // See if we can decode a passed in vovod header if (parse_vovod(xvid, media_fmt->fmt_param, 1, 0) == 0) { xvid->m_decodeState = XVID_STATE_WAIT_I; } } else if (userdata != NULL) { if (parse_vovod(xvid, (char *)userdata, 0, ud_size) == 0) { xvid->m_decodeState = XVID_STATE_WAIT_I; } } xvid->m_vinfo = vinfo; xvid->m_num_wait_i = 0; xvid->m_num_wait_i_frames = 0; xvid->m_total_frames = 0; xvid_message(LOG_DEBUG, "xvid", "created xvid"); return ((codec_data_t *)xvid); }
static av_cold int xvid_encode_init(AVCodecContext *avctx) { int xerr, i; int xvid_flags = avctx->flags; struct xvid_context *x = avctx->priv_data; uint16_t *intra, *inter; int fd; xvid_plugin_single_t single = { 0 }; struct xvid_ff_pass1 rc2pass1 = { 0 }; xvid_plugin_2pass2_t rc2pass2 = { 0 }; xvid_plugin_lumimasking_t masking_l = { 0 }; /* For lumi masking */ xvid_plugin_lumimasking_t masking_v = { 0 }; /* For variance AQ */ xvid_plugin_ssim_t ssim = { 0 }; xvid_gbl_init_t xvid_gbl_init = { 0 }; xvid_enc_create_t xvid_enc_create = { 0 }; xvid_enc_plugin_t plugins[4]; x->twopassfd = -1; /* Bring in VOP flags from ffmpeg command-line */ x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ if( xvid_flags & CODEC_FLAG_4MV ) x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */ if( avctx->trellis) x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */ if( xvid_flags & CODEC_FLAG_AC_PRED ) x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */ if( xvid_flags & CODEC_FLAG_GRAY ) x->vop_flags |= XVID_VOP_GREYSCALE; /* Decide which ME quality setting to use */ x->me_flags = 0; switch( avctx->me_method ) { case ME_FULL: /* Quality 6 */ x->me_flags |= XVID_ME_EXTSEARCH16 | XVID_ME_EXTSEARCH8; case ME_EPZS: /* Quality 4 */ x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP; case ME_LOG: /* Quality 2 */ case ME_PHODS: case ME_X1: x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16; case ME_ZERO: /* Quality 0 */ default: break; } /* Decide how we should decide blocks */ switch( avctx->mb_decision ) { case 2: x->vop_flags |= XVID_VOP_MODEDECISION_RD; x->me_flags |= XVID_ME_HALFPELREFINE8_RD | XVID_ME_QUARTERPELREFINE8_RD | XVID_ME_EXTSEARCH_RD | XVID_ME_CHECKPREDICTION_RD; case 1: if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) ) x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD; x->me_flags |= XVID_ME_HALFPELREFINE16_RD | XVID_ME_QUARTERPELREFINE16_RD; default: break; } /* Bring in VOL flags from ffmpeg command-line */ x->vol_flags = 0; if( xvid_flags & CODEC_FLAG_GMC ) { x->vol_flags |= XVID_VOL_GMC; x->me_flags |= XVID_ME_GME_REFINE; } if( xvid_flags & CODEC_FLAG_QPEL ) { x->vol_flags |= XVID_VOL_QUARTERPEL; x->me_flags |= XVID_ME_QUARTERPELREFINE16; if( x->vop_flags & XVID_VOP_INTER4V ) x->me_flags |= XVID_ME_QUARTERPELREFINE8; } xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.debug = 0; #if ARCH_PPC /* Xvid's PPC support is borked, use libavcodec to detect */ #if HAVE_ALTIVEC if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC; } else #endif xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; #else /* Xvid can detect on x86 */ xvid_gbl_init.cpu_flags = 0; #endif /* Initialize */ xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); /* Create the encoder reference */ xvid_enc_create.version = XVID_VERSION; /* Store the desired frame size */ xvid_enc_create.width = x->xsize = avctx->width; xvid_enc_create.height = x->ysize = avctx->height; /* Xvid can determine the proper profile to use */ /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */ /* We don't use zones */ xvid_enc_create.zones = NULL; xvid_enc_create.num_zones = 0; xvid_enc_create.num_threads = avctx->thread_count; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 0; /* Initialize Buffers */ x->twopassbuffer = NULL; x->old_twopassbuffer = NULL; x->twopassfile = NULL; if( xvid_flags & CODEC_FLAG_PASS1 ) { rc2pass1.version = XVID_VERSION; rc2pass1.context = x; x->twopassbuffer = av_malloc(BUFFER_SIZE); x->old_twopassbuffer = av_malloc(BUFFER_SIZE); if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot allocate 2-pass log buffers\n"); goto fail; } x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0; plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; plugins[xvid_enc_create.num_plugins].param = &rc2pass1; xvid_enc_create.num_plugins++; } else if( xvid_flags & CODEC_FLAG_PASS2 ) { rc2pass2.version = XVID_VERSION; rc2pass2.bitrate = avctx->bit_rate; fd = av_tempfile("xvidff.", &x->twopassfile, 0, avctx); if( fd == -1 ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write 2-pass pipe\n"); goto fail; } x->twopassfd = fd; if( avctx->stats_in == NULL ) { av_log(avctx, AV_LOG_ERROR, "Xvid: No 2-pass information loaded for second pass\n"); goto fail; } if( strlen(avctx->stats_in) > write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write to 2-pass pipe\n"); goto fail; } rc2pass2.filename = x->twopassfile; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; plugins[xvid_enc_create.num_plugins].param = &rc2pass2; xvid_enc_create.num_plugins++; } else if( !(xvid_flags & CODEC_FLAG_QSCALE) ) { /* Single Pass Bitrate Control! */ single.version = XVID_VERSION; single.bitrate = avctx->bit_rate; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; plugins[xvid_enc_create.num_plugins].param = &single; xvid_enc_create.num_plugins++; } if ( avctx->lumi_masking != 0.0) x->lumi_aq = 1; /* Luminance Masking */ if( x->lumi_aq ) { masking_l.method = 0; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; /* The old behavior is that when avctx->lumi_masking is specified, * plugins[...].param = NULL. Trying to keep the old behavior here. */ plugins[xvid_enc_create.num_plugins].param = avctx->lumi_masking ? NULL : &masking_l ; xvid_enc_create.num_plugins++; } /* Variance AQ */ if( x->variance_aq ) { masking_v.method = 1; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; plugins[xvid_enc_create.num_plugins].param = &masking_v ; xvid_enc_create.num_plugins++; } if( x->lumi_aq && x->variance_aq ) av_log(avctx, AV_LOG_INFO, "Both lumi_aq and variance_aq are enabled. The resulting quality" "will be the worse one of the two effects made by the AQ.\n"); /* SSIM */ if( x->ssim ) { plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim; ssim.b_printstat = ( x->ssim == 2 ); ssim.acc = x->ssim_acc; ssim.cpu_flags = xvid_gbl_init.cpu_flags; ssim.b_visualize = 0; plugins[xvid_enc_create.num_plugins].param = &ssim; xvid_enc_create.num_plugins++; } /* Frame Rate and Key Frames */ xvid_correct_framerate(avctx); xvid_enc_create.fincr = avctx->time_base.num; xvid_enc_create.fbase = avctx->time_base.den; if( avctx->gop_size > 0 ) xvid_enc_create.max_key_interval = avctx->gop_size; else xvid_enc_create.max_key_interval = 240; /* Xvid's best default */ /* Quants */ if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1; else x->qscale = 0; xvid_enc_create.min_quant[0] = avctx->qmin; xvid_enc_create.min_quant[1] = avctx->qmin; xvid_enc_create.min_quant[2] = avctx->qmin; xvid_enc_create.max_quant[0] = avctx->qmax; xvid_enc_create.max_quant[1] = avctx->qmax; xvid_enc_create.max_quant[2] = avctx->qmax; /* Quant Matrices */ x->intra_matrix = x->inter_matrix = NULL; if( avctx->mpeg_quant ) x->vol_flags |= XVID_VOL_MPEGQUANT; if( (avctx->intra_matrix || avctx->inter_matrix) ) { x->vol_flags |= XVID_VOL_MPEGQUANT; if( avctx->intra_matrix ) { intra = avctx->intra_matrix; x->intra_matrix = av_malloc(sizeof(unsigned char) * 64); } else intra = NULL; if( avctx->inter_matrix ) { inter = avctx->inter_matrix; x->inter_matrix = av_malloc(sizeof(unsigned char) * 64); } else inter = NULL; for( i = 0; i < 64; i++ ) { if( intra ) x->intra_matrix[i] = (unsigned char)intra[i]; if( inter ) x->inter_matrix[i] = (unsigned char)inter[i]; } } /* Misc Settings */ xvid_enc_create.frame_drop_ratio = 0; xvid_enc_create.global = 0; if( xvid_flags & CODEC_FLAG_CLOSED_GOP ) xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; /* Determines which codec mode we are operating in */ avctx->extradata = NULL; avctx->extradata_size = 0; if( xvid_flags & CODEC_FLAG_GLOBAL_HEADER ) { /* In this case, we are claiming to be MPEG4 */ x->quicktime_format = 1; avctx->codec_id = AV_CODEC_ID_MPEG4; } else { /* We are claiming to be Xvid */ x->quicktime_format = 0; if(!avctx->codec_tag) avctx->codec_tag = AV_RL32("xvid"); } /* Bframes */ xvid_enc_create.max_bframes = avctx->max_b_frames; xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset; xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor; if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED; av_assert0(xvid_enc_create.num_plugins + (!!x->ssim) + (!!x->variance_aq) + (!!x->lumi_aq) <= FF_ARRAY_ELEMS(plugins)); /* Create encoder context */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); if( xerr ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n"); goto fail; } x->encoder_handle = xvid_enc_create.handle; avctx->coded_frame = &x->encoded_picture; return 0; fail: xvid_encode_close(avctx); return -1; }
int FFV1_XvidInit(v4linfo *info) { int err; printf("Initializing Xvid4 with width =%d, height = %d in YUV420P format\n",info->width,info->height); MMSET(xvid_gbl_init2); MMSET(xvid_gbl_info); printf("Initializing global xvid 4\n"); xvid_gbl_init2.version = XVID_VERSION; xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init2, NULL); xvid_gbl_info.version = XVID_VERSION; xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL); if(xvid_gbl_info.build) { printf("\txvid build:%s\n",xvid_gbl_info.build); } printf("\txvid thread:%d\n",xvid_gbl_info.num_threads); printf("\txvid SIMD supported:(%x)\n",xvid_gbl_info.cpu_flags); // MMSET(xvid_enc_create); xvid_enc_create.version = XVID_VERSION; xvid_enc_create.width = info->width; xvid_enc_create.height = info->height; MMSET(single); plugins[0].func = xvid_plugin_single; plugins[0].param = &single; single.version = XVID_VERSION; single.bitrate = 1500; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 1; if(info->ntsc) xvid_enc_create.fbase =29970; else xvid_enc_create.fbase =25000; //Framerate xvid_enc_create.fincr = 1000; // // err = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); if(err<0) { printf("Xvid-4 init error :%d\n",err); return 0; } xvid_handle = xvid_enc_create.handle; printf("Xvid-4 CQ init Ok\n"); return 1; }
GF_BaseDecoder *NewXVIDDec() { const char *sOpt; GF_MediaDecoder *ifcd; XVIDDec *dec; GF_SAFEALLOC(ifcd, GF_MediaDecoder); GF_SAFEALLOC(dec, XVIDDec); GF_REGISTER_MODULE_INTERFACE(ifcd, GF_MEDIA_DECODER_INTERFACE, "XviD Decoder", "gpac distribution") ifcd->privateStack = dec; if (!xvid_is_init) { #ifdef XVID_USE_OLD_API XVID_INIT_PARAM init; init.api_version = 0; init.core_build = 0; /*get info*/ init.cpu_flags = XVID_CPU_CHKONLY; xvid_init(NULL, 0, &init, NULL); /*then init*/ xvid_init(NULL, 0, &init, NULL); #else xvid_gbl_init_t init; init.debug = 0; init.version = XVID_VERSION; init.cpu_flags = 0; /*autodetect*/ xvid_global(NULL, 0, &init, NULL); #endif xvid_is_init = 1; } /*get config*/ dec->base_filters = 0; sOpt = gf_modules_get_option((GF_BaseInterface *)ifcd, "XviD", "PostProc"); if (sOpt) { #ifndef XVID_USE_OLD_API if (strstr(sOpt, "FilmEffect")) dec->base_filters |= XVID_FILMEFFECT; #endif if (strstr(sOpt, "Deblock_Y")) { #ifdef XVID_USE_OLD_API dec->base_filters |= XVID_DEC_DEBLOCKY; #else dec->base_filters |= XVID_DEBLOCKY; #endif } if (strstr(sOpt, "Deblock_UV")) { #ifdef XVID_USE_OLD_API dec->base_filters |= XVID_DEC_DEBLOCKUV; #else dec->base_filters |= XVID_DEBLOCKUV; #endif } } /*setup our own interface*/ ifcd->AttachStream = XVID_AttachStream; ifcd->DetachStream = XVID_DetachStream; ifcd->GetCapabilities = XVID_GetCapabilities; ifcd->SetCapabilities = XVID_SetCapabilities; ifcd->GetName = XVID_GetCodecName; ifcd->CanHandleStream = XVID_CanHandleStream; ifcd->ProcessData = XVID_ProcessData; return (GF_BaseDecoder *) ifcd; }
void InitCompress( PCOMPRESS pCompress, int width, int height ) { if( !pCompress->flags.bInited ) { { int version; pCompress->bitstream = Allocate( width * height * 4 ); pCompress->xinit.version = XVID_VERSION; if( XVID_VERSION != (version = xvid_global( NULL, XVID_GBL_INIT, &pCompress->xinit, NULL ) ) ) { lprintf( WIDE("warning: xvid api version(%d) and compiled version(%d) do not match.") , version, XVID_VERSION ); } pCompress->xinfo.version = XVID_VERSION; xvid_global( NULL, XVID_GBL_INFO, &pCompress->xinfo, NULL ); } { int xerr; #define xvid_enc_create pCompress->xparam /* Version again */ memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); xvid_enc_create.version = XVID_VERSION; /* Width and Height of input frames */ xvid_enc_create.width = width; xvid_enc_create.height = height; xvid_enc_create.profile = XVID_PROFILE_AS_L4; /* init plugins */ xvid_enc_create.zones = ZONES; xvid_enc_create.num_zones = NUM_ZONES; //xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 0; /* if (ARG_SINGLE) { memset(&single, 0, sizeof(xvid_plugin_single_t)); single.version = XVID_VERSION; single.bitrate = ARG_BITRATE; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; plugins[xvid_enc_create.num_plugins].param = &single; xvid_enc_create.num_plugins++; } if (ARG_PASS2) { memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t)); rc2pass2.version = XVID_VERSION; rc2pass2.filename = ARG_PASS2; rc2pass2.bitrate = ARG_BITRATE; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; plugins[xvid_enc_create.num_plugins].param = &rc2pass2; xvid_enc_create.num_plugins++; } if (ARG_PASS1) { memset(&rc2pass1, 0, sizeof(xvid_plugin_2pass1_t)); rc2pass1.version = XVID_VERSION; rc2pass1.filename = ARG_PASS1; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass1; plugins[xvid_enc_create.num_plugins].param = &rc2pass1; xvid_enc_create.num_plugins++; } if (ARG_LUMIMASKING) { plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; plugins[xvid_enc_create.num_plugins].param = NULL; xvid_enc_create.num_plugins++; } if (ARG_DUMP) { plugins[xvid_enc_create.num_plugins].func = xvid_plugin_dump; plugins[xvid_enc_create.num_plugins].param = NULL; xvid_enc_create.num_plugins++; } #if 0 if (ARG_DEBUG) { plugins[xvid_enc_create.num_plugins].func = rawenc_debug; plugins[xvid_enc_create.num_plugins].param = NULL; xvid_enc_create.num_plugins++; } #endif */ /* No fancy thread tests */ xvid_enc_create.num_threads = 0; /* Frame rate - Do some quick float fps = fincr/fbase hack */ if ((ARG_FRAMERATE - (int) ARG_FRAMERATE) < SMALL_EPS) { xvid_enc_create.fincr = 1; xvid_enc_create.fbase = (int) ARG_FRAMERATE; } else { xvid_enc_create.fincr = FRAMERATE_INCR; xvid_enc_create.fbase = (int) (FRAMERATE_INCR * ARG_FRAMERATE); } /* Maximum key frame interval */ if (ARG_MAXKEYINTERVAL > 0) { xvid_enc_create.max_key_interval = ARG_MAXKEYINTERVAL; }else { xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE *10; } /* Bframes settings */ xvid_enc_create.max_bframes = ARG_MAXBFRAMES; xvid_enc_create.bquant_ratio = ARG_BQRATIO; xvid_enc_create.bquant_offset = ARG_BQOFFSET; /* Dropping ratio frame -- we don't need that */ xvid_enc_create.frame_drop_ratio = 0; /* Global encoder options */ xvid_enc_create.global = 0; if (ARG_PACKED) xvid_enc_create.global |= XVID_GLOBAL_PACKED; if (ARG_CLOSED_GOP) xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; if (ARG_STATS) xvid_enc_create.global |= XVID_GLOBAL_EXTRASTATS_ENABLE; /* I use a small value here, since will not encode whole movies, but short clips */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); lprintf( WIDE("xerr of xvid_encore: %d handle:%d"), xerr, pCompress->xparam.handle ); } if(0) { int xerr; pCompress->xparam.version = XVID_VERSION; pCompress->xparam.width = width; pCompress->xparam.height = height; // frame rate - scaled 1000, 29.718 (or whatever) pCompress->xparam.fincr = 1000; pCompress->xparam.fbase = 29718; //pCompress->xparam.rc_bitrate = 770; //pCompress->xparam.rc_reaction_delay_factor = -1; //pCompress->xparam.rc_averaging_period = -1; //pCompress->xparam.rc_buffer = -1; //pCompress->xparam.min_quantizer = 1; //pCompress->xparam.max_quantizer = 15; // default 31 //pCompress->xparam.max_key_interfal = -1; // default 10sec (10*fps) xerr = xvid_encore( NULL, XVID_ENC_CREATE, &pCompress->xparam, NULL ); lprintf( WIDE("xerr of xvid_encore: %d handle:%d"), xerr, pCompress->xparam.handle ); } pCompress->xstats.version = XVID_VERSION; pCompress->flags.bInited = 1; } }
int XVIDVideoCodec::enc_init() { int xerr; //xvid_plugin_cbr_t cbr; //xvid_plugin_fixed_t rcfixed; xvid_enc_plugin_t plugins[7]; xvid_gbl_init_t xvid_gbl_init; xvid_enc_create_t xvid_enc_create; /*------------------------------------------------------------------------ * XviD core initialization *----------------------------------------------------------------------*/ /* Set version -- version checking will done by xvidcore */ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.debug = 0 /*ARG_DEBUG*/; #ifdef ARCH_IS_IA64 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ASM; #else xvid_gbl_init.cpu_flags = 0; #endif /* Initialize XviD core -- Should be done once per __process__ */ xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); /*------------------------------------------------------------------------ * XviD encoder initialization *----------------------------------------------------------------------*/ /* Version again */ memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); xvid_enc_create.version = XVID_VERSION; /* Width and Height of input frames */ xvid_enc_create.width = m_width; xvid_enc_create.height = m_height; xvid_enc_create.profile = XVID_PROFILE_AS_L4; /* init plugins */ xvid_enc_create.zones = ZONES; xvid_enc_create.num_zones = 0 /*NUM_ZONES*/; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 0; /* changing default bitrate to 10Kb */ { xvid_plugin_single_t single; memset(&single, 0, sizeof(xvid_plugin_single_t)); single.version = XVID_VERSION; single.bitrate = 10000; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; plugins[xvid_enc_create.num_plugins].param = &single; xvid_enc_create.num_plugins++; } /* end */ /* No fancy thread tests */ xvid_enc_create.num_threads = 0; if ((ARG_FRAMERATE - (int) ARG_FRAMERATE) < SMALL_EPS) { xvid_enc_create.fincr = 1; xvid_enc_create.fbase = (int) ARG_FRAMERATE; } else { xvid_enc_create.fincr = FRAMERATE_INCR; xvid_enc_create.fbase = (int) (FRAMERATE_INCR * ARG_FRAMERATE); } xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE * 3 /*10*/; /* Bframes settings */ xvid_enc_create.max_bframes = 0 /*ARG_MAXBFRAMES*/; xvid_enc_create.bquant_ratio = 150 /*ARG_BQRATIO*/; xvid_enc_create.bquant_offset = 100/*ARG_BQOFFSET*/; /* Dropping ratio frame -- we don't need that */ xvid_enc_create.frame_drop_ratio = 0; /* Global encoder options */ xvid_enc_create.global = 0; /* I use a small value here, since will not encode whole movies, but short clips */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); /* Retrieve the encoder instance from the structure */ enc_handle = xvid_enc_create.handle; return (xerr); }
XVIDVideoCodec::XVIDVideoCodec() { m_width = 160; m_height = 120; /* encoder init */ in_buffer = (unsigned char *) malloc(m_width * m_height * 3); mp4_buffer = (unsigned char *) malloc(m_width * m_height * 3); ARG_FRAMERATE = 2.0f; /*25.00f;*/ ARG_QUALITY = ME_ELEMENTS - 1; static void *enc_handle = NULL; int result = enc_init(); if (result) { wxMessageBox("Could not initialize XVid CODEC", _T("Error"), wxICON_ERROR | wxOK); exit(0); } /* decoder init */ xvid_gbl_init_t xvid_gbl_init; xvid_dec_create_t xvid_dec_create; /* Reset the structure with zeros */ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t)); /* Version */ xvid_gbl_init.version = XVID_VERSION; /* Assembly setting */ #ifdef ARCH_IS_IA64 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; #else xvid_gbl_init.cpu_flags = 0; #endif xvid_gbl_init.debug = 0/*debug_level*/; xvid_global(NULL, 0, &xvid_gbl_init, NULL); xvid_dec_create.version = XVID_VERSION; xvid_dec_create.width = m_width; xvid_dec_create.height = m_height; int ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL); if (ret) { wxMessageBox("Could not initialize XVid CODEC", _T("Error"), wxICON_ERROR | wxOK); exit(0); } dec_handle = xvid_dec_create.handle; out_buffer = (unsigned char*)malloc(m_width*m_height*4); memset(out_buffer, 0x00, m_width*m_height*4); }
/** * Creates the private context for the encoder. * All buffers are allocated, settings are loaded from the user, * and the encoder context created. * * @param avctx AVCodecContext pointer to context * @return Returns 0 on success, -1 on failure */ int ff_xvid_encode_init(AVCodecContext *avctx) { int xerr, i; int xvid_flags = avctx->flags; xvid_context_t *x = avctx->priv_data; uint16_t *intra, *inter; int fd; xvid_plugin_single_t single; xvid_ff_pass1_t rc2pass1; xvid_plugin_2pass2_t rc2pass2; xvid_gbl_init_t xvid_gbl_init; xvid_enc_create_t xvid_enc_create; xvid_enc_plugin_t plugins[7]; /* Bring in VOP flags from ffmpeg command-line */ x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ if( xvid_flags & CODEC_FLAG_4MV ) x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */ if( xvid_flags & CODEC_FLAG_TRELLIS_QUANT) x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */ if( xvid_flags & CODEC_FLAG_AC_PRED ) x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */ if( xvid_flags & CODEC_FLAG_GRAY ) x->vop_flags |= XVID_VOP_GREYSCALE; /* Decide which ME quality setting to use */ x->me_flags = 0; switch( avctx->me_method ) { case ME_FULL: /* Quality 6 */ x->me_flags |= XVID_ME_EXTSEARCH16 | XVID_ME_EXTSEARCH8; case ME_EPZS: /* Quality 4 */ x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP; case ME_LOG: /* Quality 2 */ case ME_PHODS: case ME_X1: x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16; case ME_ZERO: /* Quality 0 */ default: break; } /* Decide how we should decide blocks */ switch( avctx->mb_decision ) { case 2: x->vop_flags |= XVID_VOP_MODEDECISION_RD; x->me_flags |= XVID_ME_HALFPELREFINE8_RD | XVID_ME_QUARTERPELREFINE8_RD | XVID_ME_EXTSEARCH_RD | XVID_ME_CHECKPREDICTION_RD; case 1: if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) ) x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD; x->me_flags |= XVID_ME_HALFPELREFINE16_RD | XVID_ME_QUARTERPELREFINE16_RD; default: break; } /* Bring in VOL flags from ffmpeg command-line */ x->vol_flags = 0; if( xvid_flags & CODEC_FLAG_GMC ) { x->vol_flags |= XVID_VOL_GMC; x->me_flags |= XVID_ME_GME_REFINE; } if( xvid_flags & CODEC_FLAG_QPEL ) { x->vol_flags |= XVID_VOL_QUARTERPEL; x->me_flags |= XVID_ME_QUARTERPELREFINE16; if( x->vop_flags & XVID_VOP_INTER4V ) x->me_flags |= XVID_ME_QUARTERPELREFINE8; } memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.debug = 0; #ifdef ARCH_POWERPC /* XviD's PPC support is borked, use libavcodec to detect */ #ifdef HAVE_ALTIVEC if( has_altivec() ) { xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC; } else #endif xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; #else /* XviD can detect on x86 */ xvid_gbl_init.cpu_flags = 0; #endif /* Initialize */ xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); /* Create the encoder reference */ memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); xvid_enc_create.version = XVID_VERSION; /* Store the desired frame size */ xvid_enc_create.width = x->xsize = avctx->width; xvid_enc_create.height = x->ysize = avctx->height; /* XviD can determine the proper profile to use */ /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */ /* We don't use zones or threads */ xvid_enc_create.zones = NULL; xvid_enc_create.num_zones = 0; xvid_enc_create.num_threads = 0; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 0; /* Initialize Buffers */ x->twopassbuffer = NULL; x->old_twopassbuffer = NULL; x->twopassfile = NULL; if( xvid_flags & CODEC_FLAG_PASS1 ) { memset(&rc2pass1, 0, sizeof(xvid_ff_pass1_t)); rc2pass1.version = XVID_VERSION; rc2pass1.context = x; x->twopassbuffer = av_malloc(BUFFER_SIZE); x->old_twopassbuffer = av_malloc(BUFFER_SIZE); if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) { av_log(avctx, AV_LOG_ERROR, "XviD: Cannot allocate 2-pass log buffers\n"); return -1; } x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0; plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; plugins[xvid_enc_create.num_plugins].param = &rc2pass1; xvid_enc_create.num_plugins++; } else if( xvid_flags & CODEC_FLAG_PASS2 ) { memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t)); rc2pass2.version = XVID_VERSION; rc2pass2.bitrate = avctx->bit_rate; fd = av_tempfile("xvidff.", &(x->twopassfile)); if( fd == -1 ) { av_log(avctx, AV_LOG_ERROR, "XviD: Cannot write 2-pass pipe\n"); return -1; } if( avctx->stats_in == NULL ) { av_log(avctx, AV_LOG_ERROR, "XviD: No 2-pass information loaded for second pass\n"); return -1; } if( strlen(avctx->stats_in) > write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) { close(fd); av_log(avctx, AV_LOG_ERROR, "XviD: Cannot write to 2-pass pipe\n"); return -1; } close(fd); rc2pass2.filename = x->twopassfile; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; plugins[xvid_enc_create.num_plugins].param = &rc2pass2; xvid_enc_create.num_plugins++; } else if( !(xvid_flags & CODEC_FLAG_QSCALE) ) { /* Single Pass Bitrate Control! */ memset(&single, 0, sizeof(xvid_plugin_single_t)); single.version = XVID_VERSION; single.bitrate = avctx->bit_rate; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; plugins[xvid_enc_create.num_plugins].param = &single; xvid_enc_create.num_plugins++; } /* Luminance Masking */ if( 0.0 != avctx->lumi_masking ) { plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; plugins[xvid_enc_create.num_plugins].param = NULL; xvid_enc_create.num_plugins++; } /* Frame Rate and Key Frames */ xvid_correct_framerate(avctx); xvid_enc_create.fincr = avctx->time_base.num; xvid_enc_create.fbase = avctx->time_base.den; if( avctx->gop_size > 0 ) xvid_enc_create.max_key_interval = avctx->gop_size; else xvid_enc_create.max_key_interval = 240; /* XviD's best default */ /* Quants */ if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1; else x->qscale = 0; xvid_enc_create.min_quant[0] = avctx->qmin; xvid_enc_create.min_quant[1] = avctx->qmin; xvid_enc_create.min_quant[2] = avctx->qmin; xvid_enc_create.max_quant[0] = avctx->qmax; xvid_enc_create.max_quant[1] = avctx->qmax; xvid_enc_create.max_quant[2] = avctx->qmax; /* Quant Matrices */ x->intra_matrix = x->inter_matrix = NULL; if( avctx->mpeg_quant ) x->vol_flags |= XVID_VOL_MPEGQUANT; if( (avctx->intra_matrix || avctx->inter_matrix) ) { x->vol_flags |= XVID_VOL_MPEGQUANT; if( avctx->intra_matrix ) { intra = avctx->intra_matrix; x->intra_matrix = av_malloc(sizeof(unsigned char) * 64); } else intra = NULL; if( avctx->inter_matrix ) { inter = avctx->inter_matrix; x->inter_matrix = av_malloc(sizeof(unsigned char) * 64); } else inter = NULL; for( i = 0; i < 64; i++ ) { if( intra ) x->intra_matrix[i] = (unsigned char)intra[i]; if( inter ) x->inter_matrix[i] = (unsigned char)inter[i]; } } /* Misc Settings */ xvid_enc_create.frame_drop_ratio = 0; xvid_enc_create.global = 0; if( xvid_flags & CODEC_FLAG_CLOSED_GOP ) xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; /* Determines which codec mode we are operating in */ avctx->extradata = NULL; avctx->extradata_size = 0; if( xvid_flags & CODEC_FLAG_GLOBAL_HEADER ) { /* In this case, we are claiming to be MPEG4 */ x->quicktime_format = 1; avctx->codec_id = CODEC_ID_MPEG4; } else { /* We are claiming to be XviD */ x->quicktime_format = 0; if(!avctx->codec_tag) avctx->codec_tag = ff_get_fourcc("xvid"); } /* Bframes */ xvid_enc_create.max_bframes = avctx->max_b_frames; xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset; xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor; if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED; /* Create encoder context */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); if( xerr ) { av_log(avctx, AV_LOG_ERROR, "XviD: Could not create encoder reference\n"); return -1; } x->encoder_handle = xvid_enc_create.handle; avctx->coded_frame = &x->encoded_picture; return 0; }
static int init(sh_video_t *sh) { xvid_gbl_info_t xvid_gbl_info; xvid_gbl_init_t xvid_ini; xvid_dec_create_t dec_p; priv_t* p; int cs; memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t)); xvid_gbl_info.version = XVID_VERSION; memset(&xvid_ini, 0, sizeof(xvid_gbl_init_t)); xvid_ini.version = XVID_VERSION; memset(&dec_p, 0, sizeof(xvid_dec_create_t)); dec_p.version = XVID_VERSION; switch(sh->codec->outfmt[sh->outfmtidx]){ case IMGFMT_YV12: /* We will use our own buffers, this speeds decoding avoiding * frame memcpy's overhead */ cs = (do_dr2)?XVID_CSP_INTERNAL:XVID_CSP_USER; break; case IMGFMT_YUY2: cs = XVID_CSP_YUY2; break; case IMGFMT_UYVY: cs = XVID_CSP_UYVY; break; case IMGFMT_I420: case IMGFMT_IYUV: /* We will use our own buffers, this speeds decoding avoiding * frame memcpy's overhead */ cs = (do_dr2)?XVID_CSP_INTERNAL:XVID_CSP_USER; break; case IMGFMT_BGR15: cs = XVID_CSP_RGB555; break; case IMGFMT_BGR16: cs = XVID_CSP_RGB565; break; case IMGFMT_BGR32: cs = XVID_CSP_BGRA; break; case IMGFMT_YVYU: cs = XVID_CSP_YVYU; break; default: mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unsupported out_fmt: 0x%X\n", sh->codec->outfmt[sh->outfmtidx]); return 0; } /* Gather some information about the host library */ if(xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) { mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: could not get information about the library\n"); } else { mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: using library version %d.%d.%d (build %s)\n", XVID_VERSION_MAJOR(xvid_gbl_info.actual_version), XVID_VERSION_MINOR(xvid_gbl_info.actual_version), XVID_VERSION_PATCH(xvid_gbl_info.actual_version), xvid_gbl_info.build); } /* Initialize the xvidcore library */ if(xvid_global(NULL, XVID_GBL_INIT, &xvid_ini, NULL)) return 0; /* We use 0 width and height so xvidcore will resize its buffers * if required. That allows this vd plugin to do resize on first * VOL encountered (don't trust containers' width and height) */ dec_p.width = 0; dec_p.height = 0; /* Get a decoder instance */ if(xvid_decore(0, XVID_DEC_CREATE, &dec_p, NULL)<0) { mp_msg(MSGT_DECVIDEO, MSGL_ERR, "XviD init failed\n"); return 0; } p = malloc(sizeof(priv_t)); p->cs = cs; p->hdl = dec_p.handle; p->vo_initialized = 0; sh->context = p; switch(cs) { case XVID_CSP_INTERNAL: p->img_type = MP_IMGTYPE_EXPORT; break; case XVID_CSP_USER: p->img_type = MP_IMGTYPE_STATIC; break; default: p->img_type = MP_IMGTYPE_TEMP; break; } return 1; }
void* xvid_enc_init(int width, int height, int bitrate, int framerate, int key_interval, int use_assembler) { int xerr=0; void * handle; //xvid_plugin_cbr_t cbr; //xvid_plugin_fixed_t rcfixed; xvid_enc_plugin_t plugins[7]; xvid_gbl_init_t xvid_gbl_init; xvid_enc_create_t xvid_enc_create; /*------------------------------------------------------------------------ * XviD core initialization *----------------------------------------------------------------------*/ /* Set version -- version checking will done by xvidcore */ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.debug = 0; xvid_gbl_init.cpu_flags = 0; /* Initialize XviD core -- Should be done once per __process__ */ xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); /*------------------------------------------------------------------------ * XviD encoder initialization *----------------------------------------------------------------------*/ /* Version again */ memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); xvid_enc_create.version = XVID_VERSION; /* Width and Height of input frames */ xvid_enc_create.width = width; xvid_enc_create.height = height; xvid_enc_create.profile = XVID_PROFILE_S_L0; /* init plugins */ xvid_enc_create.zones = ZONES; xvid_enc_create.num_zones = NUM_ZONES; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 0; if (ARG_SINGLE) { memset(&single, 0, sizeof(xvid_plugin_single_t)); single.version = XVID_VERSION; single.bitrate = bitrate * 1000; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; plugins[xvid_enc_create.num_plugins].param = &single; xvid_enc_create.num_plugins++; } if (ARG_PASS2) { memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t)); rc2pass2.version = XVID_VERSION; rc2pass2.filename = ARG_PASS2; rc2pass2.bitrate = bitrate * 1000; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; plugins[xvid_enc_create.num_plugins].param = &rc2pass2; xvid_enc_create.num_plugins++; } if (ARG_PASS1) { memset(&rc2pass1, 0, sizeof(xvid_plugin_2pass1_t)); rc2pass1.version = XVID_VERSION; rc2pass1.filename = ARG_PASS1; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass1; plugins[xvid_enc_create.num_plugins].param = &rc2pass1; xvid_enc_create.num_plugins++; } /* No fancy thread tests */ xvid_enc_create.num_threads = 0; xvid_enc_create.fincr = 1000/framerate; // framerate increment; set to zero for avriable framerate xvid_enc_create.fbase = 1000; /* Maximum key frame interval */ if (key_interval > 0) { xvid_enc_create.max_key_interval = key_interval; }else { xvid_enc_create.max_key_interval = framerate *3; } /* Bframes settings */ xvid_enc_create.max_bframes = ARG_MAXBFRAMES; xvid_enc_create.bquant_ratio = ARG_BQRATIO; xvid_enc_create.bquant_offset = ARG_BQOFFSET; /* Dropping ratio frame -- we don't need that */ xvid_enc_create.frame_drop_ratio = 0; /* Global encoder options */ xvid_enc_create.global = 0; if (ARG_PACKED) xvid_enc_create.global |= XVID_GLOBAL_PACKED; if (ARG_CLOSED_GOP) xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; if (ARG_STATS) xvid_enc_create.global |= XVID_GLOBAL_EXTRASTATS_ENABLE; /* I use a small value here, since will not encode whole movies, but short clips */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL, NULL); /* Retrieve the encoder instance from the structure */ handle = xvid_enc_create.handle; return handle; }
/* ------------------------------------ * gap_gve_xvid_init * ------------------------------------ * init XVID and create the encoder instance * */ GapGveXvidControl * gap_gve_xvid_init(gint32 width, gint32 height, gdouble framerate, GapGveXvidValues *xvid_val) { GapGveXvidControl *xvid_control; xvid_gbl_init_t *xvid_gbl_init; xvid_enc_create_t *xvid_enc_create; xvid_enc_frame_t *xvid_enc_frame; int xerr; gdouble l_framerate_x1000; l_framerate_x1000 = framerate * 1000.0; xvid_control = g_malloc0(sizeof(GapGveXvidControl)); xvid_gbl_init = &xvid_control->xvid_gbl_init; xvid_enc_create = &xvid_control->xvid_enc_create; xvid_enc_frame = &xvid_control->xvid_enc_frame; /* ------------------------ * XviD core initialization * ------------------------- */ memset(xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); xvid_gbl_init->version = XVID_VERSION; xvid_gbl_init->debug = 0; xvid_gbl_init->cpu_flags = 0; xvid_gbl_init->cpu_flags = XVID_CPU_FORCE; if(gap_debug) { printf("gap_gve_xvid_init XVID_VERSION: %d (%d.%d.%d)\n" ,(int)xvid_gbl_init->version ,(int)XVID_VERSION_MAJOR(xvid_gbl_init->version) ,(int)XVID_VERSION_MINOR(xvid_gbl_init->version) ,(int)XVID_VERSION_PATCH(xvid_gbl_init->version) ); } /* Initialize XviD core -- Should be done once per __process__ */ xvid_global(NULL, XVID_GBL_INIT, xvid_gbl_init, NULL); /* ------------------------ * XviD encoder initialization * ------------------------- */ /* Version again */ memset(xvid_enc_create, 0, sizeof(xvid_enc_create_t)); xvid_enc_create->version = XVID_VERSION; /* Width and Height of input frames */ xvid_enc_create->width = width; xvid_enc_create->height = height; xvid_enc_create->profile = XVID_PROFILE_AS_L4; xvid_enc_create->fincr = 1000; xvid_enc_create->fbase = l_framerate_x1000; /* init zones */ xvid_control->num_zones = 0; if(FALSE) { /* the current implementation does not use zones * but here is an example what to initialize per zone * for later use */ if(TRUE) { xvid_control->zones[xvid_control->num_zones].mode = XVID_ZONE_QUANT; } else { xvid_control->zones[xvid_control->num_zones].mode = XVID_ZONE_WEIGHT; } xvid_control->zones[xvid_control->num_zones].frame = 0; xvid_control->zones[xvid_control->num_zones].increment = 100 * 1; xvid_control->zones[xvid_control->num_zones].base = 100; xvid_control->num_zones++; } xvid_enc_create->zones = &xvid_control->zones[0]; xvid_enc_create->num_zones = xvid_control->num_zones; /* init plugins */ xvid_enc_create->plugins = xvid_control->plugins; xvid_enc_create->num_plugins = 0; /* this implementation only uses SINGLE PASS */ { memset(&xvid_control->single, 0, sizeof(xvid_plugin_single_t)); xvid_control->single.version = XVID_VERSION; xvid_control->single.bitrate = xvid_val->rc_bitrate; xvid_control->plugins[xvid_enc_create->num_plugins].func = xvid_plugin_single; xvid_control->plugins[xvid_enc_create->num_plugins].param = &xvid_control->single; xvid_enc_create->num_plugins++; } /* TODO: lumimasking should be a Parameter */ if(FALSE) { xvid_control->plugins[xvid_enc_create->num_plugins].func = xvid_plugin_lumimasking; xvid_control->plugins[xvid_enc_create->num_plugins].param = NULL; xvid_enc_create->num_plugins++; } /* TODO: Dump should be a Parameter */ if(FALSE) { xvid_control->plugins[xvid_enc_create->num_plugins].func = xvid_plugin_dump; xvid_control->plugins[xvid_enc_create->num_plugins].param = NULL; xvid_enc_create->num_plugins++; } /* parameters of older xvid version (dont know how to migrate to v1.0) */ // xvid_encparam->rc_reaction_delay_factor = xvid_val->rc_reaction_delay_factor; // xvid_encparam->rc_averaging_period = xvid_val->rc_averaging_period; // xvid_encparam->rc_buffer = xvid_val->rc_buffer; // xvid_encparam->max_quantizer = xvid_val->max_quantizer; // xvid_encparam->min_quantizer = xvid_val->min_quantizer; /* Maximum key frame interval */ xvid_enc_create->max_key_interval = xvid_val->max_key_interval; /* No fancy thread tests */ xvid_enc_create->num_threads = 0; /* Bframes settings TODO: pass params for Bframe settings */ xvid_enc_create->max_bframes = 0; // ARG_MAXBFRAMES; xvid_enc_create->bquant_ratio = 150; // ARG_BQRATIO; xvid_enc_create->bquant_offset = 100; // ARG_BQOFFSET; /* Dropping ratio frame -- we don't need that */ xvid_enc_create->frame_drop_ratio = 0; /* Global encoder options TODO: pass params for Global options */ xvid_enc_create->global = 0; if (FALSE) { xvid_enc_create->global |= XVID_GLOBAL_PACKED; } if (FALSE) { xvid_enc_create->global |= XVID_GLOBAL_CLOSED_GOP; } if (FALSE) { xvid_enc_create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE; } xvid_enc_create->handle = NULL; /* out param The encoder instance */ xvid_enc_frame->version = XVID_VERSION; xvid_enc_frame->length = -1; /* out: length returned by encoder */ xvid_enc_frame->input.csp = XVID_CSP_YV12; /*XVID_CSP_I420 XVID_CSP_BGR | XVID_CSP_VFLIP */ /* Set up core's general features */ xvid_enc_frame->vol_flags = 0; if (FALSE) { xvid_enc_frame->vol_flags |= XVID_VOL_EXTRASTATS; } if (FALSE) { xvid_enc_frame->vol_flags |= XVID_VOL_QUARTERPEL; } if (FALSE) { xvid_enc_frame->vol_flags |= XVID_VOL_GMC; } xvid_enc_frame->vop_flags = xvid_val->general; xvid_enc_frame->motion = xvid_val->motion; if(FALSE) { xvid_enc_frame->motion |= XVID_ME_GME_REFINE; } if(FALSE) { xvid_enc_frame->motion |= XVID_ME_QUARTERPELREFINE16; } if(FALSE && (xvid_enc_frame->vop_flags & XVID_VOP_INTER4V)) { xvid_enc_frame->motion |= XVID_ME_QUARTERPELREFINE8; } xvid_enc_frame->quant_intra_matrix = NULL; /* use built in default Matrix */ xvid_enc_frame->quant_inter_matrix = NULL; /* use built in default Matrix */ xvid_enc_frame->quant = 0; /* 0: codec decides, 1..31 force quant for this frame */ xvid_enc_frame->type = XVID_TYPE_AUTO; /* Frame type -- let core decide for us */ /* create the encoder instance */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, xvid_enc_create, NULL); if(xerr) { printf("gap_gve_xvid_init create encoder instance failed. ERRORCODE: %d\n", (int)xerr); g_free(xvid_control); return (NULL); } return(xvid_control); } /* end gap_gve_xvid_init */
static int scxvid_create(scxvid_state_t *state) { int error = 0; xvid_gbl_init_t xvid_init; memset(&xvid_init, 0, sizeof(xvid_gbl_init_t)); xvid_init.version = XVID_VERSION; xvid_init.debug = ~0; error = xvid_global(NULL, XVID_GBL_INIT, &xvid_init, NULL); if (error) { fprintf(stderr, "SCXvid: Failed to initialize Xvid\n"); return error; } xvid_gbl_info_t xvid_info; memset(&xvid_info, 0, sizeof(xvid_gbl_info_t)); xvid_info.version = XVID_VERSION; error = xvid_global(NULL, XVID_GBL_INFO, &xvid_info, NULL); if (error) { fprintf(stderr, "SCXvid: Failed to initialize Xvid\n"); return error; } memset(&state->xvid_enc_create, 0, sizeof(xvid_enc_create_t)); state->xvid_enc_create.version = XVID_VERSION; state->xvid_enc_create.profile = 0; state->xvid_enc_create.width = state->vi.width; state->xvid_enc_create.height = state->vi.height; state->xvid_enc_create.num_threads = xvid_info.num_threads; state->xvid_enc_create.num_slices = xvid_info.num_threads; state->xvid_enc_create.fincr = 1; state->xvid_enc_create.fbase = 1; state->xvid_enc_create.max_key_interval = 10000000; //huge number xvid_enc_plugin_t plugins[1]; xvid_plugin_2pass1_t xvid_rc_plugin; memset(&xvid_rc_plugin, 0, sizeof(xvid_plugin_2pass1_t)); xvid_rc_plugin.version = XVID_VERSION; xvid_rc_plugin.filename = state->logname; plugins[0].func = xvid_plugin_2pass1; plugins[0].param = &xvid_rc_plugin; state->xvid_enc_create.plugins = plugins; state->xvid_enc_create.num_plugins = 1; error = xvid_encore(NULL, XVID_ENC_CREATE, &state->xvid_enc_create, NULL); if (error) { fprintf(stderr,"SCXvid: Failed to initialize Xvid encoder\n"); return error; } state->xvid_handle = state->xvid_enc_create.handle; //default identical(?) to xvid 1.1.2 vfw general preset memset(&state->xvid_enc_frame, 0, sizeof(xvid_enc_frame_t)); state->xvid_enc_frame.version = XVID_VERSION; state->xvid_enc_frame.vol_flags = 0; state->xvid_enc_frame.vop_flags = XVID_VOP_MODEDECISION_RD | XVID_VOP_HALFPEL | XVID_VOP_HQACPRED | XVID_VOP_TRELLISQUANT | XVID_VOP_INTER4V; state->xvid_enc_frame.motion = XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | XVID_ME_HALFPELREFINE8 | 0 | XVID_ME_USESQUARES16; state->xvid_enc_frame.type = XVID_TYPE_AUTO; state->xvid_enc_frame.quant = 0; state->xvid_enc_frame.input.csp = XVID_CSP_YV12; if (!(state->output_buffer = malloc(SCXVID_BUFFER_SIZE))) { fprintf(stderr,"SCXvid: Failed to allocate buffer\n"); perror(NULL); return XVID_ERR_MEMORY; } return 0; }