00001 /* 00002 * Ratecontrol 00003 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard 00004 * Copyright (c) 2002-2004 Michael Niedermayer 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * FFmpeg is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with FFmpeg; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef AVCODEC_RATECONTROL_H 00024 #define AVCODEC_RATECONTROL_H 00025 00031 #include <stdio.h> 00032 #include <stdint.h> 00033 #include "libavutil/eval.h" 00034 00035 typedef struct Predictor{ 00036 double coeff; 00037 double count; 00038 double decay; 00039 } Predictor; 00040 00041 typedef struct RateControlEntry{ 00042 int pict_type; 00043 float qscale; 00044 int mv_bits; 00045 int i_tex_bits; 00046 int p_tex_bits; 00047 int misc_bits; 00048 int header_bits; 00049 uint64_t expected_bits; 00050 int new_pict_type; 00051 float new_qscale; 00052 int mc_mb_var_sum; 00053 int mb_var_sum; 00054 int i_count; 00055 int skip_count; 00056 int f_code; 00057 int b_code; 00058 }RateControlEntry; 00059 00063 typedef struct RateControlContext{ 00064 FILE *stats_file; 00065 int num_entries; 00066 RateControlEntry *entry; 00067 double buffer_index; 00068 Predictor pred[5]; 00069 double short_term_qsum; 00070 double short_term_qcount; 00071 double pass1_rc_eq_output_sum; 00072 double pass1_wanted_bits; 00073 double last_qscale; 00074 double last_qscale_for[5]; 00075 int last_mc_mb_var_sum; 00076 int last_mb_var_sum; 00077 uint64_t i_cplx_sum[5]; 00078 uint64_t p_cplx_sum[5]; 00079 uint64_t mv_bits_sum[5]; 00080 uint64_t qscale_sum[5]; 00081 int frame_count[5]; 00082 int last_non_b_pict_type; 00083 00084 void *non_lavc_opaque; 00085 float dry_run_qscale; 00086 int last_picture_number; 00087 AVExpr * rc_eq_eval; 00088 }RateControlContext; 00089 00090 struct MpegEncContext; 00091 00092 /* rate control */ 00093 int ff_rate_control_init(struct MpegEncContext *s); 00094 float ff_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); 00095 void ff_write_pass1_stats(struct MpegEncContext *s); 00096 void ff_rate_control_uninit(struct MpegEncContext *s); 00097 int ff_vbv_update(struct MpegEncContext *s, int frame_size); 00098 void ff_get_2pass_fcode(struct MpegEncContext *s); 00099 00100 int ff_xvid_rate_control_init(struct MpegEncContext *s); 00101 void ff_xvid_rate_control_uninit(struct MpegEncContext *s); 00102 float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); 00103 00104 #endif /* AVCODEC_RATECONTROL_H */ 00105