68 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
71 1, 2, 3, 5, 4, 10, 9, 8,
72 11, 15, 17, 16, 23, 22, 21, 20,
73 19, 18, 25, 24, 27, 26, 11, 7,
74 6, 1, 2, 13, 2, 2, 2, 2,
75 6, 12, 3, 9, 1, 3, 4, 3,
76 7, 4, 1, 1, 5, 5, 14, 6,
77 1, 7, 1, 8, 1, 1, 1, 1,
78 10, 1, 1, 5, 9, 17, 25, 24,
79 29, 33, 32, 41, 2, 23, 28, 31,
80 3, 22, 30, 4, 27, 40, 8, 26,
81 6, 39, 7, 38, 16, 37, 15, 10,
82 11, 12, 13, 14, 1, 21, 20, 18,
107 int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
108 int best_clock_code=1;
110 int best_error= INT_MAX;
116 div= av_clip(div, 1, 127);
118 if(error < best_error){
125 s->
custom_pcf= best_clock_code!=1 || best_divisor!=60;
126 coded_frame_rate= 1800000;
127 coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
232 assert(s->
mb_x == 0 && s->
mb_y == 0);
282 for(i=1; i<s->
mb_num; i++){
286 for(i=s->
mb_num-2; i>=0; i--){
292 for(i=1; i<s->
mb_num; i++){
311 int level,
run, last, i, j, last_index, last_non_zero, sign, slevel, code;
324 else if (level < 1) {
340 int inter_vlc_bits=0;
345 last_non_zero = i - 1;
346 for (; i <= last_index; i++) {
350 run = i - last_non_zero - 1;
351 last = (i == last_index);
353 if(level<0) level= -
level;
357 inter_vlc_bits += rl->
table_vlc[code][1]+1;
361 inter_vlc_bits += 1+6+8-1;
364 aic_vlc_bits += 1+6+8-1;
365 wrong_pos += run + 1;
372 if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63)
379 last_non_zero = i - 1;
380 for (; i <= last_index; i++) {
384 run = i - last_non_zero - 1;
385 last = (i == last_index);
437 sval = ((val < 0) ? (
short)(-val):(
short)val);
440 while (temp_val != 0) {
441 temp_val = temp_val >> 1;
447 tcode = (sval & (1 << (i-1))) >> (i-1);
448 tcode = (tcode << 1) | 1;
449 code = (code << 2) | tcode;
452 code = ((code << 1) | (val < 0)) << 1;
459 int motion_x,
int motion_y)
461 int cbpc, cbpy, i, cbp, pred_x, pred_y;
463 int16_t rec_intradc[6];
469 cbp=
get_p_cbp(s, block, motion_x, motion_y);
474 if(interleaved_stats){
498 if(interleaved_stats){
507 motion_y - pred_y, 1);
512 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
524 if(interleaved_stats){
536 motion_y - pred_y, 1);
541 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
548 if(interleaved_stats){
558 int16_t
level = block[i][0];
568 level = (level + (scale>>1))/
scale;
570 level = (level - (scale>>1))/
scale;
579 else if (level > 127)
585 rec_intradc[i] = scale*level + pred_dc;
591 if (rec_intradc[i] < 0)
593 else if (rec_intradc[i] > 2047)
594 rec_intradc[i] = 2047;
597 *dc_ptr[i] = rec_intradc[i];
631 if(interleaved_stats){
642 block[i][0] = rec_intradc[i];
647 if(interleaved_stats){
660 int range, bit_size, sign, code,
bits;
667 bit_size = f_code - 1;
668 range = 1 << bit_size;
672 val= (val^sign)-sign;
676 code = (val >> bit_size) + 1;
677 bits = val & (range - 1);
691 for(f_code=1; f_code<=
MAX_FCODE; f_code++){
697 int val, bit_size, code;
699 bit_size = f_code - 1;
705 code = (val >> bit_size) + 1;
707 len=
ff_mvtab[code][1] + 1 + bit_size;
717 for(f_code=
MAX_FCODE; f_code>0; f_code--){
718 for(mv=-(16<<f_code); mv<(16<<f_code); mv++){
723 for(mv=0; mv<
MAX_MV*2+1; mv++){
729 int slevel,
run, last;
734 for(slevel=-64; slevel<64; slevel++){
735 if(slevel==0)
continue;
736 for(run=0; run<64; run++){
737 for(last=0; last<=1; last++){
739 int level= slevel < 0 ? -slevel : slevel;
740 int sign= slevel < 0 ? 1 : 0;
749 bits=bits*2+sign; len++;
751 if(code!=rl->
n && len < len_tab[index]){
758 bits=bits*2+last; len++;
759 bits=bits*64+
run; len+=6;
760 bits=bits*256+(level&0xff); len+=8;
762 if(len < len_tab[index]){
static const int dquant_code[5]
uint8_t * fcode_tab
smallest fcode needed for each MV
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_uni_h263_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab)
const uint8_t ff_h263_intra_MCBPC_code[9]
const uint8_t ff_h263_cbpy_tab[16][2]
void ff_init_rl(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
int obmc
overlapped block motion compensation
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int min_qcoeff
minimum encodable coefficient
#define UNI_MPEG4_ENC_INDEX(last, run, level)
uint8_t * intra_ac_vlc_length
const uint16_t ff_h263_format[8][2]
int mb_num
number of MBs of a picture
static int get_p_cbp(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
void ff_h263_encode_motion(MpegEncContext *s, int val, int f_code)
void ff_h263_encode_gob_header(MpegEncContext *s, int mb_line)
Encode a group of blocks header.
void ff_h263_encode_mba(MpegEncContext *s)
int h263_aic
Advanded INTRA Coding (AIC)
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static uint8_t uni_h263_inter_rl_len[64 *64 *2 *2]
int alt_inter_vlc
alternative inter vlc
const uint8_t ff_h263_intra_MCBPC_bits[9]
const uint8_t ff_mvtab[33][2]
int misc_bits
cbp, mb_type
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
const uint8_t ff_h263_inter_MCBPC_bits[28]
Picture current_picture
copy of the current picture structure.
uint8_t(* mv_penalty)[MAX_MV *2+1]
amount of bits needed to encode a MV
static void h263p_encode_umotion(MpegEncContext *s, int val)
void ff_init_qscale_tab(MpegEncContext *s)
init s->current_picture.qscale_table from s->lambda_table
int ff_h263_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr)
int max_qcoeff
maximum encodable coefficient
const AVRational ff_h263_pixel_aspect[16]
int dquant
qscale difference to prev qscale
static int get_bits_diff(MpegEncContext *s)
#define FF_ASPECT_EXTENDED
int h263_plus
h263 plus headers
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
uint8_t * inter_ac_vlc_last_length
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last)
static uint8_t fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need.
int h263_slice_structured
#define CANDIDATE_MB_TYPE_INTER
uint16_t * mb_type
Table for candidate MB types for encoding.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
uint8_t * intra_ac_vlc_last_length
struct AVRational AVRational
rational number numerator/denominator
int n
number of entries of table_vlc minus 1
const uint16_t(* table_vlc)[2]
int umvplus
== H263+ && unrestricted_mv
#define CANDIDATE_MB_TYPE_INTER4V
int block_last_index[12]
last non zero coefficient in block
const uint8_t ff_aic_dc_scale_table[32]
const uint8_t ff_h263_inter_MCBPC_code[28]
int ac_esc_length
num of bits needed to encode the longest esc
static void h263_encode_block(MpegEncContext *s, DCTELEM *block, int n)
Encode an 8x8 block.
int block_index[6]
index to current MB in block based arrays with edges
int * mb_index2xy
mb_index -> mb_x + mb_y*mb_stride
static const int8_t mv[256][2]
#define MV_TYPE_16X16
1 vector for the whole mb
int h263_flv
use flv h263 header
uint8_t ff_h263_static_rl_table_store[2][2][2 *MAX_RUN+MAX_LEVEL+3]
static void init_mv_penalty_and_fcode(MpegEncContext *s)
static uint8_t umv_fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need in umv.
void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number)
ScanTable intra_scantable
int height
picture size. must be a multiple of 16
const uint8_t ff_mpeg1_dc_scale_table[128]
int16_t(*[2] motion_val)[2]
motion vector table
uint8_t * inter_ac_vlc_length
static const uint8_t wrong_run[102]
#define FF_ARRAY_ELEMS(a)
rational number numerator/denominator
static void ff_h263_encode_motion_vector(MpegEncContext *s, int x, int y, int f_code)
static uint8_t uni_h263_intra_aic_rl_len[64 *64 *2 *2]
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
static av_const int sign_extend(int val, unsigned bits)
static const uint16_t scale[4]
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
int8_t * qscale_table
QP table.
struct AVCodecContext * avctx
PutBitContext pb
bit output
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
common internal api header.
void ff_h263_encode_init(MpegEncContext *s)
av_const int ff_h263_aspect_to_info(AVRational aspect)
Return the 4 bit value that specifies the given aspect ratio.
static int get_rl_index(const RLTable *rl, int last, int run, int level)
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is acually possible in h263 (limit difference to -2..2)
int last_bits
temp var used for calculating the above vars
void ff_h263_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
int flags
AVCodecContext.flags (HQ, MV4, ...)
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
Return the index into tab at which {a,b} match elements {[0],[1]} of tab.