📄 encoderparams.cc
字号:
mjpeg_info( "Progressive format frames = %d", frame_pred_dct_tab[0] ); qscale_tab[0] = qscale_tab[1] = qscale_tab[2] = options.mpeg == 1 ? 0 : 1; intravlc_tab[0] = intravlc_tab[1] = intravlc_tab[2] = options.mpeg == 1 ? 0 : 1; altscan_tab[2] = altscan_tab[1] = altscan_tab[0] = (options.mpeg == 1 || options.hack_altscan_bug) ? 0 : 1; /* A.Stevens 2000: The search radius *has* to be a multiple of 8 for the new fast motion compensation search to work correctly. We simply round it up if needs be. */ int searchrad = options.searchrad; if(searchrad*M>127) { searchrad = 127/M; mjpeg_warn("Search radius reduced to %d",searchrad); } { int radius_x = searchrad; int radius_y = searchrad*vertical_size/horizontal_size; /* TODO: These f-codes should really be adjusted for each picture type... */ motion_data = (struct motion_data *)malloc(M*sizeof(struct motion_data)); if (!motion_data) mjpeg_error_exit1("malloc failed"); for (i=0; i<M; i++) { if(i==0) { motion_data[i].sxf = round_search_radius(radius_x*M); motion_data[i].forw_hor_f_code = f_code(motion_data[i].sxf); motion_data[i].syf = round_search_radius(radius_y*M); motion_data[i].forw_vert_f_code = f_code(motion_data[i].syf); } else { motion_data[i].sxf = round_search_radius(radius_x*i); motion_data[i].forw_hor_f_code = f_code(motion_data[i].sxf); motion_data[i].syf = round_search_radius(radius_y*i); motion_data[i].forw_vert_f_code = f_code(motion_data[i].syf); motion_data[i].sxb = round_search_radius(radius_x*(M-i)); motion_data[i].back_hor_f_code = f_code(motion_data[i].sxb); motion_data[i].syb = round_search_radius(radius_y*(M-i)); motion_data[i].back_vert_f_code = f_code(motion_data[i].syb); } /* MPEG-1 demands f-codes for vertical and horizontal axes are identical!!!! */ if( mpeg1 ) { motion_data[i].syf = motion_data[i].sxf; motion_data[i].syb = motion_data[i].sxb; motion_data[i].forw_vert_f_code = motion_data[i].forw_hor_f_code; motion_data[i].back_vert_f_code = motion_data[i].back_hor_f_code; } } } /* make sure MPEG specific parameters are valid */ RangeChecks(); /* Set the frame decode rate and frame display rates. For 3:2 movie pulldown decode rate is != display rate due to the repeated field that appears every other frame. */ frame_rate = Y4M_RATIO_DBL(mpeg_framerate(frame_rate_code)); if( options.vid32_pulldown ) { decode_frame_rate = frame_rate * (2.0 + 2.0) / (3.0 + 2.0); mjpeg_info( "3:2 Pulldown selected frame decode rate = %3.3f fps", decode_frame_rate); } else decode_frame_rate = frame_rate; if ( !mpeg1) { ProfileAndLevelChecks(); } else { /* MPEG-1 */ if (constrparms) { if (horizontal_size>768 || vertical_size>576 || ((horizontal_size+15)/16)*((vertical_size+15)/16)>396 || ((horizontal_size+15)/16)*((vertical_size+15)/16)*frame_rate>396*25.0 || frame_rate>30.0) { mjpeg_info( "size - setting constrained_parameters_flag = 0"); constrparms = 0; } } if (constrparms) { for (i=0; i<M; i++) { if (motion_data[i].forw_hor_f_code>4) { mjpeg_info("Hor. motion search forces constrained_parameters_flag = 0"); constrparms = 0; break; } if (motion_data[i].forw_vert_f_code>4) { mjpeg_info("Ver. motion search forces constrained_parameters_flag = 0"); constrparms = 0; break; } if (i!=0) { if (motion_data[i].back_hor_f_code>4) { mjpeg_info("Hor. motion search setting constrained_parameters_flag = 0"); constrparms = 0; break; } if (motion_data[i].back_vert_f_code>4) { mjpeg_info("Ver. motion search setting constrained_parameters_flag = 0"); constrparms = 0; break; } } } } } /* relational checks */ if ( mpeg1 ) { if (!prog_seq) { mjpeg_warn("mpeg1 specified - setting progressive_sequence = 1"); prog_seq = 1; } if (dc_prec!=0) { mjpeg_info("mpeg1 - setting intra_dc_precision = 0"); dc_prec = 0; } for (i=0; i<3; i++) if (qscale_tab[i]) { mjpeg_info("mpeg1 - setting qscale_tab[%d] = 0",i); qscale_tab[i] = 0; } for (i=0; i<3; i++) if (intravlc_tab[i]) { mjpeg_info("mpeg1 - setting intravlc_tab[%d] = 0",i); intravlc_tab[i] = 0; } for (i=0; i<3; i++) if (altscan_tab[i]) { mjpeg_info("mpeg1 - setting altscan_tab[%d] = 0",i); altscan_tab[i] = 0; } } if ( !mpeg1 && constrparms) { mjpeg_info("not mpeg1 - setting constrained_parameters_flag = 0"); constrparms = 0; } if( (!prog_seq || fieldpic != 0 ) && ( (vertical_size+15) / 16)%2 != 0 ) { mjpeg_warn( "Frame height won't split into two equal field pictures..."); mjpeg_warn( "forcing encoding as progressive video"); prog_seq = 1; fieldpic = 0; } if (prog_seq && fieldpic != 0) { mjpeg_info("prog sequence - forcing progressive frame encoding"); fieldpic = 0; } if (prog_seq && topfirst ) { mjpeg_info("prog sequence setting top_field_first = 0"); topfirst = 0; } /* search windows */ for (i=0; i<M; i++) { if (motion_data[i].sxf > (4U<<motion_data[i].forw_hor_f_code)-1) { mjpeg_info( "reducing forward horizontal search width to %d", (4<<motion_data[i].forw_hor_f_code)-1); motion_data[i].sxf = (4U<<motion_data[i].forw_hor_f_code)-1; } if (motion_data[i].syf > (4U<<motion_data[i].forw_vert_f_code)-1) { mjpeg_info( "reducing forward vertical search width to %d", (4<<motion_data[i].forw_vert_f_code)-1); motion_data[i].syf = (4U<<motion_data[i].forw_vert_f_code)-1; } if (i!=0) { if (motion_data[i].sxb > (4U<<motion_data[i].back_hor_f_code)-1) { mjpeg_info( "reducing backward horizontal search width to %d", (4<<motion_data[i].back_hor_f_code)-1); motion_data[i].sxb = (4U<<motion_data[i].back_hor_f_code)-1; } if (motion_data[i].syb > (4U<<motion_data[i].back_vert_f_code)-1) { mjpeg_info( "reducing backward vertical search width to %d", (4<<motion_data[i].back_vert_f_code)-1); motion_data[i].syb = (4U<<motion_data[i].back_vert_f_code)-1; } } } InitQuantMatrices( options ); InitEncodingControls( options );}/* If the use has selected suppression of hf noise via quantisation then we boost quantisation of hf components EXPERIMENTAL: currently a linear ramp from 0 at 4pel to hf_q_boost increased quantisation...*/static int quant_hfnoise_filt(int orgquant, int qmat_pos, double hf_q_boost ) { int orgdist = MAX(qmat_pos % 8, qmat_pos/8); double qboost; /* Maximum hf_q_boost quantisation boost for HF components.. */ qboost = 1.0 + ((hf_q_boost * orgdist) / 8); return static_cast<int>(orgquant * qboost); }void EncoderParams::InitQuantMatrices( const MPEG2EncOptions &options ){ int i, v; const char *msg = NULL; const uint16_t *qmat = 0; const uint16_t *niqmat = 0; load_iquant = 0; load_niquant = 0; /* bufalloc to ensure alignment */ intra_q = static_cast<uint16_t*>(bufalloc(sizeof(uint16_t[64]))); inter_q = static_cast<uint16_t*>(bufalloc(sizeof(uint16_t[64]))); switch (options.hf_quant) { case 0: /* No -N, -H or -K used. Default matrices */ msg = "Using default unmodified quantization matrices"; qmat = default_intra_quantizer_matrix; niqmat = default_nonintra_quantizer_matrix; break; case 1: /* "-N value" used but not -K or -H */ msg = "Using -N modified default quantization matrices"; qmat = default_intra_quantizer_matrix; niqmat = default_nonintra_quantizer_matrix; load_iquant = 1; load_niquant = 1; break; case 2: /* -H used OR -H followed by "-N value" */ msg = "Setting hi-res intra Quantisation matrix"; qmat = hires_intra_quantizer_matrix; niqmat = hires_nonintra_quantizer_matrix; load_iquant = 1; if(options.hf_q_boost) load_niquant = 1; /* Custom matrix if -N used */ break; case 3: msg = "KVCD Notch Quantization Matrix"; qmat = kvcd_intra_quantizer_matrix; niqmat = kvcd_nonintra_quantizer_matrix; load_iquant = 1; load_niquant = 1; break; case 4: msg = "TMPGEnc Quantization matrix"; qmat = tmpgenc_intra_quantizer_matrix; niqmat = tmpgenc_nonintra_quantizer_matrix; load_iquant = 1; load_niquant = 1; break; case 5: /* -K file=qmatrixfilename */ msg = "Loading custom matrices from user specified file"; load_iquant = 1; load_niquant = 1; qmat = options.custom_intra_quantizer_matrix; niqmat = options.custom_nonintra_quantizer_matrix; break; default: mjpeg_error_exit1("Help! Unknown hf_quant value %d", options.hf_quant); /* NOTREACHED */ } if (msg) mjpeg_info(msg); for (i = 0; i < 64; i++) { v = quant_hfnoise_filt(qmat[i], i, options.hf_q_boost); if (v < 1 || v > 255) mjpeg_error_exit1("bad intra value after -N adjust"); intra_q[i] = v; v = quant_hfnoise_filt(niqmat[i], i, options.hf_q_boost); if (v < 1 || v > 255) mjpeg_error_exit1("bad nonintra value after -N adjust"); inter_q[i] = v; }}/* * Local variables: * c-file-style: "stroustrup" * tab-width: 4 * indent-tabs-mode: nil * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -