ve_xvid4.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,533 行 · 第 1/4 页
C
1,533 行
{ int err; xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; /* Complete the muxer initialization */ mod->mux->bih->biWidth = width; mod->mux->bih->biHeight = height; mod->mux->bih->biSizeImage = mod->mux->bih->biWidth * mod->mux->bih->biHeight * 3 / 2; mod->mux->aspect = (float)d_width/d_height; /* Message the FourCC type */ mp_msg(MSGT_MENCODER, MSGL_INFO, "videocodec: XviD (%dx%d fourcc=%x [%.4s])\n", width, height, mod->mux->bih->biCompression, (char *)&mod->mux->bih->biCompression); /* Total number of pixels per frame required for PSNR */ mod->pixels = mod->mux->bih->biWidth*mod->mux->bih->biHeight; /*-------------------------------------------------------------------- * Dispatch all module settings to XviD structures *------------------------------------------------------------------*/ mod->d_width = d_width; mod->d_height = d_height; if(dispatch_settings(mod) == BAD) return(BAD); /*-------------------------------------------------------------------- * Set remaining information in the xvid_enc_create_t structure *------------------------------------------------------------------*/ if(set_create_struct(mod) == BAD) return(BAD); /*-------------------------------------------------------------------- * Encoder instance creation *------------------------------------------------------------------*/ err = xvid_encore(NULL, XVID_ENC_CREATE, &mod->create, NULL); if(err<0) { mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: xvidcore returned a '%s' error\n", errorstring(err)); return(BAD); } /* Store the encoder instance into the private data */ mod->instance = mod->create.handle; mod->mux->decoder_delay = mod->create.max_bframes ? 1 : 0; return(FINE);}/*============================================================================ * uninit *==========================================================================*/static voiduninit(struct vf_instance_s* vf){ xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; /* Destroy xvid instance */ xvid_encore(mod->instance, XVID_ENC_DESTROY, NULL, NULL); /* Display stats (if any) */ print_stats(mod); /* Close PSNR file if ever opened */ if (mod->fvstats) { fclose(mod->fvstats); mod->fvstats = NULL; } /* Free allocated memory */ if(mod->frame.quant_intra_matrix) free(mod->frame.quant_intra_matrix); if(mod->frame.quant_inter_matrix) free(mod->frame.quant_inter_matrix); if(mod->mux->bih) free(mod->mux->bih); free(vf->priv); vf->priv=NULL; return;}/*============================================================================ * control *==========================================================================*/static intcontrol(struct vf_instance_s* vf, int request, void* data){xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; switch(request){ case VFCTRL_FLUSH_FRAMES: if(mod)/*paranoid*/ flush_internal_buffers(mod); break; } return(CONTROL_UNKNOWN);}/*============================================================================ * query_format *==========================================================================*/static intquery_format(struct vf_instance_s* vf, unsigned int fmt){ switch(fmt){ case IMGFMT_YV12: case IMGFMT_IYUV: case IMGFMT_I420: return(VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW); case IMGFMT_YUY2: case IMGFMT_UYVY: return(VFCAP_CSP_SUPPORTED); } return(BAD);}/*============================================================================ * put_image *==========================================================================*/static intput_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ int size; xvid_enc_stats_t stats; xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; /* Prepare the stats */ memset(&stats,0,sizeof( xvid_enc_stats_t)); stats.version = XVID_VERSION; /* ------------------------------------------------------------------- * Set remaining information in the xvid_enc_frame_t structure * NB: all the other struct members were initialized by * dispatch_settings * -----------------------------------------------------------------*/ if(set_frame_struct(mod, mpi) == BAD) return(BAD); /* ------------------------------------------------------------------- * Encode the frame * ---------------------------------------------------------------- */ size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats); /* Analyse the returned value */ if(size<0) { mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: xvidcore returned a '%s' error\n", errorstring(size)); return(BAD); } /* If size is == 0, we're done with that frame */ if(size == 0) { ++mod->mux->encoder_delay; return(FINE); } /* xvidcore returns stats about encoded frame in an asynchronous way * accumulate these stats */ update_stats(mod, &stats); /* xvidcore outputed bitstream -- mux it */ muxer_write_chunk(mod->mux, size, (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE); return(FINE);}/*============================================================================ * vf_open *==========================================================================*/static intvf_open(vf_instance_t *vf, char* args){ xvid_mplayer_module_t *mod; xvid_gbl_init_t xvid_gbl_init; xvid_gbl_info_t xvid_gbl_info; /* Setting libmpcodec module API pointers */ vf->config = config; vf->default_caps = VFCAP_CONSTANT; vf->control = control; vf->uninit = uninit; vf->query_format = query_format; vf->put_image = put_image; /* Allocate the private part of the codec module */ vf->priv = malloc(sizeof(xvid_mplayer_module_t)); mod = (xvid_mplayer_module_t*)vf->priv; if(mod == NULL) { mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: memory allocation failure (private data)\n"); return(BAD); } /* Initialize the module to zeros */ memset(mod, 0, sizeof(xvid_mplayer_module_t)); mod->min_sse_y = mod->min_sse_u = mod->min_sse_v = INT_MAX; mod->max_sse_y = mod->max_sse_u = mod->max_sse_v = INT_MIN; /* Bind the Muxer */ mod->mux = (muxer_stream_t*)args; /* Initialize muxer BITMAP header */ mod->mux->bih = calloc(1, sizeof(BITMAPINFOHEADER)); if(mod->mux->bih == NULL) { mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: memory allocation failure (BITMAP header)\n"); return(BAD); } mod->mux->bih->biSize = sizeof(BITMAPINFOHEADER); mod->mux->bih->biWidth = 0; mod->mux->bih->biHeight = 0; mod->mux->bih->biPlanes = 1; mod->mux->bih->biBitCount = 12; mod->mux->bih->biCompression = mmioFOURCC('X','V','I','D'); /* Retrieve information about the host XviD library */ memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t)); xvid_gbl_info.version = XVID_VERSION; if (xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) { mp_msg(MSGT_MENCODER,MSGL_WARN, "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 xvid_gbl_init structure */ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); xvid_gbl_init.version = XVID_VERSION; xvid_gbl_init.debug = xvidenc_debug; /* Initialize the xvidcore library */ if (xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL) < 0) { mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n"); return(BAD); } return(FINE);}/***************************************************************************** * Helper functions ****************************************************************************/static void *read_matrix(unsigned char *filename);static int dispatch_settings(xvid_mplayer_module_t *mod){ xvid_enc_create_t *create = &mod->create; xvid_enc_frame_t *frame = &mod->frame; xvid_plugin_single_t *onepass = &mod->onepass; xvid_plugin_2pass2_t *pass2 = &mod->pass2; AVRational ar; const int motion_presets[7] = { 0, 0, 0, 0, XVID_ME_HALFPELREFINE16, XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND16, XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | XVID_ME_HALFPELREFINE8 | XVID_ME_USESQUARES16 }; //profile is unrestricted as default profile_t *selected_profile = profileFromName("unrestricted"); if(xvidenc_profile) selected_profile = profileFromName(xvidenc_profile); if(!selected_profile) { mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid:[ERROR] \"%s\" is an invalid profile name\n", xvidenc_profile); return(BAD); } /* ------------------------------------------------------------------- * Dispatch all settings having an impact on the "create" structure * This includes plugins as they are passed to encore through the * create structure * -----------------------------------------------------------------*/ /* ------------------------------------------------------------------- * The create structure * ---------------------------------------------------------------- */ create->global = 0; if(xvidenc_psnr) xvidenc_stats = 1; if(xvidenc_stats) create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE; create->num_zones = 0; create->zones = NULL; create->num_plugins = 0; create->plugins = NULL; create->num_threads = xvidenc_num_threads; if( (selected_profile->flags & PROFILE_BVOP) && /* dxn: prevent bframes usage if interlacing is selected */ !((selected_profile->flags & PROFILE_DXN) && xvidenc_interlaced) ) { create->max_bframes = xvidenc_max_bframes; create->bquant_ratio = xvidenc_bquant_ratio; create->bquant_offset = xvidenc_bquant_offset; if(xvidenc_packed) create->global |= XVID_GLOBAL_PACKED; if(xvidenc_closed_gop) create->global |= XVID_GLOBAL_CLOSED_GOP; /* dxn: restrict max bframes, require closed gop and require packed b-frames */ if(selected_profile->flags & PROFILE_DXN) { if(create->max_bframes > selected_profile->dxn_max_bframes) create->max_bframes = selected_profile->dxn_max_bframes; create->global |= XVID_GLOBAL_CLOSED_GOP; create->global |= XVID_GLOBAL_PACKED; } } else create->max_bframes = 0;#if XVID_API >= XVID_MAKE_API(4,1) /* dxn: always write divx5 userdata */ if(selected_profile->flags & PROFILE_DXN) create->global |= XVID_GLOBAL_DIVX5_USERDATA;#endif create->max_key_interval = xvidenc_max_key_interval; create->frame_drop_ratio = xvidenc_frame_drop_ratio; create->min_quant[0] = xvidenc_min_quant[0]; create->min_quant[1] = xvidenc_min_quant[1]; create->min_quant[2] = xvidenc_min_quant[2]; create->max_quant[0] = xvidenc_max_quant[0]; create->max_quant[1] = xvidenc_max_quant[1]; create->max_quant[2] = xvidenc_max_quant[2]; /* ------------------------------------------------------------------- * The single pass plugin * ---------------------------------------------------------------- */ if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate; else onepass->bitrate = xvidenc_bitrate*1000; onepass->reaction_delay_factor = xvidenc_cbr_reaction_delay_factor; onepass->averaging_period = xvidenc_cbr_averaging_period; onepass->buffer = xvidenc_cbr_buffer; /* ------------------------------------------------------------------- * The pass2 plugin * ---------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?