Commit 8b4c7dbc authored by Michael Niedermayer's avatar Michael Niedermayer

fixed ratecontrol & b-frames

2pass ratecontrol
fixed hq with 2pass
inceased build num (a few more vars for the rc stuff)
hopefully no new bugs

Originally committed as revision 408 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 2c029cd1
......@@ -6,7 +6,8 @@ LDFLAGS= -g
OBJS= common.o utils.o mpegvideo.o h263.o jrevdct.o jfdctfst.o \
mpegaudio.o ac3enc.o mjpeg.o resample.o dsputil.o \
motion_est.o imgconvert.o imgresample.o msmpeg4.o \
mpeg12.o h263dec.o rv10.o mpegaudiodec.o pcm.o simple_idct.o
mpeg12.o h263dec.o rv10.o mpegaudiodec.o pcm.o simple_idct.o \
ratecontrol.o
ASM_OBJS=
# currently using libac3 for ac3 decoding
......
......@@ -5,8 +5,8 @@
#define LIBAVCODEC_VERSION_INT 0x000406
#define LIBAVCODEC_VERSION "0.4.6"
#define LIBAVCODEC_BUILD 4600
#define LIBAVCODEC_BUILD_STR "4600"
#define LIBAVCODEC_BUILD 4601
#define LIBAVCODEC_BUILD_STR "4601"
enum CodecID {
CODEC_ID_NONE,
......@@ -90,7 +90,9 @@ static const int Motion_Est_QTab[] = { 1, 4, 3, 6, 5, 2 };
#define CODEC_FLAG_TYPE 0x0040 /* fixed I/P frame type, from avctx->key_frame */
/* parent program gurantees that the input for b-frame containing streams is not written to
for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
#define CODEC_FLAG_INPUT_PRESERVED 0x0100
#define CODEC_FLAG_INPUT_PRESERVED 0x0100
#define CODEC_FLAG_PASS1 0x0200 /* use internal 2pass ratecontrol in first pass mode */
#define CODEC_FLAG_PASS2 0x0400 /* use internal 2pass ratecontrol in second pass mode */
/* codec capabilities */
......@@ -139,13 +141,18 @@ typedef struct AVCodecContext {
int key_frame; /* true if the previous compressed frame was
a key frame (intra, or seekable) */
int quality; /* quality of the previous encoded frame
(between 1 (good) and 31 (bad)) */
(between 1 (good) and 31 (bad))
this is allso used to set the quality in vbr mode
and the per frame quality in CODEC_FLAG_TYPE (second pass mode) */
float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
int qmin; /* min qscale */
int qmax; /* max qscale */
int max_qdiff; /* max qscale difference between frames */
int max_b_frames; /* maximum b frames, the output will be delayed by max_b_frames+1 relative to the input */
float b_quant_factor;/* qscale factor between ips and b frames */
int rc_strategy;
int b_frame_strategy;
struct AVCodec *codec;
void *priv_data;
......
This diff is collapsed.
......@@ -44,6 +44,24 @@ typedef struct Predictor{
double decay;
} Predictor;
typedef struct RateControlEntry{
int pict_type;
int qscale;
int mv_bits;
int i_tex_bits;
int p_tex_bits;
int misc_bits;
uint64_t expected_bits;
int new_pict_type;
float new_qscale;
}RateControlEntry;
typedef struct RateControlContext{
FILE *stats_file;
int num_entries;
RateControlEntry *entry;
}RateControlContext;
typedef struct ReorderBuffer{
UINT8 *picture[3];
int pict_type;
......@@ -78,6 +96,9 @@ typedef struct MpegEncContext {
int flags; /* AVCodecContext.flags (HQ, MV4, ...) */
int force_input_type;/* 0= no force, otherwise I_TYPE, P_TYPE, ... */
int max_b_frames; /* max number of b-frames for encoding */
float b_quant_factor;/* qscale factor between ips and b frames */
int rc_strategy;
int b_frame_strategy;
/* the following fields are managed internally by the encoder */
/* bit output */
......@@ -121,9 +142,9 @@ typedef struct MpegEncContext {
int input_pict_type; /* pict_type prior to reordering of frames */
int force_type; /* 0= no force, otherwise I_TYPE, P_TYPE, ... */
int qscale; /* QP */
int last_non_b_qscale; /* QP of last non b frame used for b frame qscale*/
int pict_type; /* I_TYPE, P_TYPE, B_TYPE, ... */
int last_non_b_pict_type; /* used for mpeg4 gmc b-frames */
int last_pict_type; /* used for bit rate stuff (needs that to update the right predictor) */
int last_non_b_pict_type; /* used for mpeg4 gmc b-frames & ratecontrol */
int frame_rate_index;
/* motion compensation */
int unrestricted_mv;
......@@ -195,7 +216,7 @@ typedef struct MpegEncContext {
int q_intra_matrix[64];
int q_non_intra_matrix[64];
/* identical to the above but for MMX & these are not permutated */
UINT16 __align8 q_intra_matrix16[64] ;
UINT16 __align8 q_intra_matrix16[64];
UINT16 __align8 q_non_intra_matrix16[64];
int block_last_index[6]; /* last non zero coefficient in block */
......@@ -204,18 +225,19 @@ typedef struct MpegEncContext {
/* bit rate control */
int I_frame_bits; //FIXME used in mpeg12 ...
int avg_mb_var; /* average MB variance for current frame */
int mc_mb_var; /* motion compensated MB variance for current frame */
int last_mc_mb_var; /* motion compensated MB variance for last frame */
int mc_mb_var; /* motion compensated MB variance for current frame */
int last_non_b_mc_mb_var;/* motion compensated MB variance for last non b frame */
INT64 wanted_bits;
INT64 total_bits;
int frame_bits; /* bits used for the current frame */
int last_frame_bits; /* bits used for the last frame */
int frame_bits; /* bits used for the current frame */
int pb_frame_bits; /* bits of the last b...bp group */
Predictor i_pred;
Predictor p_pred;
double qsum; /* sum of qscales */
double qcount; /* count of qscales */
double short_term_qsum; /* sum of recent qscales */
double short_term_qcount; /* count of recent qscales */
RateControlContext rc_context;
/* statistics, used for 2-pass encoding */
int mv_bits;
......@@ -459,3 +481,14 @@ void mjpeg_encode_mb(MpegEncContext *s,
DCTELEM block[6][64]);
void mjpeg_picture_header(MpegEncContext *s);
void mjpeg_picture_trailer(MpegEncContext *s);
/* rate control */
int ff_rate_control_init(MpegEncContext *s);
int ff_rate_estimate_qscale(MpegEncContext *s);
int ff_rate_estimate_qscale_pass2(MpegEncContext *s);
void ff_write_pass1_stats(MpegEncContext *s);
void ff_rate_control_uninit(MpegEncContext *s);
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment