808
|
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 ratecontrol.h
|
|
28 * ratecontrol header.
|
|
29 */
|
|
30
|
|
31 typedef struct Predictor{
|
|
32 double coeff;
|
|
33 double count;
|
|
34 double decay;
|
|
35 } Predictor;
|
|
36
|
|
37 typedef struct RateControlEntry{
|
|
38 int pict_type;
|
|
39 float qscale;
|
|
40 int mv_bits;
|
|
41 int i_tex_bits;
|
|
42 int p_tex_bits;
|
|
43 int misc_bits;
|
|
44 int header_bits;
|
|
45 uint64_t expected_bits;
|
|
46 int new_pict_type;
|
|
47 float new_qscale;
|
|
48 int mc_mb_var_sum;
|
|
49 int mb_var_sum;
|
|
50 int i_count;
|
|
51 int skip_count;
|
|
52 int f_code;
|
|
53 int b_code;
|
|
54 }RateControlEntry;
|
|
55
|
|
56 /**
|
|
57 * rate control context.
|
|
58 */
|
|
59 typedef struct RateControlContext{
|
|
60 FILE *stats_file;
|
|
61 int num_entries; ///< number of RateControlEntries
|
|
62 RateControlEntry *entry;
|
|
63 double buffer_index; ///< amount of bits in the video/audio buffer
|
|
64 Predictor pred[5];
|
|
65 double short_term_qsum; ///< sum of recent qscales
|
|
66 double short_term_qcount; ///< count of recent qscales
|
|
67 double pass1_rc_eq_output_sum;///< sum of the output of the rc equation, this is used for normalization
|
|
68 double pass1_wanted_bits; ///< bits which should have been outputed by the pass1 code (including complexity init)
|
|
69 double last_qscale;
|
|
70 double last_qscale_for[5]; ///< last qscale for a specific pict type, used for max_diff & ipb factor stuff
|
|
71 int last_mc_mb_var_sum;
|
|
72 int last_mb_var_sum;
|
|
73 uint64_t i_cplx_sum[5];
|
|
74 uint64_t p_cplx_sum[5];
|
|
75 uint64_t mv_bits_sum[5];
|
|
76 uint64_t qscale_sum[5];
|
|
77 int frame_count[5];
|
|
78 int last_non_b_pict_type;
|
|
79
|
|
80 void *non_lavc_opaque; ///< context for non lavc rc code (for example xvid)
|
|
81 float dry_run_qscale; ///< for xvid rc
|
|
82 int last_picture_number; ///< for xvid rc
|
|
83 }RateControlContext;
|
|
84
|
|
85 struct MpegEncContext;
|
|
86
|
|
87 /* rate control */
|
|
88 int ff_rate_control_init(struct MpegEncContext *s);
|
|
89 float ff_rate_estimate_qscale(struct MpegEncContext *s, int dry_run);
|
|
90 void ff_write_pass1_stats(struct MpegEncContext *s);
|
|
91 void ff_rate_control_uninit(struct MpegEncContext *s);
|
|
92 int ff_vbv_update(struct MpegEncContext *s, int frame_size);
|
|
93 void ff_get_2pass_fcode(struct MpegEncContext *s);
|
|
94
|
|
95 int ff_xvid_rate_control_init(struct MpegEncContext *s);
|
|
96 void ff_xvid_rate_control_uninit(struct MpegEncContext *s);
|
|
97 float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run);
|
|
98
|
|
99 #endif /* AVCODEC_RATECONTROL_H */
|
|
100
|