static void enc_preprocess(MSFilter *f){ EncData *d=(EncData*)f->data; x264_param_t params; float bitrate; d->packer=rfc3984_new(); rfc3984_set_mode(d->packer,d->mode); rfc3984_enable_stap_a(d->packer,FALSE); x264_param_default(¶ms); params.i_threads=0; params.i_sync_lookahead=0; params.i_width=d->vsize.width; params.i_height=d->vsize.height; params.i_fps_num=(int)d->fps; params.i_fps_den=1; params.i_slice_max_size=ms_get_payload_max_size()-100; /*-100 security margin*/ params.i_level_idc=13; bitrate=(float)d->bitrate*0.92; if (bitrate>RC_MARGIN) bitrate-=RC_MARGIN; params.rc.i_rc_method = X264_RC_ABR; params.rc.i_bitrate=(int)(bitrate/1000); params.rc.f_rate_tolerance=0.1; params.rc.i_vbv_max_bitrate=(int) ((bitrate+RC_MARGIN/2)/1000); params.rc.i_vbv_buffer_size=params.rc.i_vbv_max_bitrate; params.rc.f_vbv_buffer_init=0.5; params.rc.i_lookahead=0; /*enable this by config ?*/ /* params.i_keyint_max = (int)d->fps*d->keyframe_int; params.i_keyint_min = (int)d->fps; */ params.b_repeat_headers=1; params.b_annexb=0; //these parameters must be set so that our stream is baseline params.analyse.b_transform_8x8 = 0; params.b_cabac = 0; params.i_cqm_preset = X264_CQM_FLAT; params.i_bframe = 0; params.analyse.i_weighted_pred = X264_WEIGHTP_NONE; x264_param_apply_preset(¶ms,"faster");//将编码设置成superfast模式【相比其他模式,会有一些花屏】 x264_param_apply_tune(¶ms,"zerolatency");//将延时设置成最短 d->enc=x264_encoder_open(¶ms); if (d->enc==NULL) ms_error("Fail to create x264 encoder."); d->framenum=0; video_starter_init(&d->starter); }
static void enc_preprocess(MSFilter *f){ EncData *d=(EncData*)f->data; x264_param_t *params=&d->params; d->packer=rfc3984_new(); rfc3984_set_mode(d->packer,d->mode); rfc3984_enable_stap_a(d->packer,FALSE); #if defined(__arm__) || defined(ANDROID) if (x264_param_default_preset(params,"superfast"/*"ultrafast"*/,"zerolatency")) { ms_error("Cannot apply default x264 configuration"); } #else x264_param_default(params); #endif params->i_threads=ms_get_cpu_count(); params->i_sync_lookahead=0; params->i_width=d->vconf.vsize.width; params->i_height=d->vconf.vsize.height; params->i_fps_num=(int)d->vconf.fps; params->i_fps_den=1; params->i_slice_max_size=ms_get_payload_max_size()-100; /*-100 security margin*/ params->i_level_idc=13; apply_bitrate(f); params->rc.i_lookahead=0; /*enable this by config ?*/ /* params.i_keyint_max = (int)d->fps*d->keyframe_int; params.i_keyint_min = (int)d->fps; */ params->b_repeat_headers=1; params->b_annexb=0; //these parameters must be set so that our stream is baseline params->analyse.b_transform_8x8 = 0; params->b_cabac = 0; params->i_cqm_preset = X264_CQM_FLAT; params->i_bframe = 0; params->analyse.i_weighted_pred = X264_WEIGHTP_NONE; d->enc=x264_encoder_open(params); if (d->enc==NULL) ms_error("Fail to create x264 encoder."); d->framenum=0; video_starter_init(&d->starter); }
static void enc_preprocess(MSFilter *f) { vpx_codec_err_t res; EncState *s=(EncState*)f->data; s->cfg.g_w = s->vconf.vsize.width; s->cfg.g_h = s->vconf.vsize.height; s->cfg.g_timebase.den=s->vconf.fps; /* Initialize codec */ #ifdef FRAGMENT_ON_PARTITIONS /* VPX_CODEC_USE_OUTPUT_PARTITION: output 1 frame per partition */ res = vpx_codec_enc_init(&s->codec, interface, &s->cfg, VPX_CODEC_USE_OUTPUT_PARTITION); #else res = vpx_codec_enc_init(&s->codec, interface, &s->cfg, 0); #endif if (res) { ms_error("vpx_codec_enc_init failed: %s (%s)n", vpx_codec_err_to_string(res), vpx_codec_error_detail(&s->codec)); } /*cpu/quality tradeoff: positive values decrease CPU usage at the expense of quality*/ vpx_codec_control(&s->codec, VP8E_SET_CPUUSED, (s->cfg.g_threads > 1) ? 10 : 10); vpx_codec_control(&s->codec, VP8E_SET_STATIC_THRESHOLD, 0); vpx_codec_control(&s->codec, VP8E_SET_ENABLEAUTOALTREF, 1); if (s->cfg.g_threads > 1) { if (vpx_codec_control(&s->codec, VP8E_SET_TOKEN_PARTITIONS, 2) != VPX_CODEC_OK) { ms_error("VP8: failed to set multiple token partition"); } else { ms_message("VP8: multiple token partitions used"); } } #ifdef FRAGMENT_ON_PARTITIONS vpx_codec_control(&s->codec, VP8E_SET_TOKEN_PARTITIONS, 0x3); s->token_partition_count = 8; #endif /* vpx_codec_control(&s->codec, VP8E_SET_CPUUSED, 0);*/ /* -16 (quality) .. 16 (speed) */ video_starter_init(&s->starter); s->ready=TRUE; }
static void enc_preprocess(MSFilter *f){ EncData *d=(EncData*)f->data; x264_param_t *params=&d->params; d->packer=rfc3984_new(); rfc3984_set_mode(d->packer,d->mode); rfc3984_enable_stap_a(d->packer,FALSE); #if defined(__arm__) || defined(ANDROID) if (x264_param_default_preset(params,"superfast"/*"ultrafast"*/,"zerolatency")) { #else x264_param_default(params); { #endif ms_error("Cannot apply default x264 configuration"); }; params->i_threads=ms_get_cpu_count(); params->i_sync_lookahead=0; params->i_width=d->vconf.vsize.width; params->i_height=d->vconf.vsize.height; params->i_fps_num=(int)d->vconf.fps; params->i_fps_den=1; params->i_slice_max_size=ms_get_payload_max_size()-100; /*-100 security margin*/ params->i_level_idc=13; apply_bitrate(f); params->rc.i_lookahead=0; /*enable this by config ?*/ /* params.i_keyint_max = (int)d->fps*d->keyframe_int; params.i_keyint_min = (int)d->fps; */ params->b_repeat_headers=1; params->b_annexb=0; //these parameters must be set so that our stream is baseline params->analyse.b_transform_8x8 = 0; params->b_cabac = 0; params->i_cqm_preset = X264_CQM_FLAT; params->i_bframe = 0; params->analyse.i_weighted_pred = X264_WEIGHTP_NONE; d->enc=x264_encoder_open(params); if (d->enc==NULL) ms_error("Fail to create x264 encoder."); d->framenum=0; video_starter_init(&d->starter); } static void x264_nals_to_msgb(x264_nal_t *xnals, int num_nals, MSQueue * nalus){ int i; mblk_t *m; /*int bytes;*/ for (i=0;i<num_nals;++i){ m=allocb(xnals[i].i_payload+10,0); memcpy(m->b_wptr,xnals[i].p_payload+4,xnals[i].i_payload-4); m->b_wptr+=xnals[i].i_payload-4; if (xnals[i].i_type==7) { ms_message("A SPS is being sent."); }else if (xnals[i].i_type==8) { ms_message("A PPS is being sent."); } ms_queue_put(nalus,m); } }