Go to the documentation of this file.
67 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
70 1, 2, 3, 5, 4, 10, 9, 8,
71 11, 15, 17, 16, 23, 22, 21, 20,
72 19, 18, 25, 24, 27, 26, 11, 7,
73 6, 1, 2, 13, 2, 2, 2, 2,
74 6, 12, 3, 9, 1, 3, 4, 3,
75 7, 4, 1, 1, 5, 5, 14, 6,
76 1, 7, 1, 8, 1, 1, 1, 1,
77 10, 1, 1, 5, 9, 17, 25, 24,
78 29, 33, 32, 41, 2, 23, 28, 31,
79 3, 22, 30, 4, 27, 40, 8, 26,
80 6, 39, 7, 38, 16, 37, 15, 10,
81 11, 12, 13, 14, 1, 21, 20, 18,
106 int format, coded_frame_rate, coded_frame_rate_base,
i, temp_ref;
107 int best_clock_code=1;
109 int best_error= INT_MAX;
114 div= (
s->avctx->time_base.num*1800000LL + 500LL*
s->avctx->time_base.den) / ((1000LL+
i)*
s->avctx->time_base.den);
116 error=
FFABS(
s->avctx->time_base.num*1800000LL - (1000LL+
i)*
s->avctx->time_base.den*div);
117 if(
error < best_error){
124 s->custom_pcf= best_clock_code!=1 || best_divisor!=60;
125 coded_frame_rate= 1800000;
126 coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
133 temp_ref=
s->picture_number * (int64_t)coded_frame_rate *
s->avctx->time_base.num /
134 (coded_frame_rate_base * (int64_t)
s->avctx->time_base.den);
203 put_bits(&
s->pb, 8,
s->avctx->sample_aspect_ratio.num);
204 put_bits(&
s->pb, 8,
s->avctx->sample_aspect_ratio.den);
220 if(
s->h263_slice_structured)
228 if(
s->h263_slice_structured){
245 if(
s->h263_slice_structured){
256 int gob_number= mb_line /
s->gob_index;
269 int8_t *
const qscale_table =
s->current_picture.qscale_table;
273 for(
i=1;
i<
s->mb_num;
i++){
274 if(qscale_table[
s->mb_index2xy[
i] ] - qscale_table[
s->mb_index2xy[
i-1] ] >2)
275 qscale_table[
s->mb_index2xy[
i] ]= qscale_table[
s->mb_index2xy[
i-1] ]+2;
277 for(
i=
s->mb_num-2;
i>=0;
i--){
278 if(qscale_table[
s->mb_index2xy[
i] ] - qscale_table[
s->mb_index2xy[
i+1] ] >2)
279 qscale_table[
s->mb_index2xy[
i] ]= qscale_table[
s->mb_index2xy[
i+1] ]+2;
283 for(
i=1;
i<
s->mb_num;
i++){
284 int mb_xy=
s->mb_index2xy[
i];
302 int level,
run, last,
i, j, last_index, last_non_zero, sign, slevel,
code;
306 if (
s->mb_intra && !
s->h263_aic) {
315 else if (
level < 1) {
326 if (
s->h263_aic &&
s->mb_intra)
329 if(
s->alt_inter_vlc && !
s->mb_intra){
331 int inter_vlc_bits=0;
335 last_index =
s->block_last_index[n];
336 last_non_zero =
i - 1;
337 for (;
i <= last_index;
i++) {
338 j =
s->intra_scantable.permutated[
i];
341 run =
i - last_non_zero - 1;
342 last = (
i == last_index);
352 inter_vlc_bits += 1+6+8-1;
355 aic_vlc_bits += 1+6+8-1;
356 wrong_pos +=
run + 1;
363 if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63)
369 last_index =
s->block_last_index[n];
370 last_non_zero =
i - 1;
371 for (;
i <= last_index;
i++) {
372 j =
s->intra_scantable.permutated[
i];
375 run =
i - last_non_zero - 1;
376 last = (
i == last_index);
386 if(!CONFIG_FLV_ENCODER ||
s->h263_flv <= 1){
428 sval = ((
val < 0) ? (
short)(-
val):(
short)
val);
431 while (temp_val != 0) {
432 temp_val = temp_val >> 1;
438 tcode = (sval & (1 << (
i-1))) >> (
i-1);
439 tcode = (tcode << 1) | 1;
449 int16_t
block[6][64],
450 int motion_x,
int motion_y)
452 int cbpc, cbpy,
i, cbp, pred_x, pred_y;
454 int16_t rec_intradc[6];
462 if ((cbp | motion_x | motion_y |
s->dquant | (
s->mv_type -
MV_TYPE_16X16)) == 0) {
465 if(interleaved_stats){
477 if(
s->alt_inter_vlc==0 || cbpc!=3)
479 if(
s->dquant) cbpc+= 8;
489 if(interleaved_stats){
498 motion_y - pred_y, 1);
503 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
515 if(interleaved_stats){
523 motion_x =
s->current_picture.motion_val[0][
s->block_index[
i]][0];
524 motion_y =
s->current_picture.motion_val[0][
s->block_index[
i]][1];
527 motion_y - pred_y, 1);
532 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
539 if(interleaved_stats){
553 else scale=
s->c_dc_scale;
563 if(!
s->modified_quant){
566 else if (
level > 127)
578 if (rec_intradc[
i] < 0)
580 else if (rec_intradc[
i] > 2047)
581 rec_intradc[
i] = 2047;
584 *dc_ptr[
i] = rec_intradc[
i];
586 if (
s->block_last_index[
i] > 0 ||
587 (
s->block_last_index[
i] == 0 &&
level !=0))
593 if (
s->block_last_index[
i] >= 1)
600 if(
s->dquant) cbpc+=4;
605 if(
s->dquant) cbpc+=8;
620 if(interleaved_stats){
630 if (
s->h263_aic &&
s->mb_intra) {
636 if(interleaved_stats){
649 int range, bit_size, sign,
code,
bits;
656 bit_size = f_code - 1;
657 range = 1 << bit_size;
680 for(f_code=1; f_code<=
MAX_FCODE; f_code++){
688 bit_size = f_code - 1;
706 for(f_code=
MAX_FCODE; f_code>0; f_code--){
707 for(
mv=-(16<<f_code);
mv<(16<<f_code);
mv++){
719 int slevel,
run, last;
724 for(slevel=-64; slevel<64; slevel++){
725 if(slevel==0)
continue;
727 for(last=0; last<=1; last++){
729 int level= slevel < 0 ? -slevel : slevel;
730 int sign= slevel < 0 ? 1 : 0;
783 s->ac_esc_length= 7+1+6+8;
793 if(
s->modified_quant){
794 s->min_qcoeff= -2047;
803 if (
s->h263_flv > 1) {
804 s->min_qcoeff= -1023;
833 mb_pos=
s->mb_x +
s->mb_width*
s->mb_y;
static void error(const char *err)
#define MV_TYPE_16X16
1 vector for the whole mb
#define FF_ASPECT_EXTENDED
static const uint8_t wrong_run[102]
static uint8_t fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need.
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static uint8_t uni_h263_inter_rl_len[64 *64 *2 *2]
#define UNI_MPEG4_ENC_INDEX(last, run, level)
const uint8_t ff_mpeg1_dc_scale_table[128]
static const int8_t mv[256][2]
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
void ff_init_qscale_tab(MpegEncContext *s)
init s->current_picture.qscale_table from s->lambda_table
static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
#define CANDIDATE_MB_TYPE_INTER
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.
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
const AVRational ff_h263_pixel_aspect[16]
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
Table of number of bits a motion vector component needs.
static double val(void *priv, double ch)
static av_always_inline float scale(float x, float s)
av_const int ff_h263_aspect_to_info(AVRational aspect)
Return the 4 bit value that specifies the given aspect ratio.
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last)
#define CANDIDATE_MB_TYPE_INTER4V
static void h263_encode_block(MpegEncContext *s, int16_t *block, int n)
Encode an 8x8 block.
int n
number of entries of table_vlc minus 1
static int ff_thread_once(char *control, void(*routine)(void))
void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
#define FF_ARRAY_ELEMS(a)
void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number)
static int get_rl_index(const RLTable *rl, int last, int run, int level)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int get_p_cbp(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
av_cold void ff_h263_encode_init(MpegEncContext *s)
av_cold void ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Initialize index_run, max_level and max_run from n, last, table_vlc, table_run and table_level.
void ff_h263_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static av_cold void init_mv_penalty_and_fcode(void)
const uint16_t(* table_vlc)[2]
Rational number (pair of numerator and denominator).
static uint8_t uni_h263_intra_aic_rl_len[64 *64 *2 *2]
@ AV_PICTURE_TYPE_I
Intra.
const uint16_t ff_mba_max[6]
int ff_h263_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr)
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is actually possible in H.263 (limit difference to -2....
const uint8_t ff_h263_cbpy_tab[16][2]
const uint8_t ff_h263_inter_MCBPC_bits[28]
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
const uint16_t ff_h263_format[8][2]
void ff_h263_encode_mba(MpegEncContext *s)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static int get_bits_diff(MpegEncContext *s)
static av_cold void h263_encode_init_static(void)
const uint8_t ff_aic_dc_scale_table[32]
const uint8_t ff_mvtab[33][2]
const uint8_t ff_h263_intra_MCBPC_bits[9]
static const int dquant_code[5]
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
const uint8_t ff_h263_intra_MCBPC_code[9]
static uint8_t umv_fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need in umv.
static av_const int sign_extend(int val, unsigned bits)
const uint8_t ff_mba_length[7]
void ff_h263_encode_gob_header(MpegEncContext *s, int mb_line)
Encode a group of blocks header.
const uint8_t ff_h263_inter_MCBPC_code[28]
@ AV_PICTURE_TYPE_P
Predicted.
static void ff_h263_encode_motion_vector(MpegEncContext *s, int x, int y, int f_code)
static void FUNC() pred_dc(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int log2_size, int c_idx)
static void h263p_encode_umotion(PutBitContext *pb, int val)
The exact code depends on how similar the blocks are and how related they are to the block
av_cold void ff_h263_init_rl_inter(void)
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.