static void mpeg4_stop( struct mpeg4_encoder *en ) { spook_log( SL_DEBUG, "mpeg4: destroying mpeg4 encoder" ); xvid_encore( en->xvid_handle, XVID_ENC_DESTROY, NULL, NULL ); en->xvid_handle = NULL; }
int FFV1_XvidInit(v4linfo *info) { int err; printf("Initializing Xvid with width =%d, height = %d in YUV420P format\n",info->width,info->height); XVID_INIT_PARAM xinit; memset(&xinit,0,sizeof(xinit)); memset(&fr, 0, sizeof(fr)); xinit.cpu_flags = XVID_CPU_MMX; xvid_init(NULL, 0, &xinit, NULL); xparam.fincr = 1000; if(info->ntsc) xparam.fbase =29970; else xparam.fbase =25000; xparam.width = info->width; xparam.height = info->height; xparam.min_quantizer = info->quality; xparam.max_quantizer = info->quality; xparam.max_key_interval = info->keydist; err = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); if( XVID_ERR_OK!=err) { printf("\n Error initializing xvid !!!\n"); return 0; } xvid_handle=xparam.handle; printf("Xvid successfully initialized\n"); return 1; }
static int enc_stop() { int xerr; xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL); return xerr; }
void CXvidVideoEncoder::StopEncoder() { CHECK_AND_FREE(m_vopBuffer); xvid_encore(m_xvidHandle, XVID_ENC_DESTROY, NULL, NULL); m_xvidHandle = NULL; #ifdef WRITE_RAW fclose(m_raw_file); #endif }
uint8_t xvidEncoderCQ::encode( ADMImage * in, uint8_t * out, uint32_t * len, uint32_t * flags) { XVID_ENC_FRAME xframe; int xerr; memset(&xframe,0,sizeof(xframe)); xframe.general = encode_flags; xframe.motion = motion_flags; xframe.bitstream = out; xframe.length = -1; // this is written by the routine xframe.image = in->data; xframe.colorspace = XVID_CSP_YV12; // defined in <xvid.h> xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0) xframe.quant = _q; // xframe.quant = QUANTI; // is quant != 0, use a fixed quant (and ignore bitrate) xerr = xvid_encore(_handle, XVID_ENC_ENCODE, &xframe, &xstats); /* enc_result->is_key_frame = xframe.intra; enc_result->quantizer = xframe.quant; enc_result->total_bits = xframe.length * 8; enc_result->motion_bits = xstats.hlength * 8; enc_result->texture_bits = enc_result->total_bits - enc_result->motion_bits; */ xvid_res.is_key_frame = xframe.intra; xvid_res.quantizer = xframe.quant; xvid_res.total_bits = xframe.length * 8; xvid_res.motion_bits = xstats.hlength * 8; xvid_res.texture_bits = xvid_res.total_bits - xvid_res.motion_bits; xvid_res.out_quantizer=xstats.quant; /* This is statictical data, e.g. for 2-pass. If you are not interested in any of this, you can use NULL instead of &xstats */ *len = xframe.length; *flags=0; if(xerr!=XVID_ERR_OK) return 0; if( xframe.intra) { *flags=AVI_KEY_FRAME; } return 1; }
static void xvid_init_encoder (enix_venc_t *this_gen, enix_stream_t *stream) { xvid_t *this = (xvid_t *) this_gen; XVID_ENC_PARAM xparam; int xerr; int width, height, frame_duration; enix_options_t *options; width = stream->get_property (stream, ENIX_STREAM_PROP_WIDTH); height = stream->get_property (stream, ENIX_STREAM_PROP_HEIGHT); frame_duration = stream->get_property (stream, ENIX_STREAM_PROP_FRAME_DURATION); options = this->encoder.options; #ifdef LOG printf ("xvid: width=%02d, height=%02d\n", width, height); #endif this->quality = options->get_num_option (options, "quality"); this->bitrate = options->get_num_option (options, "bitrate"); xparam.width = width; xparam.height = height; xparam.fbase = 90000; xparam.fincr = frame_duration; xparam.rc_reaction_delay_factor = 16; xparam.rc_averaging_period = 100; xparam.rc_buffer = 10; xparam.rc_bitrate = this->bitrate; xparam.min_quantizer = 1; xparam.max_quantizer = 31; xparam.max_key_interval = 250; xparam.bquant_ratio = 120; xparam.bquant_offset = 0; xparam.max_bframes = options->get_num_option (options, "max_bframes");; xparam.frame_drop_ratio = 0; xparam.global = 0; xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xparam, NULL); #ifdef LOG printf ("xvid: enc_create done, xerr = %d\n", xerr); #endif if (xerr) { printf ("xvid: XVID_ENC_CREATE failed.\n"); exit (1); } this->xvid_handle = xparam.handle; }
void DestroyCompressor( PCOMPRESS *ppCompressor ) { if( ppCompressor ) { PCOMPRESS pCompressor = *ppCompressor; xvid_encore( pCompressor->handle, XVID_DEC_DESTROY, NULL, NULL ); Release( pCompressor ); (*ppCompressor) = NULL; } }
void Revel_XvidEncoder::Reset(void) { // Must call base Reset() first! Revel_BaseEncoder::Reset(); if (m_xvidEncoderHandle != NULL) { int xerr = xvid_encore(m_xvidEncoderHandle, XVID_ENC_DESTROY, NULL, NULL); m_xvidEncoderHandle = NULL; } }
//____________________________________________ // // Initialize the compressor // uint8_t xvid4Encoder::stopEncoder (void) { if (_handle) { xvid_encore (_handle, XVID_ENC_DESTROY, NULL, NULL); printf ("[xvid] Destroying\n"); _handle = NULL; } return 1; }
//int CPROC CompressFrame( PCOMPRESS pCompress, POINTER *data, INDEX *len ) int CPROC CompressFrame( uintptr_t psv, PCAPTURE_DEVICE pDevice ) { PCOMPRESS pCompress = (PCOMPRESS)psv; int xerr; Image frame; GetDeviceData( pDevice, &frame, NULL ); { // setup constant factors about encoding behavior pCompress->xframe.version = XVID_VERSION; //pCompress->xframe.general = 0; pCompress->xframe.motion = 0; /*PMV_ADVANCEDDIAMOND16;*/ pCompress->xframe.quant = 0; //1-31 specify quantizer... //pCompress->xframe.intra = -0; // 1- force keyframe, 0-force not keyframe pCompress->xframe.quant_intra_matrix = NULL; pCompress->xframe.quant_inter_matrix = NULL; /* setup the input frame here... */ pCompress->xframe.type = XVID_TYPE_AUTO; pCompress->xframe.input.csp = XVID_CSP_BGRA; pCompress->xframe.input.plane[0] = frame->image; pCompress->xframe.input.stride[0] = frame->pwidth*sizeof(CDATA); if( !pCompress->xframe.bitstream ) { pCompress->xframe.length = frame->pwidth * frame->height; //frame->width * frame->height * 4; pCompress->xframe.bitstream = Allocate( frame->pwidth * frame->height ); } } pCompress->xstats.version = XVID_VERSION; xerr = xvid_encore( pCompress->xparam.handle, XVID_ENC_ENCODE, &pCompress->xframe, &pCompress->xstats ); if(0) lprintf( WIDE("stats! %d %d %d %d %d %d") , xerr , pCompress->xstats.length , pCompress->xstats.hlength , pCompress->xstats.kblks , pCompress->xstats.mblks , pCompress->xstats.ublks ); if( xerr < 0 || xerr > 512000 ) { lprintf( WIDE("Resulting %d data was %p(%d)") , xerr , pCompress->xframe.bitstream , pCompress->xframe.length ); } MemCpy( pCompress->bitstream, pCompress->xframe.bitstream, xerr ); SetDeviceData( pDevice, pCompress->bitstream, xerr ); // at this point pCompress->xframe.intra 0 did not result in keyframe // 1 is a keyframe (scene change) 2 is keyframe (max keyfram interval) return 1; }
// ************************************************* // ************************************************* // Pass1 // ************************************************* // ************************************************* uint8_t xvid4EncoderPass1::init (uint32_t br, uint32_t fps1000, xvid4EncParam * param) { int xerr; printf ("[xvid] Pass 1 of 2 (log: %s)\n", (char *) param->logName); _fps1000 = fps1000; memcpy (&_param, param, sizeof (_param)); dump (); // Here we go... MMSET (xvid_enc_create); MMSET (pass1); xvid_enc_create.version = XVID_VERSION; xvid_enc_create.width = _w; xvid_enc_create.height = _h; plugins[0].func = xvid_plugin_2pass1; plugins[0].param = &pass1; pass1.version = XVID_VERSION; pass1.filename = (char *) _param.logName; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 1; //Framerate xvid_enc_create.fincr = 1000; xvid_enc_create.fbase = _fps1000; // createUpdate (); // Force Qz=2 ! xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); if (xerr < 0) { printf ("[xvid] Init error: %d\n", xerr); return 0; } _handle = xvid_enc_create.handle; printf ("[xvid] Pass 1 init Ok\n"); return 1; }
//____________________________________________ // // Initialize the compressor // uint8_t xvidEncoder::stopEncoder(void ) { int ret; ADM_assert(_init); ret = xvid_encore(_handle, XVID_ENC_DESTROY, 0, 0); _init = 0; _handle=NULL; if (ret == XVID_ERR_OK) return 1; return 0; }
uint8_t xvidEncoderVBR::encodeVBR( ADMImage * in, uint8_t * out, uint32_t * len, uint32_t * flags, uint16_t nq, uint8_t forcekey) { XVID_ENC_FRAME xframe; int xerr; memset(&xframe,0,sizeof(xframe)); xframe.general = encode_flags; xframe.motion = motion_flags; xframe.bitstream = out; xframe.length = -1; // this is written by the routine xframe.image = in->data; xframe.colorspace = XVID_CSP_YV12; // defined in <xvid.h> if( forcekey) xframe.intra = 1; // let the codec decide between I-frame (1) and P-frame (0) else xframe.intra = 0; // let the codec decide between I-frame (1) and P-frame (0) xframe.quant = nq; xerr = xvid_encore(_handle, XVID_ENC_ENCODE, &xframe, &xstats); xvid_res.is_key_frame = xframe.intra; xvid_res.quantizer = xframe.quant; xvid_res.out_quantizer=xstats.quant; xvid_res.total_bits = xframe.length * 8; xvid_res.motion_bits = xstats.hlength * 8; xvid_res.texture_bits = xvid_res.total_bits - xvid_res.motion_bits; *len = xframe.length; *flags=0; if(xerr!=XVID_ERR_OK) return 0; if( xframe.intra) { *flags=AVI_KEY_FRAME; } return 1; }
int FFV1_XvidCompress(unsigned char *in,unsigned char *out,uint32_t *outlen) { int ret; MMSET(xvid_enc_frame); MMSET(xvid_enc_stats); xvid_enc_frame.version = XVID_VERSION; xvid_enc_stats.version = XVID_VERSION; xvid_enc_frame.length = 0; xvid_enc_frame.vop_flags|=XVID_VOP_HALFPEL; if(vinfo.quant) xvid_enc_frame.vol_flags|=XVID_VOL_MPEGQUANT; xvid_enc_frame.input.csp = XVID_CSP_YV12; xvid_enc_frame.input.stride[0] = _w; xvid_enc_frame.input.stride[1] = _w>>1; xvid_enc_frame.input.stride[2] = _w>>1; xvid_enc_frame.type = XVID_TYPE_AUTO; /* Set up motion estimation flags */ xvid_enc_frame.input.plane[0] = in; xvid_enc_frame.input.plane[2] = in+(_w*_h); xvid_enc_frame.input.plane[1] = in+((_w*_h*5)>>2); xvid_enc_frame.bitstream = out; xvid_enc_frame.quant = vinfo.quality; xvid_enc_frame.motion = X4motion_presets[vinfo.me]; if(nextIsKF) { xvid_enc_frame.type = XVID_TYPE_IVOP; // let the codec decide between I-frame (1) and P-frame (0) nextIsKF=0; } else { xvid_enc_frame.type = XVID_TYPE_VOL; // let the codec decide between I-frame (1) and P-frame (0) } ret = xvid_encore(xvid_handle, XVID_ENC_ENCODE, &xvid_enc_frame, &xvid_enc_stats); *outlen = ret; #ifdef ADM_DEBUG printf("Outlen: %lu\n",*outlen); #endif return 1; }
// ************************************************* // ************************************************* // CBR // ************************************************* // ************************************************* uint8_t xvid4EncoderCBR::init (uint32_t br, uint32_t fps1000, xvid4EncParam * param) { int xerr; printf ("[xvid] CBR mode = %lu kbps\n", br); _bitrate = br; _fps1000 = fps1000; memcpy (&_param, param, sizeof (_param)); dump (); // Here we go... MMSET (single); MMSET (xvid_enc_create); xvid_enc_create.version = XVID_VERSION; xvid_enc_create.width = _w; xvid_enc_create.height = _h; plugins[0].func = xvid_plugin_single; plugins[0].param = &single; plugins[1].func = adm_hook; plugins[1].param = NULL; single.version = XVID_VERSION; single.bitrate = _bitrate * 1000; // Kb->bit xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 2; //Framerate xvid_enc_create.fincr = 1000; xvid_enc_create.fbase = _fps1000; // createUpdate (); xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); if (xerr < 0) { printf ("[xvid] Init error: %d\n", xerr); return 0; } _handle = xvid_enc_create.handle; printf ("[xvid] CBR init Ok\n"); return 1; }
/** * Destroy the private context for the encoder. * All buffers are freed, and the Xvid encoder context is destroyed. * * @param avctx AVCodecContext pointer to context * @return Returns 0, success guaranteed */ static av_cold int xvid_encode_close(AVCodecContext *avctx) { struct xvid_context *x = avctx->priv_data; xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); av_freep(&avctx->extradata); if( x->twopassbuffer != NULL ) { av_free(x->twopassbuffer); av_free(x->old_twopassbuffer); } av_free(x->twopassfile); av_free(x->intra_matrix); av_free(x->inter_matrix); return 0; }
static void xvid_dispose (enix_venc_t *this_gen) { xvid_t *this = (xvid_t *) this_gen; int xerr; xerr = xvid_encore (this->xvid_handle, XVID_ENC_DESTROY, NULL, NULL); this->xvid_handle = 0; if (this->hints_file) { fclose (this->hints_file); this->hints_file = NULL; } free (this); }
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; }
static void mpeg4_start( struct mpeg4_encoder *en, struct frame *f ) { xvid_enc_create_t xvid_enc_create; xvid_enc_plugin_t plugins[1]; xvid_plugin_single_t single; en->reset_pending = 0; en->width = f->width; en->height = f->height; memset( &xvid_enc_create, 0, sizeof( xvid_enc_create ) ); xvid_enc_create.version = XVID_VERSION; xvid_enc_create.width = en->width; xvid_enc_create.height = en->height; xvid_enc_create.profile = XVID_PROFILE_ARTS_L4; en->input->stream->get_framerate( en->input->stream, &xvid_enc_create.fincr, &xvid_enc_create.fbase ); spook_log( SL_DEBUG, "creating mpeg4 encoder with fincr=%d fbase=%d", xvid_enc_create.fincr, xvid_enc_create.fbase ); xvid_enc_create.zones = NULL; xvid_enc_create.num_zones = 0; xvid_enc_create.plugins = plugins; xvid_enc_create.num_plugins = 1; xvid_enc_create.num_threads = 0; xvid_enc_create.max_key_interval = 300; 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; memset( &single, 0, sizeof( single ) ); single.version = XVID_VERSION; single.bitrate = en->bitrate * 1000; plugins[0].func = xvid_plugin_single; plugins[0].param = &single; if( xvid_encore( NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL ) ) { spook_log( SL_ERR, "mpeg4: unable to start XviD!" ); return; } en->xvid_handle = xvid_enc_create.handle; }
int xvid_encode_frame(void* handle, unsigned char* frame, int width, int height, unsigned char* bitstream, unsigned int incr) { xvid_enc_frame_t xvid_enc_frame; int ret; unsigned char *buf; buf = frame; /* Version for the frame and the stats */ memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame)); xvid_enc_frame.version = XVID_VERSION; /* Bind output buffer */ xvid_enc_frame.bitstream = bitstream; xvid_enc_frame.length = -1; /* Initialize input image fields */ xvid_enc_frame.input.plane[0] = buf; xvid_enc_frame.input.csp = XVID_CSP_I420; xvid_enc_frame.input.stride[0] = width; /* Set up core's general features */ xvid_enc_frame.vol_flags = 0; /* Set up core's general features */ xvid_enc_frame.vop_flags = XVID_VOP_HALFPEL | XVID_VOP_INTER4V; /* Frame type -- let core decide for us */ xvid_enc_frame.type = XVID_TYPE_AUTO; /* Force the right quantizer -- It is internally managed by RC plugins */ xvid_enc_frame.quant = 0; /* Set up motion estimation flags */ xvid_enc_frame.motion = XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16; /* We don't use special matrices */ xvid_enc_frame.quant_intra_matrix = NULL; xvid_enc_frame.quant_inter_matrix = NULL; xvid_enc_frame.fincr = 0; ret = xvid_encore(handle, XVID_ENC_ENCODE, &xvid_enc_frame, NULL, &incr); return ret; }
uint8_t xvidEncoderCQ::initExtented (uint32_t q, xvidEncParam * extend) { XVID_INIT_PARAM xinit; int xerr; checkFlags (extend); memset (&xinit, 0, sizeof (xinit)); memset (&fr, 0, sizeof (fr)); //xinit.cpu_flags=XVID_CPU_FORCE; xinit.cpu_flags = XVID_CPU_MMX; //--- _q = q; printf (" Xvid : Compressing %lu x %lu video in CQ %lu\n", _w, _h, _q); ADM_assert (0 == _init); xvid_init (NULL, 0, &xinit, NULL); xparam.width = _w; xparam.height = _h; xparam.fincr = 1; xparam.fbase = 25; xparam.rc_bitrate = 1000; xparam.rc_reaction_delay_factor = 16; xparam.rc_averaging_period = 100; xparam.rc_buffer = 100; xparam.min_quantizer = _q; xparam.max_quantizer = _q; xparam.max_key_interval = extend->max_key_interval; xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xparam, NULL); if (XVID_ERR_OK != xerr) { printf ("\n Error initializing xvid !!!"); return 0; } _handle = xparam.handle; dumpConf (); return 1; }
static GstStateChangeReturn gst_xvidenc_change_state (GstElement * element, GstStateChange transition) { GstXvidEnc *xvidenc = GST_XVIDENC (element); GstStateChangeReturn ret; switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: if (!gst_xvid_init ()) return GST_STATE_CHANGE_FAILURE; break; case GST_STATE_CHANGE_READY_TO_PAUSED: xvidenc->delay = g_queue_new (); break; default: break; } ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); if (ret == GST_STATE_CHANGE_FAILURE) goto done; switch (transition) { case GST_STATE_CHANGE_PAUSED_TO_READY: if (xvidenc->handle) { gst_xvidenc_flush_buffers (xvidenc, FALSE); xvid_encore (xvidenc->handle, XVID_ENC_DESTROY, NULL, NULL); xvidenc->handle = NULL; } g_queue_free (xvidenc->delay); xvidenc->delay = NULL; g_free (xvidenc->xframe_cache); xvidenc->xframe_cache = NULL; break; default: break; } done: return ret; }
int evid_destroy_handler(evid_handler_t *evid_handler, char **errstr) { handler_t *handler=(handler_t *)evid_handler; free(handler->filename); // avilib if(AVI_close(handler->avilib.avi)) { x_asprintf(errstr, "Error closing AVI file: %s.\n", AVI_strerror()); return 1; } // xvid if(xvid_encore(handler->xvid.handle, XVID_ENC_DESTROY, NULL, NULL)) { (*errstr)=NULL; return 1; } // free bitstream free(handler->xvid.bitstream); // free handle free(handler); return 0; }
/** * Destroys the private context for the encoder. * All buffers are freed, and the XviD encoder context is destroyed. * * @param avctx AVCodecContext pointer to context * @return Returns 0, success guaranteed */ int ff_xvid_encode_close(AVCodecContext *avctx) { xvid_context_t *x = avctx->priv_data; xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); if( avctx->extradata != NULL ) av_free(avctx->extradata); if( x->twopassbuffer != NULL ) { av_free(x->twopassbuffer); av_free(x->old_twopassbuffer); } if( x->twopassfile != NULL ) av_free(x->twopassfile); if( x->intra_matrix != NULL ) av_free(x->intra_matrix); if( x->inter_matrix != NULL ) av_free(x->inter_matrix); return 0; }
static int enc_main(unsigned char* image, unsigned char* bitstream, long *streamlength, long *frametype) { int xerr; XVID_ENC_FRAME xframe; XVID_ENC_STATS xstats; xframe.bitstream = bitstream; xframe.length = -1; /* this is written by the routine */ xframe.image = image; xframe.colorspace = XVID_CSP_I420; /* defined in <xvid.h> */ /* let the codec decide between I-frame (1) and P-frame (0) */ if(filenr % (ARG_NUMBEROFP + 1) == 0) { xframe.intra = 1; } else { xframe.intra = 0; } xframe.quant = ARG_QUANTI; /* is quant != 0, use a fixed quant (and ignore bitrate) */ xframe.motion = motion_presets[ARG_QUALITY]; xframe.general = general_presets[ARG_QUALITY]; xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL; xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); /* * This is statictical data, e.g. for 2-pass. If you are not * interested in any of this, you can use NULL instead of &xstats */ *frametype = xframe.intra; *streamlength = xframe.length; return xerr; }
static int scxvid_process_frame(scxvid_state_t *state, void *plane_y, int stride_y, void *plane_u, int stride_u, void *plane_v, int stride_v) { state->xvid_enc_frame.input.plane[0] = plane_y; state->xvid_enc_frame.input.stride[0] = stride_y; state->xvid_enc_frame.input.plane[1] = plane_u; state->xvid_enc_frame.input.stride[1] = stride_u; state->xvid_enc_frame.input.plane[2] = plane_v; state->xvid_enc_frame.input.stride[2] = stride_v; state->xvid_enc_frame.length = SCXVID_BUFFER_SIZE; state->xvid_enc_frame.bitstream = state->output_buffer; int error = xvid_encore(state->xvid_handle, XVID_ENC_ENCODE, &state->xvid_enc_frame, NULL); if (error < 0) { fprintf(stderr,"SCXvid: xvid_encore returned an error code\n"); return error; } return 0; }
int FFV1_XvidCompress(unsigned char *in,unsigned char *out,uint32_t *outlen) { XVID_ENC_FRAME xframe; int xerr; memset(&xframe,0,sizeof(xframe)); xframe.general = divx4_general_presets[vinfo.me]; xframe.motion = divx4_motion_presets[vinfo.me]; xframe.general |= XVID_H263QUANT;// + XVID_INTERLACING; xframe.bitstream = out; xframe.length = -1; // this is written by the routine xframe.image = in; xframe.colorspace = XVID_CSP_I420; // defined in <xvid.h> if(nextIsKF) { xframe.intra = 1; // let the codec decide between I-frame (1) and P-frame (0) nextIsKF=0; } else { xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0) } xframe.quant = vinfo.quality; // xframe.quant = QUANTI; // is quant != 0, use a fixed quant (and ignore bitrate) xerr =xvid_encore(xvid_handle, XVID_ENC_ENCODE, &xframe, &xstats); assert(XVID_ERR_OK==xerr); *outlen = xframe.length; return 1; }
uint8_t xvid4Encoder::encode(ADMImage * in,ADMBitstream * out) { int ret=0; /* Encode the frame */ xvid_enc_frame.bitstream = out->data; preAmble (in->data); ret = xvid_encore (_handle, XVID_ENC_ENCODE, &xvid_enc_frame, &xvid_enc_stats); if (ret < 0) { printf ("[xvid] Error calling xvid4 %d\n", ret); return 0; } postAmble (out); out->len = ret; if (!ret) printf ("[xvid] Skipped\n"); return 1; }
bool CXvidVideoEncoder::EncodeImage( const u_int8_t* pY, const u_int8_t* pU, const u_int8_t* pV, u_int32_t yStride, u_int32_t uvStride, bool wantKeyFrame, Duration Elapsed, Timestamp srcFrameTimestamp) { m_srcFrameTimestamp = srcFrameTimestamp; m_vopBuffer = (u_int8_t*)malloc(Profile()->m_videoMaxVopSize); if (m_vopBuffer == NULL) { return false; } XVID_DEC_PICTURE decpict; decpict.y = (void *)pY; decpict.u = (void *)pU; decpict.v = (void *)pV; decpict.stride_y = yStride; decpict.stride_u = uvStride; m_xvidFrame.image = &decpict; m_xvidFrame.colorspace = XVID_CSP_USER; m_xvidFrame.bitstream = m_vopBuffer; m_xvidFrame.intra = (wantKeyFrame ? 1 : -1); if (xvid_encore(m_xvidHandle, XVID_ENC_ENCODE, &m_xvidFrame, &m_xvidResult) != XVID_ERR_OK) { debug_message("Xvid can't encode frame!"); CHECK_AND_FREE(m_vopBuffer); return false; } m_vopBufferLength = m_xvidFrame.length; return true; }
/* Initialize encoder for first use, pass all needed parameters to the codec */ static int enc_init(void) { int xerr; XVID_INIT_PARAM xinit; XVID_ENC_PARAM xparam; xinit.cpu_flags = XVID_CPU_FORCE; xvid_init(NULL, 0, &xinit, NULL); xparam.width = XDIM; xparam.height = YDIM; if ((ARG_FRAMERATE - (int)ARG_FRAMERATE) < SMALL_EPS) { xparam.fincr = 1; xparam.fbase = (int)ARG_FRAMERATE; } else { xparam.fincr = FRAMERATE_INCR; xparam.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE); } xparam.rc_reaction_delay_factor = 16; xparam.rc_averaging_period = 100; xparam.rc_buffer = 10; xparam.rc_bitrate = ARG_BITRATE; xparam.min_quantizer = ARG_MINQUANT; xparam.max_quantizer = ARG_MAXQUANT; xparam.max_key_interval = (int)ARG_FRAMERATE*10; /* I use a small value here, since will not encode whole movies, but short clips */ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); enc_handle=xparam.handle; return xerr; }