📄 mpegvideo.h
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS and its licensors.** All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.** See below for additional copyright and license information**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************//* * Generic DCT based hybrid video encoder * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * * 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_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; int 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[2])[2]; int8_t *ref_index[2]; uint32_t *mb_type_base; uint32_t *mb_type; ///< mb_type_base + mb_width + 2, note: only used for decoding currently#define MB_TYPE_INTRA4x4 0x0001#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific#define MB_TYPE_16x16 0x0008#define MB_TYPE_16x8 0x0010#define MB_TYPE_8x16 0x0020#define MB_TYPE_8x8 0x0040#define MB_TYPE_INTERLACED 0x0080#define MB_TYPE_DIRECT2 0x0100 //FIXME#define MB_TYPE_ACPRED 0x0200#define MB_TYPE_GMC 0x0400 //FIXME mpeg4 specific#define MB_TYPE_SKIP 0x0800#define MB_TYPE_P0L0 0x1000#define MB_TYPE_P1L0 0x2000#define MB_TYPE_P0L1 0x4000#define MB_TYPE_P1L1 0x8000#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)#define MB_TYPE_QUANT 0x00010000//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 pat, ...)#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 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 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; 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 xmin, int ymin, int xmax, int ymax, int pred_x, int pred_y, Picture *ref_picture, int n, int size, uint8_t * const mv_penalty); int (*motion_search[7])(struct MpegEncContext * s, int block, int *mx_ptr, int *my_ptr, int P[10][2], int pred_x, int pred_y, int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, int16_t (*last_mv)[2], int ref_mv_scale, uint8_t * const mv_penalty); int (*pre_motion_search)(struct MpegEncContext * s, int block, int *mx_ptr, int *my_ptr, int P[10][2], int pred_x, int pred_y, int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, 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, Picture *ref_picture, 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 int bit_rate_tolerance; ///< amount of +- bits (>0) 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_rv10; ///< use RV10 variation for H263 int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead) int h263_intel; ///< use I263 intel h263 header int h263_flv; ///< use flv h263 header int codec_id; /* see CODEC_ID_xxx */ int fixed_qscale; ///< fixed qscale if non zero 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 max_qdiff; ///< max qscale difference between frames int encoding; ///< true if we are encoding (vs decoding) int flags; ///< AVCodecContext.flags (HQ, MV4, ...) int max_b_frames; ///< max number of b-frames for encoding int b_frame_strategy; 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -