00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef AVCODEC_MPEGVIDEO_H
00029 #define AVCODEC_MPEGVIDEO_H
00030
00031 #include "avcodec.h"
00032 #include "dsputil.h"
00033 #include "get_bits.h"
00034 #include "put_bits.h"
00035 #include "ratecontrol.h"
00036 #include "parser.h"
00037 #include "mpeg12data.h"
00038 #include "rl.h"
00039 #include "libavutil/timecode.h"
00040
00041 #include "libavutil/opt.h"
00042
00043 #define FRAME_SKIPPED 100
00044
00045 enum OutputFormat {
00046 FMT_MPEG1,
00047 FMT_H261,
00048 FMT_H263,
00049 FMT_MJPEG,
00050 FMT_H264,
00051 };
00052
00053 #define MPEG_BUF_SIZE (16 * 1024)
00054
00055 #define QMAT_SHIFT_MMX 16
00056 #define QMAT_SHIFT 22
00057
00058 #define MAX_FCODE 7
00059 #define MAX_MV 2048
00060
00061 #define MAX_THREADS 32
00062
00063 #define MAX_PICTURE_COUNT 32
00064
00065 #define ME_MAP_SIZE 64
00066 #define ME_MAP_SHIFT 3
00067 #define ME_MAP_MV_BITS 11
00068
00069 #define MAX_MB_BYTES (30*16*16*3/8 + 120)
00070
00071 #define INPLACE_OFFSET 16
00072
00073
00074 #define SEQ_END_CODE 0x000001b7
00075 #define SEQ_START_CODE 0x000001b3
00076 #define GOP_START_CODE 0x000001b8
00077 #define PICTURE_START_CODE 0x00000100
00078 #define SLICE_MIN_START_CODE 0x00000101
00079 #define SLICE_MAX_START_CODE 0x000001af
00080 #define EXT_START_CODE 0x000001b5
00081 #define USER_START_CODE 0x000001b2
00082
00083 struct MpegEncContext;
00084
00088 typedef struct Picture{
00089 struct AVFrame f;
00090
00094 uint8_t *interpolated[3];
00095 int8_t *qscale_table_base;
00096 int16_t (*motion_val_base[2])[2];
00097 uint32_t *mb_type_base;
00098 #define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if there is just one type
00099 #define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)
00100 #define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)
00101 #define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
00102 #define IS_INTRA(a) ((a)&7)
00103 #define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))
00104 #define IS_SKIP(a) ((a)&MB_TYPE_SKIP)
00105 #define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
00106 #define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)
00107 #define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)
00108 #define IS_GMC(a) ((a)&MB_TYPE_GMC)
00109 #define IS_16X16(a) ((a)&MB_TYPE_16x16)
00110 #define IS_16X8(a) ((a)&MB_TYPE_16x8)
00111 #define IS_8X16(a) ((a)&MB_TYPE_8x16)
00112 #define IS_8X8(a) ((a)&MB_TYPE_8x8)
00113 #define IS_SUB_8X8(a) ((a)&MB_TYPE_16x16) //note reused
00114 #define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused
00115 #define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused
00116 #define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused
00117 #define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)
00118 #define IS_QUANT(a) ((a)&MB_TYPE_QUANT)
00119 #define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))
00120 #define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list))))
00121 #define HAS_CBP(a) ((a)&MB_TYPE_CBP)
00122
00123 int field_poc[2];
00124 int poc;
00125 int frame_num;
00126 int mmco_reset;
00127 int pic_id;
00129 int long_ref;
00130 int ref_poc[2][2][32];
00131 int ref_count[2][2];
00132 int mbaff;
00133 int field_picture;
00134 int sync;
00135
00136 int mb_var_sum;
00137 int mc_mb_var_sum;
00138 uint16_t *mb_var;
00139 uint16_t *mc_mb_var;
00140 uint8_t *mb_mean;
00141 int32_t *mb_cmp_score;
00142 int b_frame_score;
00143 struct MpegEncContext *owner2;
00144 } Picture;
00145
00149 typedef struct MotionEstContext{
00150 AVCodecContext *avctx;
00151 int skip;
00152 int co_located_mv[4][2];
00153 int direct_basis_mv[4][2];
00154 uint8_t *scratchpad;
00155 uint8_t *best_mb;
00156 uint8_t *temp_mb[2];
00157 uint8_t *temp;
00158 int best_bits;
00159 uint32_t *map;
00160 uint32_t *score_map;
00161 unsigned map_generation;
00162 int pre_penalty_factor;
00163 int penalty_factor;
00168 int sub_penalty_factor;
00169 int mb_penalty_factor;
00170 int flags;
00171 int sub_flags;
00172 int mb_flags;
00173 int pre_pass;
00174 int dia_size;
00175 int xmin;
00176 int xmax;
00177 int ymin;
00178 int ymax;
00179 int pred_x;
00180 int pred_y;
00181 uint8_t *src[4][4];
00182 uint8_t *ref[4][4];
00183 int stride;
00184 int uvstride;
00185
00186 int mc_mb_var_sum_temp;
00187 int mb_var_sum_temp;
00188 int scene_change_score;
00189
00190 op_pixels_func (*hpel_put)[4];
00191 op_pixels_func (*hpel_avg)[4];
00192 qpel_mc_func (*qpel_put)[16];
00193 qpel_mc_func (*qpel_avg)[16];
00194 uint8_t (*mv_penalty)[MAX_MV*2+1];
00195 uint8_t *current_mv_penalty;
00196 int (*sub_motion_search)(struct MpegEncContext * s,
00197 int *mx_ptr, int *my_ptr, int dmin,
00198 int src_index, int ref_index,
00199 int size, int h);
00200 }MotionEstContext;
00201
00205 typedef struct MpegEncContext {
00206 AVClass *class;
00207 struct AVCodecContext *avctx;
00208
00209 int width, height;
00210 int gop_size;
00211 int intra_only;
00212 int bit_rate;
00213 enum OutputFormat out_format;
00214 int h263_pred;
00215 int pb_frame;
00216
00217
00218 int h263_plus;
00219 int h263_flv;
00220
00221 enum CodecID codec_id;
00222 int fixed_qscale;
00223 int encoding;
00224 int flags;
00225 int flags2;
00226 int max_b_frames;
00227 int luma_elim_threshold;
00228 int chroma_elim_threshold;
00229 int strict_std_compliance;
00230 int workaround_bugs;
00231 int codec_tag;
00232 int stream_codec_tag;
00233
00234
00235
00236 int context_initialized;
00237 int input_picture_number;
00238 int coded_picture_number;
00239 int picture_number;
00240 int picture_in_gop_number;
00241 int mb_width, mb_height;
00242 int mb_stride;
00243 int b8_stride;
00244 int b4_stride;
00245 int h_edge_pos, v_edge_pos;
00246 int mb_num;
00247 int linesize;
00248 int uvlinesize;
00249 Picture *picture;
00250 Picture **input_picture;
00251 Picture **reordered_input_picture;
00252
00253 int y_dc_scale, c_dc_scale;
00254 int ac_pred;
00255 int block_last_index[12];
00256 int h263_aic;
00257
00258
00259 ScanTable inter_scantable;
00260 ScanTable intra_scantable;
00261 ScanTable intra_h_scantable;
00262 ScanTable intra_v_scantable;
00263
00264
00265
00266
00267 int64_t user_specified_pts;
00268
00271 int64_t dts_delta;
00275 int64_t reordered_pts;
00276
00278 PutBitContext pb;
00279
00280 int start_mb_y;
00281 int end_mb_y;
00282 struct MpegEncContext *thread_context[MAX_THREADS];
00283 int slice_context_count;
00284
00289 Picture last_picture;
00290
00295 Picture next_picture;
00296
00301 Picture new_picture;
00302
00307 Picture current_picture;
00308
00309 Picture *last_picture_ptr;
00310 Picture *next_picture_ptr;
00311 Picture *current_picture_ptr;
00312 int picture_count;
00313 int picture_range_start, picture_range_end;
00314 uint8_t *visualization_buffer[3];
00315 int last_dc[3];
00316 int16_t *dc_val_base;
00317 int16_t *dc_val[3];
00318 const uint8_t *y_dc_scale_table;
00319 const uint8_t *c_dc_scale_table;
00320 const uint8_t *chroma_qscale_table;
00321 uint8_t *coded_block_base;
00322 uint8_t *coded_block;
00323 int16_t (*ac_val_base)[16];
00324 int16_t (*ac_val[3])[16];
00325 int mb_skipped;
00326 uint8_t *mbskip_table;
00328 uint8_t *mbintra_table;
00329 uint8_t *cbp_table;
00330 uint8_t *pred_dir_table;
00331 uint8_t *edge_emu_buffer;
00332 uint8_t *rd_scratchpad;
00333 uint8_t *obmc_scratchpad;
00334 uint8_t *b_scratchpad;
00335
00336 int qscale;
00337 int chroma_qscale;
00338 unsigned int lambda;
00339 unsigned int lambda2;
00340 int *lambda_table;
00341 int adaptive_quant;
00342 int dquant;
00343 int closed_gop;
00344 int pict_type;
00345 int last_pict_type;
00346 int last_non_b_pict_type;
00347 int dropable;
00348 int frame_rate_index;
00349 int last_lambda_for[5];
00350 int skipdct;
00351
00352
00353 int unrestricted_mv;
00354 int h263_long_vectors;
00355
00356 DSPContext dsp;
00357 int f_code;
00358 int b_code;
00359 int16_t (*p_mv_table_base)[2];
00360 int16_t (*b_forw_mv_table_base)[2];
00361 int16_t (*b_back_mv_table_base)[2];
00362 int16_t (*b_bidir_forw_mv_table_base)[2];
00363 int16_t (*b_bidir_back_mv_table_base)[2];
00364 int16_t (*b_direct_mv_table_base)[2];
00365 int16_t (*p_field_mv_table_base[2][2])[2];
00366 int16_t (*b_field_mv_table_base[2][2][2])[2];
00367 int16_t (*p_mv_table)[2];
00368 int16_t (*b_forw_mv_table)[2];
00369 int16_t (*b_back_mv_table)[2];
00370 int16_t (*b_bidir_forw_mv_table)[2];
00371 int16_t (*b_bidir_back_mv_table)[2];
00372 int16_t (*b_direct_mv_table)[2];
00373 int16_t (*p_field_mv_table[2][2])[2];
00374 int16_t (*b_field_mv_table[2][2][2])[2];
00375 uint8_t (*p_field_select_table[2]);
00376 uint8_t (*b_field_select_table[2][2]);
00377 int me_method;
00378 int mv_dir;
00379 #define MV_DIR_FORWARD 1
00380 #define MV_DIR_BACKWARD 2
00381 #define MV_DIRECT 4
00382 int mv_type;
00383 #define MV_TYPE_16X16 0
00384 #define MV_TYPE_8X8 1
00385 #define MV_TYPE_16X8 2
00386 #define MV_TYPE_FIELD 3
00387 #define MV_TYPE_DMV 4
00388
00393 int mv[2][4][2];
00394 int field_select[2][2];
00395 int last_mv[2][2][2];
00396 uint8_t *fcode_tab;
00397 int16_t direct_scale_mv[2][64];
00398
00399 MotionEstContext me;
00400
00401 int no_rounding;
00404
00405 int mb_x, mb_y;
00406 int mb_skip_run;
00407 int mb_intra;
00408 uint16_t *mb_type;
00409 #define CANDIDATE_MB_TYPE_INTRA 0x01
00410 #define CANDIDATE_MB_TYPE_INTER 0x02
00411 #define CANDIDATE_MB_TYPE_INTER4V 0x04
00412 #define CANDIDATE_MB_TYPE_SKIPPED 0x08
00413
00414
00415 #define CANDIDATE_MB_TYPE_DIRECT 0x10
00416 #define CANDIDATE_MB_TYPE_FORWARD 0x20
00417 #define CANDIDATE_MB_TYPE_BACKWARD 0x40
00418 #define CANDIDATE_MB_TYPE_BIDIR 0x80
00419
00420 #define CANDIDATE_MB_TYPE_INTER_I 0x100
00421 #define CANDIDATE_MB_TYPE_FORWARD_I 0x200
00422 #define CANDIDATE_MB_TYPE_BACKWARD_I 0x400
00423 #define CANDIDATE_MB_TYPE_BIDIR_I 0x800
00424
00425 #define CANDIDATE_MB_TYPE_DIRECT0 0x1000
00426
00427 int block_index[6];
00428 int block_wrap[6];
00429 uint8_t *dest[3];
00430
00431 int *mb_index2xy;
00432
00434 uint16_t intra_matrix[64];
00435 uint16_t chroma_intra_matrix[64];
00436 uint16_t inter_matrix[64];
00437 uint16_t chroma_inter_matrix[64];
00438 #define QUANT_BIAS_SHIFT 8
00439 int intra_quant_bias;
00440 int inter_quant_bias;
00441 int min_qcoeff;
00442 int max_qcoeff;
00443 int ac_esc_length;
00444 uint8_t *intra_ac_vlc_length;
00445 uint8_t *intra_ac_vlc_last_length;
00446 uint8_t *inter_ac_vlc_length;
00447 uint8_t *inter_ac_vlc_last_length;
00448 uint8_t *luma_dc_vlc_length;
00449 #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
00450
00451 int coded_score[8];
00452
00454 int (*q_intra_matrix)[64];
00455 int (*q_chroma_intra_matrix)[64];
00456 int (*q_inter_matrix)[64];
00458 uint16_t (*q_intra_matrix16)[2][64];
00459 uint16_t (*q_chroma_intra_matrix16)[2][64];
00460 uint16_t (*q_inter_matrix16)[2][64];
00461
00462
00463 int (*dct_error_sum)[64];
00464 int dct_count[2];
00465 uint16_t (*dct_offset)[64];
00466
00467 void *opaque;
00468
00469
00470 int64_t total_bits;
00471 int frame_bits;
00472 int next_lambda;
00473 RateControlContext rc_context;
00474
00475
00476 int mv_bits;
00477 int header_bits;
00478 int i_tex_bits;
00479 int p_tex_bits;
00480 int i_count;
00481 int f_count;
00482 int b_count;
00483 int skip_count;
00484 int misc_bits;
00485 int last_bits;
00486
00487
00488 int error_count, error_occurred;
00489 uint8_t *error_status_table;
00490 #define VP_START 1
00491 #define ER_AC_ERROR 2
00492 #define ER_DC_ERROR 4
00493 #define ER_MV_ERROR 8
00494 #define ER_AC_END 16
00495 #define ER_DC_END 32
00496 #define ER_MV_END 64
00497
00498 #define ER_MB_ERROR (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)
00499 #define ER_MB_END (ER_AC_END|ER_DC_END|ER_MV_END)
00500
00501 int resync_mb_x;
00502 int resync_mb_y;
00503 GetBitContext last_resync_gb;
00504 int mb_num_left;
00505 int next_p_frame_damaged;
00506 int err_recognition;
00507
00508 ParseContext parse_context;
00509
00510
00511 int gob_index;
00512 int obmc;
00513 int showed_packed_warning;
00514 int mb_info;
00515 int prev_mb_info, last_mb_info;
00516 uint8_t *mb_info_ptr;
00517 int mb_info_size;
00518
00519
00520 int umvplus;
00521 int h263_aic_dir;
00522 int h263_slice_structured;
00523 int alt_inter_vlc;
00524 int modified_quant;
00525 int loop_filter;
00526 int custom_pcf;
00527
00528
00529 int time_increment_bits;
00530 int last_time_base;
00531 int time_base;
00532 int64_t time;
00533 int64_t last_non_b_time;
00534 uint16_t pp_time;
00535 uint16_t pb_time;
00536 uint16_t pp_field_time;
00537 uint16_t pb_field_time;
00538 int shape;
00539 int vol_sprite_usage;
00540 int sprite_width;
00541 int sprite_height;
00542 int sprite_left;
00543 int sprite_top;
00544 int sprite_brightness_change;
00545 int num_sprite_warping_points;
00546 int real_sprite_warping_points;
00547 uint16_t sprite_traj[4][2];
00548 int sprite_offset[2][2];
00549 int sprite_delta[2][2];
00550 int sprite_shift[2];
00551 int mcsel;
00552 int quant_precision;
00553 int quarter_sample;
00554 int scalability;
00555 int hierachy_type;
00556 int enhancement_type;
00557 int new_pred;
00558 int reduced_res_vop;
00559 int aspect_ratio_info;
00560 int sprite_warping_accuracy;
00561 int low_latency_sprite;
00562 int data_partitioning;
00563 int partitioned_frame;
00564 int rvlc;
00565 int resync_marker;
00566 int low_delay;
00567 int vo_type;
00568 int vol_control_parameters;
00569 int intra_dc_threshold;
00570 int use_intra_dc_vlc;
00571 PutBitContext tex_pb;
00572 PutBitContext pb2;
00573 int mpeg_quant;
00574 int t_frame;
00575 int padding_bug_score;
00576 int cplx_estimation_trash_i;
00577 int cplx_estimation_trash_p;
00578 int cplx_estimation_trash_b;
00579
00580
00581 int divx_version;
00582 int divx_build;
00583 int divx_packed;
00584 uint8_t *bitstream_buffer;
00585 int bitstream_buffer_size;
00586 unsigned int allocated_bitstream_buffer_size;
00587
00588 int xvid_build;
00589
00590
00591 int lavc_build;
00592
00593
00594 int rv10_version;
00595 int rv10_first_dc_coded[3];
00596 int orig_width, orig_height;
00597
00598
00599 struct MJpegContext *mjpeg_ctx;
00600 int mjpeg_vsample[3];
00601 int mjpeg_hsample[3];
00602
00603
00604 int mv_table_index;
00605 int rl_table_index;
00606 int rl_chroma_table_index;
00607 int dc_table_index;
00608 int use_skip_mb_code;
00609 int slice_height;
00610 int first_slice_line;
00611 int flipflop_rounding;
00612 int msmpeg4_version;
00613 int per_mb_rl_table;
00614 int esc3_level_length;
00615 int esc3_run_length;
00617 int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
00618 int inter_intra_pred;
00619 int mspel;
00620
00621
00622 GetBitContext gb;
00623
00624
00625 int gop_picture_number;
00626 int last_mv_dir;
00627 int broken_link;
00628 uint8_t *vbv_delay_ptr;
00629
00630
00631 int progressive_sequence;
00632 int mpeg_f_code[2][2];
00633 int picture_structure;
00634
00635 #define PICT_TOP_FIELD 1
00636 #define PICT_BOTTOM_FIELD 2
00637 #define PICT_FRAME 3
00638
00639 int intra_dc_precision;
00640 int frame_pred_frame_dct;
00641 int top_field_first;
00642 int concealment_motion_vectors;
00643 int q_scale_type;
00644 int intra_vlc_format;
00645 int alternate_scan;
00646 int repeat_first_field;
00647 int chroma_420_type;
00648 int chroma_format;
00649 #define CHROMA_420 1
00650 #define CHROMA_422 2
00651 #define CHROMA_444 3
00652 int chroma_x_shift;
00653 int chroma_y_shift;
00654
00655 int progressive_frame;
00656 int full_pel[2];
00657 int interlaced_dct;
00658 int first_slice;
00659 int first_field;
00660 int drop_frame_timecode;
00661 int scan_offset;
00662
00663
00664 int rtp_mode;
00665
00666 char *tc_opt_str;
00667 AVTimecode tc;
00668
00669 uint8_t *ptr_lastgob;
00670 int swap_uv;
00671 DCTELEM (*pblocks[12])[64];
00672
00673 DCTELEM (*block)[64];
00674 DCTELEM (*blocks)[8][64];
00675 int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]);
00676 #define SLICE_OK 0
00677 #define SLICE_ERROR -1
00678 #define SLICE_END -2
00679 #define SLICE_NOEND -3
00680
00681 void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
00682 DCTELEM *block, int n, int qscale);
00683 void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
00684 DCTELEM *block, int n, int qscale);
00685 void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
00686 DCTELEM *block, int n, int qscale);
00687 void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
00688 DCTELEM *block, int n, int qscale);
00689 void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
00690 DCTELEM *block, int n, int qscale);
00691 void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
00692 DCTELEM *block, int n, int qscale);
00693 void (*dct_unquantize_h261_intra)(struct MpegEncContext *s,
00694 DCTELEM *block, int n, int qscale);
00695 void (*dct_unquantize_h261_inter)(struct MpegEncContext *s,
00696 DCTELEM *block, int n, int qscale);
00697 void (*dct_unquantize_intra)(struct MpegEncContext *s,
00698 DCTELEM *block, int n, int qscale);
00699 void (*dct_unquantize_inter)(struct MpegEncContext *s,
00700 DCTELEM *block, int n, int qscale);
00701 int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
00702 int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
00703 void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
00704
00705 int mpv_flags;
00706 int quantizer_noise_shaping;
00707 } MpegEncContext;
00708
00709 #define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \
00710 (pic >= old_ctx->picture && pic < old_ctx->picture+old_ctx->picture_count ?\
00711 &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\
00712 : NULL)
00713
00714
00715 #define FF_MPV_FLAG_SKIP_RD 0x0001
00716 #define FF_MPV_FLAG_STRICT_GOP 0x0002
00717 #define FF_MPV_FLAG_QP_RD 0x0004
00718 #define FF_MPV_FLAG_CBP_RD 0x0008
00719
00720 #define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
00721 #define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
00722 #define FF_MPV_COMMON_OPTS \
00723 { "mpv_flags", "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
00724 { "skip_rd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_SKIP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
00725 { "strict_gop", "Strictly enforce gop size", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
00726 { "qp_rd", "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_QP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
00727 { "cbp_rd", "use rate distortion optimization for CBP", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
00728 { "luma_elim_threshold", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
00729 FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
00730 { "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
00731 FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
00732 { "quantizer_noise_shaping", NULL, FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },
00733
00734 extern const AVOption ff_mpv_generic_options[];
00735
00736 #define FF_MPV_GENERIC_CLASS(name) \
00737 static const AVClass name ## _class = {\
00738 .class_name = #name " encoder",\
00739 .item_name = av_default_item_name,\
00740 .option = ff_mpv_generic_options,\
00741 .version = LIBAVUTIL_VERSION_INT,\
00742 };
00743
00744 void ff_MPV_decode_defaults(MpegEncContext *s);
00745 int ff_MPV_common_init(MpegEncContext *s);
00746 void ff_MPV_common_end(MpegEncContext *s);
00747 void ff_MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]);
00748 int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
00749 void ff_MPV_frame_end(MpegEncContext *s);
00750 int ff_MPV_encode_init(AVCodecContext *avctx);
00751 int ff_MPV_encode_end(AVCodecContext *avctx);
00752 int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
00753 AVFrame *frame, int *got_packet);
00754 void ff_MPV_common_init_mmx(MpegEncContext *s);
00755 void ff_MPV_common_init_axp(MpegEncContext *s);
00756 void ff_MPV_common_init_mmi(MpegEncContext *s);
00757 void ff_MPV_common_init_arm(MpegEncContext *s);
00758 void ff_MPV_common_init_altivec(MpegEncContext *s);
00759 void ff_MPV_common_init_bfin(MpegEncContext *s);
00760 void ff_clean_intra_table_entries(MpegEncContext *s);
00761 void ff_draw_horiz_band(MpegEncContext *s, int y, int h);
00762 void ff_mpeg_flush(AVCodecContext *avctx);
00763 void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
00764 void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
00765 void ff_release_unused_pictures(MpegEncContext *s, int remove_current);
00766 int ff_find_unused_picture(MpegEncContext *s, int shared);
00767 void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
00768 void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
00769 int ff_MPV_lowest_referenced_row(MpegEncContext *s, int dir);
00770 void ff_MPV_report_decode_progress(MpegEncContext *s);
00771 int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
00772 const uint8_t *avpriv_mpv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state);
00773 void ff_set_qscale(MpegEncContext * s, int qscale);
00774
00775 void ff_er_frame_start(MpegEncContext *s);
00776 void ff_er_frame_end(MpegEncContext *s);
00777 void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status);
00778
00779 int ff_dct_common_init(MpegEncContext *s);
00780 void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
00781 const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
00782
00783 void ff_init_block_index(MpegEncContext *s);
00784 void ff_copy_picture(Picture *dst, Picture *src);
00785
00790 int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared);
00791
00792 extern const enum PixelFormat ff_pixfmt_list_420[];
00793 extern const enum PixelFormat ff_hwaccel_pixfmt_list_420[];
00794
00795 static inline void ff_update_block_index(MpegEncContext *s){
00796 const int block_size= 8 >> s->avctx->lowres;
00797
00798 s->block_index[0]+=2;
00799 s->block_index[1]+=2;
00800 s->block_index[2]+=2;
00801 s->block_index[3]+=2;
00802 s->block_index[4]++;
00803 s->block_index[5]++;
00804 s->dest[0]+= 2*block_size;
00805 s->dest[1]+= block_size;
00806 s->dest[2]+= block_size;
00807 }
00808
00809 static inline int get_bits_diff(MpegEncContext *s){
00810 const int bits= put_bits_count(&s->pb);
00811 const int last= s->last_bits;
00812
00813 s->last_bits = bits;
00814
00815 return bits - last;
00816 }
00817
00818 static inline int ff_h263_round_chroma(int x){
00819 static const uint8_t h263_chroma_roundtab[16] = {
00820
00821 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
00822 };
00823 return h263_chroma_roundtab[x & 0xf] + (x >> 3);
00824 }
00825
00826
00827 void ff_estimate_p_frame_motion(MpegEncContext * s,
00828 int mb_x, int mb_y);
00829 void ff_estimate_b_frame_motion(MpegEncContext * s,
00830 int mb_x, int mb_y);
00831 int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type);
00832 void ff_fix_long_p_mvs(MpegEncContext * s);
00833 void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select,
00834 int16_t (*mv_table)[2], int f_code, int type, int truncate);
00835 int ff_init_me(MpegEncContext *s);
00836 int ff_pre_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y);
00837 int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
00838 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
00839 int ref_mv_scale, int size, int h);
00840 int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
00841 int ref_index, int size, int h, int add_rate);
00842
00843
00844 extern const uint8_t ff_mpeg1_dc_scale_table[128];
00845 extern const uint8_t * const ff_mpeg2_dc_scale_table[4];
00846
00847 void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
00848 void ff_mpeg1_encode_mb(MpegEncContext *s,
00849 DCTELEM block[6][64],
00850 int motion_x, int motion_y);
00851 void ff_mpeg1_encode_init(MpegEncContext *s);
00852 void ff_mpeg1_encode_slice_header(MpegEncContext *s);
00853 void ff_mpeg1_clean_buffers(MpegEncContext *s);
00854 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s);
00855
00856 extern const uint8_t ff_aic_dc_scale_table[32];
00857 extern const uint8_t ff_h263_chroma_qscale_table[32];
00858 extern const uint8_t ff_h263_loop_filter_strength[32];
00859
00860
00861 void ff_h261_loop_filter(MpegEncContext *s);
00862 void ff_h261_reorder_mb_index(MpegEncContext* s);
00863 void ff_h261_encode_mb(MpegEncContext *s,
00864 DCTELEM block[6][64],
00865 int motion_x, int motion_y);
00866 void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number);
00867 void ff_h261_encode_init(MpegEncContext *s);
00868 int ff_h261_get_picture_format(int width, int height);
00869
00870
00871
00872 void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number);
00873 int ff_rv_decode_dc(MpegEncContext *s, int n);
00874 void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number);
00875
00876
00877
00878 void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
00879 void ff_msmpeg4_encode_ext_header(MpegEncContext * s);
00880 void ff_msmpeg4_encode_mb(MpegEncContext * s,
00881 DCTELEM block[6][64],
00882 int motion_x, int motion_y);
00883 int ff_msmpeg4_decode_picture_header(MpegEncContext * s);
00884 int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
00885 int ff_msmpeg4_decode_init(AVCodecContext *avctx);
00886 void ff_msmpeg4_encode_init(MpegEncContext *s);
00887 int ff_wmv2_decode_picture_header(MpegEncContext * s);
00888 int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
00889 void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
00890 void ff_mspel_motion(MpegEncContext *s,
00891 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
00892 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
00893 int motion_x, int motion_y, int h);
00894 int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number);
00895 void ff_wmv2_encode_mb(MpegEncContext * s,
00896 DCTELEM block[6][64],
00897 int motion_x, int motion_y);
00898
00899 #endif