📄 mpegvideo.h
字号:
/* * Generic DCT based hybrid video encoder * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * 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 * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//** * @file mpegvideo.h * mpegvideo header. */ #ifndef AVCODEC_MPEGVIDEO_H#define AVCODEC_MPEGVIDEO_H#include "dsputil.h"#define FRAME_SKIPED 100 ///< return value for header parsers if frame is not codedenum OutputFormat { FMT_MPEG1, FMT_H263, FMT_MJPEG, FMT_H264,};#define EDGE_WIDTH 16#define MPEG_BUF_SIZE (16 * 1024)#define QMAT_SHIFT_MMX 16#define QMAT_SHIFT 22#define MAX_FCODE 7#define MAX_MV 2048#define MAX_THREADS 8#define MAX_PICTURE_COUNT 15#define ME_MAP_SIZE 64#define ME_MAP_SHIFT 3#define ME_MAP_MV_BITS 11/* run length table */#define MAX_RUN 64#define MAX_LEVEL 64#define I_TYPE FF_I_TYPE ///< Intra#define P_TYPE FF_P_TYPE ///< Predicted#define B_TYPE FF_B_TYPE ///< Bi-dir predicted#define S_TYPE FF_S_TYPE ///< S(GMC)-VOP MPEG4#define SI_TYPE FF_SI_TYPE ///< Switching Intra#define SP_TYPE FF_SP_TYPE ///< Switching Predictedtypedef 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; uint64_t expected_bits; int new_pict_type; float new_qscale; int mc_mb_var_sum; int mb_var_sum; int i_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;}RateControlContext;/** * Scantable. */typedef struct ScanTable{ const uint8_t *scantable; uint8_t permutated[64]; uint8_t raster_end[64];#ifdef ARCH_POWERPC /** Used by dct_quantise_alitvec to find last-non-zero */ uint8_t __align8 inverse[64];#endif} ScanTable;/** * Picture. */typedef struct Picture{ FF_COMMON_FRAME /** * halfpel luma planes. */ uint8_t *interpolated[3]; int16_t (*motion_val_base[2])[2]; int8_t *ref_index[2]; uint32_t *mb_type_base;#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if theres just one type#define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)#define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)#define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)#define IS_INTRA(a) ((a)&7)#define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))#define IS_SKIP(a) ((a)&MB_TYPE_SKIP)#define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)#define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)#define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)#define IS_GMC(a) ((a)&MB_TYPE_GMC)#define IS_16X16(a) ((a)&MB_TYPE_16x16)#define IS_16X8(a) ((a)&MB_TYPE_16x8)#define IS_8X16(a) ((a)&MB_TYPE_8x16)#define IS_8X8(a) ((a)&MB_TYPE_8x8)#define IS_SUB_8X8(a) ((a)&MB_TYPE_16x16) //note reused#define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused#define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused#define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused#define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)#define IS_QUANT(a) ((a)&MB_TYPE_QUANT)#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs#define HAS_CBP(a) ((a)&MB_TYPE_CBP) int field_poc[2]; ///< h264 top/bottom POC int poc; ///< h264 frame POC int frame_num; ///< h264 frame_num int pic_id; ///< h264 pic_num or long_term_pic_idx int long_ref; ///< 1->long term reference 0->short term reference int mb_var_sum; ///< sum of MB variance for current frame int mc_mb_var_sum; ///< motion compensated MB variance for current frame uint16_t *mb_var; ///< Table for MB variances uint16_t *mc_mb_var; ///< Table for motion compensated MB variances uint8_t *mb_mean; ///< Table for MB luminance int32_t *mb_cmp_score; ///< Table for MB cmp scores, for mb decission FIXME remove int b_frame_score; /* */} Picture;typedef struct ParseContext{ uint8_t *buffer; int index; int last_index; int buffer_size; uint32_t state; ///< contains the last few bytes in MSB order int frame_start_found; int overread; ///< the number of bytes which where irreversibly read from the next frame int overread_index; ///< the index into ParseContext.buffer of the overreaded bytes} ParseContext;struct MpegEncContext;/** * Motion estimation context. */typedef struct MotionEstContext{ int skip; ///< set if ME is skiped for the current MB int co_located_mv[4][2]; ///< mv from last p frame for direct mode ME int direct_basis_mv[4][2]; uint8_t *scratchpad; ///< data area for the me algo, so that the ME doesnt need to malloc/free uint32_t *map; ///< map to avoid duplicate evaluations uint32_t *score_map; ///< map to store the scores int map_generation; int pre_penalty_factor; int penalty_factor; int sub_penalty_factor; int mb_penalty_factor; int pre_pass; ///< = 1 for the pre pass int dia_size; int xmin; int xmax; int ymin; int ymax; uint8_t (*mv_penalty)[MAX_MV*2+1]; ///< amount of bits needed to encode a MV int (*sub_motion_search)(struct MpegEncContext * s, int *mx_ptr, int *my_ptr, int dmin, int pred_x, int pred_y, uint8_t *src_data[3], uint8_t *ref_data[6], int stride, int uvstride, int size, int h, uint8_t * const mv_penalty); int (*motion_search[7])(struct MpegEncContext * s, int *mx_ptr, int *my_ptr, int P[10][2], int pred_x, int pred_y, uint8_t *src_data[3], uint8_t *ref_data[6], int stride, int uvstride, int16_t (*last_mv)[2], int ref_mv_scale, uint8_t * const mv_penalty); int (*pre_motion_search)(struct MpegEncContext * s, int *mx_ptr, int *my_ptr, int P[10][2], int pred_x, int pred_y, uint8_t *src_data[3], uint8_t *ref_data[6], int stride, int uvstride, int16_t (*last_mv)[2], int ref_mv_scale, uint8_t * const mv_penalty); int (*get_mb_score)(struct MpegEncContext * s, int mx, int my, int pred_x, int pred_y, uint8_t *src_data[3], uint8_t *ref_data[6], int stride, int uvstride, uint8_t * const mv_penalty);}MotionEstContext;/** * MpegEncContext. */typedef struct MpegEncContext { struct AVCodecContext *avctx; /* the following parameters must be initialized before encoding */ int width, height;///< picture size. must be a multiple of 16 int gop_size; int intra_only; ///< if true, only intra pictures are generated int bit_rate; ///< wanted bit rate enum OutputFormat out_format; ///< output format int h263_pred; ///< use mpeg4/h263 ac/dc predictions /* the following codec id fields are deprecated in favor of codec_id */ int h263_plus; ///< h263 plus headers int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead) int h263_flv; ///< use flv h263 header int codec_id; /* see CODEC_ID_xxx */ int fixed_qscale; ///< fixed qscale if non zero int encoding; ///< true if we are encoding (vs decoding) int flags; ///< AVCodecContext.flags (HQ, MV4, ...) int flags2; ///< AVCodecContext.flags2 int max_b_frames; ///< max number of b-frames for encoding int luma_elim_threshold; int chroma_elim_threshold; int strict_std_compliance; ///< strictly follow the std (MPEG4, ...) int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically /* the following fields are managed internally by the encoder */ /** bit output */ PutBitContext pb; /* sequence parameters */ int context_initialized; int input_picture_number; ///< used to set pic->display_picture_number, shouldnt be used for/by anything else int coded_picture_number; ///< used to set pic->coded_picture_number, shouldnt be used for/by anything else int picture_number; //FIXME remove, unclear definition int picture_in_gop_number; ///< 0-> first pic in gop, ... int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video() int mb_width, mb_height; ///< number of MBs horizontally & vertically int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressng of left & top MBs withoutt sig11 int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressng int b4_stride; ///< 4*mb_width+1 used for some 4x4 block arrays to allow simple addressng int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replicateion) int mb_num; ///< number of MBs of a picture int linesize; ///< line size, in bytes, may be different from width int uvlinesize; ///< line size, for chroma in bytes, may be different from width Picture *picture; ///< main picture buffer Picture **input_picture; ///< next pictures on display order for encoding Picture **reordered_input_picture; ///< pointer to the next pictures in codedorder for encoding int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) struct MpegEncContext *thread_context[MAX_THREADS]; /** * copy of the previous picture structure. * note, linesize & data, might not match the previous picture (for field pictures) */ Picture last_picture; /** * copy of the next picture structure. * note, linesize & data, might not match the next picture (for field pictures) */ Picture next_picture; /** * copy of the source picture structure for encoding. * note, linesize & data, might not match the source picture (for field pictures) */ Picture new_picture; /** * copy of the current picture structure. * note, linesize & data, might not match the current picture (for field pictures) */ Picture current_picture; ///< buffer to store the decompressed current picture
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -