yading@10: /* yading@10: * Ratecontrol yading@10: * Copyright (c) 2000, 2001, 2002 Fabrice Bellard yading@10: * Copyright (c) 2002-2004 Michael Niedermayer yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: #ifndef AVCODEC_RATECONTROL_H yading@10: #define AVCODEC_RATECONTROL_H yading@10: yading@10: /** yading@10: * @file yading@10: * ratecontrol header. yading@10: */ yading@10: yading@10: #include yading@10: #include yading@10: #include "libavutil/eval.h" yading@10: yading@10: typedef struct Predictor{ yading@10: double coeff; yading@10: double count; yading@10: double decay; yading@10: } Predictor; yading@10: yading@10: typedef struct RateControlEntry{ yading@10: int pict_type; yading@10: float qscale; yading@10: int mv_bits; yading@10: int i_tex_bits; yading@10: int p_tex_bits; yading@10: int misc_bits; yading@10: int header_bits; yading@10: uint64_t expected_bits; yading@10: int new_pict_type; yading@10: float new_qscale; yading@10: int mc_mb_var_sum; yading@10: int mb_var_sum; yading@10: int i_count; yading@10: int skip_count; yading@10: int f_code; yading@10: int b_code; yading@10: }RateControlEntry; yading@10: yading@10: /** yading@10: * rate control context. yading@10: */ yading@10: typedef struct RateControlContext{ yading@10: int num_entries; ///< number of RateControlEntries yading@10: RateControlEntry *entry; yading@10: double buffer_index; ///< amount of bits in the video/audio buffer yading@10: Predictor pred[5]; yading@10: double short_term_qsum; ///< sum of recent qscales yading@10: double short_term_qcount; ///< count of recent qscales yading@10: double pass1_rc_eq_output_sum;///< sum of the output of the rc equation, this is used for normalization yading@10: double pass1_wanted_bits; ///< bits which should have been outputed by the pass1 code (including complexity init) yading@10: double last_qscale; yading@10: double last_qscale_for[5]; ///< last qscale for a specific pict type, used for max_diff & ipb factor stuff yading@10: int last_mc_mb_var_sum; yading@10: int last_mb_var_sum; yading@10: uint64_t i_cplx_sum[5]; yading@10: uint64_t p_cplx_sum[5]; yading@10: uint64_t mv_bits_sum[5]; yading@10: uint64_t qscale_sum[5]; yading@10: int frame_count[5]; yading@10: int last_non_b_pict_type; yading@10: yading@10: void *non_lavc_opaque; ///< context for non lavc rc code (for example xvid) yading@10: float dry_run_qscale; ///< for xvid rc yading@10: int last_picture_number; ///< for xvid rc yading@10: AVExpr * rc_eq_eval; yading@10: }RateControlContext; yading@10: yading@10: struct MpegEncContext; yading@10: yading@10: /* rate control */ yading@10: int ff_rate_control_init(struct MpegEncContext *s); yading@10: float ff_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); yading@10: void ff_write_pass1_stats(struct MpegEncContext *s); yading@10: void ff_rate_control_uninit(struct MpegEncContext *s); yading@10: int ff_vbv_update(struct MpegEncContext *s, int frame_size); yading@10: void ff_get_2pass_fcode(struct MpegEncContext *s); yading@10: yading@10: int ff_xvid_rate_control_init(struct MpegEncContext *s); yading@10: void ff_xvid_rate_control_uninit(struct MpegEncContext *s); yading@10: float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); yading@10: yading@10: #endif /* AVCODEC_RATECONTROL_H */