FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ratecontrol.h
Go to the documentation of this file.
1 /*
2  * Ratecontrol
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef AVCODEC_RATECONTROL_H
24 #define AVCODEC_RATECONTROL_H
25 
26 /**
27  * @file
28  * ratecontrol header.
29  */
30 
31 #include <stdio.h>
32 #include <stdint.h>
33 #include "libavutil/eval.h"
34 
35 typedef struct Predictor{
36  double coeff;
37  double count;
38  double decay;
39 } Predictor;
40 
41 typedef struct RateControlEntry{
42  int pict_type;
43  float qscale;
44  int mv_bits;
47  int misc_bits;
49  uint64_t expected_bits;
51  float new_qscale;
52  int64_t mc_mb_var_sum;
53  int64_t mb_var_sum;
54  int i_count;
56  int f_code;
57  int b_code;
59 
60 /**
61  * rate control context.
62  */
63 typedef struct RateControlContext{
64  int num_entries; ///< number of RateControlEntries
66  double buffer_index; ///< amount of bits in the video/audio buffer
68  double short_term_qsum; ///< sum of recent qscales
69  double short_term_qcount; ///< count of recent qscales
70  double pass1_rc_eq_output_sum;///< sum of the output of the rc equation, this is used for normalization
71  double pass1_wanted_bits; ///< bits which should have been outputed by the pass1 code (including complexity init)
72  double last_qscale;
73  double last_qscale_for[5]; ///< last qscale for a specific pict type, used for max_diff & ipb factor stuff
75  int64_t last_mb_var_sum;
76  uint64_t i_cplx_sum[5];
77  uint64_t p_cplx_sum[5];
78  uint64_t mv_bits_sum[5];
79  uint64_t qscale_sum[5];
80  int frame_count[5];
82 
83  void *non_lavc_opaque; ///< context for non lavc rc code (for example xvid)
84  float dry_run_qscale; ///< for xvid rc
85  int last_picture_number; ///< for xvid rc
88 
89 struct MpegEncContext;
90 
91 /* rate control */
93 float ff_rate_estimate_qscale(struct MpegEncContext *s, int dry_run);
96 int ff_vbv_update(struct MpegEncContext *s, int frame_size);
97 void ff_get_2pass_fcode(struct MpegEncContext *s);
98 
101 float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run);
102 
103 #endif /* AVCODEC_RATECONTROL_H */
Predictor
Definition: huffyuv.h:48
const char * s
Definition: avisynth_c.h:631
rate control context.
Definition: ratecontrol.h:63
double pass1_rc_eq_output_sum
sum of the output of the rc equation, this is used for normalization
Definition: ratecontrol.h:70
RateControlEntry * entry
Definition: ratecontrol.h:65
double count
Definition: ratecontrol.h:37
void ff_write_pass1_stats(struct MpegEncContext *s)
Definition: ratecontrol.c:42
Definition: eval.c:148
int num_entries
number of RateControlEntries
Definition: ratecontrol.h:64
int64_t last_mb_var_sum
Definition: ratecontrol.h:75
float dry_run_qscale
for xvid rc
Definition: ratecontrol.h:84
float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run)
Definition: libxvid_rc.c:101
AVExpr * rc_eq_eval
Definition: ratecontrol.h:86
int ff_xvid_rate_control_init(struct MpegEncContext *s)
Definition: libxvid_rc.c:42
double pass1_wanted_bits
bits which should have been outputed by the pass1 code (including complexity init) ...
Definition: ratecontrol.h:71
int frame_size
Definition: mxfenc.c:1821
void ff_rate_control_uninit(struct MpegEncContext *s)
Definition: ratecontrol.c:312
double buffer_index
amount of bits in the video/audio buffer
Definition: ratecontrol.h:66
double decay
Definition: ratecontrol.h:38
double coeff
Definition: ratecontrol.h:36
int64_t last_mc_mb_var_sum
Definition: ratecontrol.h:74
int ff_vbv_update(struct MpegEncContext *s, int frame_size)
Definition: ratecontrol.c:326
int ff_rate_control_init(struct MpegEncContext *s)
Definition: ratecontrol.c:84
int last_picture_number
for xvid rc
Definition: ratecontrol.h:85
uint64_t p_cplx_sum[5]
Definition: ratecontrol.h:77
double last_qscale_for[5]
last qscale for a specific pict type, used for max_diff & ipb factor stuff
Definition: ratecontrol.h:73
uint64_t i_cplx_sum[5]
Definition: ratecontrol.h:76
double short_term_qsum
sum of recent qscales
Definition: ratecontrol.h:68
MpegEncContext.
Definition: mpegvideo.h:78
uint64_t mv_bits_sum[5]
Definition: ratecontrol.h:78
void ff_xvid_rate_control_uninit(struct MpegEncContext *s)
Definition: libxvid_rc.c:158
void * non_lavc_opaque
context for non lavc rc code (for example xvid)
Definition: ratecontrol.h:83
float ff_rate_estimate_qscale(struct MpegEncContext *s, int dry_run)
Definition: ratecontrol.c:753
uint64_t qscale_sum[5]
Definition: ratecontrol.h:79
int64_t mc_mb_var_sum
Definition: ratecontrol.h:52
int64_t mb_var_sum
Definition: ratecontrol.h:53
void ff_get_2pass_fcode(struct MpegEncContext *s)
Definition: ratecontrol.c:742
uint64_t expected_bits
Definition: ratecontrol.h:49
double short_term_qcount
count of recent qscales
Definition: ratecontrol.h:69
Predictor pred[5]
Definition: ratecontrol.h:67
simple arithmetic expression evaluator