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