FFmpeg
Loading...
Searching...
No Matches
mpegvideoenc.h
Go to the documentation of this file.
1/*
2 * Generic DCT based hybrid video encoder
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file
25 * mpegvideo header.
26 */
27
28#ifndef AVCODEC_MPEGVIDEOENC_H
29#define AVCODEC_MPEGVIDEOENC_H
30
31#include <float.h>
32
33#include "libavutil/avassert.h"
35#include "libavutil/opt.h"
36#include "fdctdsp.h"
37#include "motion_est.h"
38#include "mpegvideo.h"
39#include "mpegvideoencdsp.h"
40#include "pixblockdsp.h"
41#include "put_bits.h"
42#include "ratecontrol.h"
43
44#define MPVENC_MAX_B_FRAMES 16
45
46typedef struct MPVEncContext {
47 MpegEncContext c; ///< the common base context
48
49 /** bit output */
51
52 unsigned int lambda; ///< Lagrange multiplier used in rate distortion
53 unsigned int lambda2; ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
55 int adaptive_quant; ///< use adaptive quantization
56 int dquant; ///< qscale difference to prev qscale
57 int skipdct; ///< skip dct and code zero residual
58
60
63
64 int mpv_flags; ///< flags set by private options
65 /// Bitfield containing information which frames to reconstruct.
67
68 /**
69 * Reference to the source picture.
70 */
72
74
79
80 int f_code; ///< forward MV resolution
81 int b_code; ///< backward MV resolution for B-frames
82
83 int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) P-frame
84 int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode B-frame
85 int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode B-frame
86 int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame
87 int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame
88 int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode B-frame
89 int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced B-frame
90 uint8_t (*p_field_select_table[2]); ///< Only the first element is allocated
91 uint8_t (*b_field_select_table[2][2]); ///< allocated jointly with p_field_select_table
92
93 uint16_t *mb_type; ///< Table for candidate MB types
94 uint16_t *mb_var; ///< Table for MB variances
95 uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
96 uint8_t *mb_mean; ///< Table for MB luminance
98
99 int intra_quant_bias; ///< bias for the quantizer
100 int inter_quant_bias; ///< bias for the quantizer
101 int min_qcoeff; ///< minimum encodable coefficient
102 int max_qcoeff; ///< maximum encodable coefficient
103 int ac_esc_length; ///< num of bits needed to encode the longest esc
104 const uint8_t *intra_ac_vlc_length;
108 const uint8_t *inter_ac_vlc_length;
110 const uint8_t *luma_dc_vlc_length;
111
112 int coded_score[12];
113
114 int16_t (*block)[64]; ///< points into blocks below
115
116 /** precomputed matrix (combine qscale and DCT renorm) */
117 int (*q_intra_matrix)[64];
119 int (*q_inter_matrix)[64];
120 /** identical to the above but for SSE & these are not permutated, second 64 entries are bias*/
121 uint16_t (*q_intra_matrix16)[2][64];
122 uint16_t (*q_chroma_intra_matrix16)[2][64];
123 uint16_t (*q_inter_matrix16)[2][64];
124
125 /* noise reduction */
126 int (*dct_error_sum)[64];
127 int dct_count[2];
128 uint16_t (*dct_offset)[64];
129
131
132 /* statistics, used for 2-pass encoding */
137 int misc_bits; ///< cbp, mb_type
138 int last_bits; ///< temp var used for calculating the above vars
139
141 int last_dc[3]; ///< last DC values
142
143 /* H.263 specific */
145 int mb_info; ///< interval for outputting info about mb offsets as side data
148 uint8_t *mb_info_ptr;
149
150 /* H.263+ specific */
151 int umvplus; ///< == H.263+ && unrestricted_mv
153 int alt_inter_vlc; ///< alternative inter vlc
156
157 /* MJPEG specific */
160
161 /* MPEG-1 specific */
162 int last_mv_dir; ///< last mv_dir, used for B-frame encoding
163
164 /* MPEG-4 specific */
165 int data_partitioning; ///< data partitioning flag, set via option
166 int partitioned_frame; ///< is current frame partitioned
168 PutBitContext tex_pb; ///< used for data partitioned VOPs
169 PutBitContext pb2; ///< used for data partitioned VOPs
170
171 /* MSMPEG4 specific */
172 int slice_height; ///< in macroblocks
173 int flipflop_rounding; ///< also used for MPEG-4, H.263+
175
176 /* RTP specific */
180
181 uint8_t *ptr_lastgob;
182
183 void (*encode_mb)(struct MPVEncContext *s, int16_t block[][64],
184 int motion_x, int motion_y);
185
186 int (*dct_quantize)(struct MPVEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
187
188 me_cmp_func ildct_cmp[2]; ///< 0 = intra, 1 = non-intra
189 me_cmp_func n_sse_cmp[2]; ///< either SSE or NSSE cmp func
192 int (*sum_abs_dctelem)(const int16_t *block);
193
195
198
199 DECLARE_ALIGNED_32(int16_t, blocks)[2][12][64]; // for HQ mode we need to keep the best block
201
202typedef struct MPVMainEncContext {
203 MPVEncContext s; ///< The main slicecontext
204
205 int intra_only; ///< if true, only intra pictures are generated
207 int max_b_frames; ///< max number of B-frames
208 int picture_in_gop_number; ///< 0-> first pic in gop, ...
209 int input_picture_number; ///< used to set pic->display_picture_number
210 int coded_picture_number; ///< used to set pic->coded_picture_number
211
212 MPVPicture *input_picture[MPVENC_MAX_B_FRAMES + 1]; ///< next pictures in display order
213 MPVPicture *reordered_input_picture[MPVENC_MAX_B_FRAMES + 1]; ///< next pictures in coded order
214
215 int64_t user_specified_pts; ///< last non-zero pts from user-supplied AVFrame
216 /**
217 * pts difference between the first and second input frame, used for
218 * calculating dts of the first frame when there's a delay */
220 /**
221 * reordered pts to be used as dts for the next output frame when there's
222 * a delay */
224
225 /// temporary frames used by b_frame_strategy = 2
230
232
234
236 int lmin, lmax;
238
239 /* MPEG-1/2 specific */
240 int vbv_delay_pos; ///< offset of vbv_delay in the bitstream
241
242 const uint8_t *fcode_tab; ///< smallest fcode needed for each MV
243
244 /* frame skip options */
250
252
253 /* bit rate control */
256 int frame_bits; ///< bits used for the current frame
258 int stuffing_bits; ///< bits used for stuffing
259 int next_lambda; ///< next lambda used for retrying to encode a frame
260 int fixed_qscale; ///< fixed qscale if non zero
261 int last_lambda_for[5]; ///< last lambda for a specific pict type
262 int last_pict_type; //FIXME removes
263 int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
264 RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
265
267 int me_pre; ///< prepass for motion estimation
268
269 int64_t mb_var_sum; ///< sum of MB variance for current frame
270 int64_t mc_mb_var_sum; ///< motion compensated MB variance for current frame
271
272 char *me_map_base; ///< backs MotionEstContext.(map|score_map)
273 char *dct_error_sum_base; ///< backs dct_error_sum
274 int16_t (*mv_table_base)[2];
276
278{
279#ifdef NO_SLICE_THREADING_HERE
280 av_assert2(s->c.slice_context_count <= 1 &&
281 !(s->c.avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS));
282 return (const MPVMainEncContext*)s;
283#else
284 return s->parent;
285#endif
286}
287
288#define MAX_FCODE 7
289#define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
290#define INPLACE_OFFSET 16
291
292/* MB types for encoding */
293#define CANDIDATE_MB_TYPE_INTRA (1 << 0)
294#define CANDIDATE_MB_TYPE_INTER (1 << 1)
295#define CANDIDATE_MB_TYPE_INTER4V (1 << 2)
296#define CANDIDATE_MB_TYPE_SKIPPED (1 << 3)
297
298#define CANDIDATE_MB_TYPE_DIRECT (1 << 4)
299#define CANDIDATE_MB_TYPE_FORWARD (1 << 5)
300#define CANDIDATE_MB_TYPE_BACKWARD (1 << 6)
301#define CANDIDATE_MB_TYPE_BIDIR (1 << 7)
302
303#define CANDIDATE_MB_TYPE_INTER_I (1 << 8)
304#define CANDIDATE_MB_TYPE_FORWARD_I (1 << 9)
305#define CANDIDATE_MB_TYPE_BACKWARD_I (1 << 10)
306#define CANDIDATE_MB_TYPE_BIDIR_I (1 << 11)
307
308#define CANDIDATE_MB_TYPE_DIRECT0 (1 << 12)
309
310/* mpegvideo_enc common options */
311#define FF_MPV_FLAG_SKIP_RD 0x0001
312#define FF_MPV_FLAG_STRICT_GOP 0x0002
313#define FF_MPV_FLAG_QP_RD 0x0004
314#define FF_MPV_FLAG_CBP_RD 0x0008
315#define FF_MPV_FLAG_NAQ 0x0010
316#define FF_MPV_FLAG_MV0 0x0020
317
318#define FF_MPV_OPT_CMP_FUNC \
319{ "sad", "Sum of absolute differences, fast", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_SAD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
320{ "sse", "Sum of squared errors", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_SSE }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
321{ "satd", "Sum of absolute Hadamard transformed differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_SATD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
322{ "dct", "Sum of absolute DCT transformed differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCT }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
323{ "psnr", "Sum of squared quantization errors, low quality", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_PSNR }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
324{ "bit", "Number of bits needed for the block", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_BIT }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
325{ "rd", "Rate distortion optimal, slow", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_RD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
326{ "zero", "Zero", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_ZERO }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
327{ "vsad", "Sum of absolute vertical differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_VSAD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
328{ "vsse", "Sum of squared vertical differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_VSSE }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
329{ "nsse", "Noise preserving sum of squared differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_NSSE }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
330{ "dct264", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCT264 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
331{ "dctmax", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
332{ "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_CHROMA }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
333{ "msad", "Sum of absolute differences, median predicted", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_MEDIAN_SAD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }
334
335#define FF_MPV_OFFSET(x) offsetof(MPVEncContext, x)
336#define FF_MPV_MAIN_OFFSET(x) offsetof(MPVMainEncContext, x)
337#define FF_RC_OFFSET(x) offsetof(MPVMainEncContext, rc_context.x)
338#define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
339#define FF_MPV_COMMON_OPTS \
340FF_MPV_OPT_CMP_FUNC, \
341{ "mpv_flags", "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "mpv_flags" },\
342{ "skip_rd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_SKIP_RD }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "mpv_flags" },\
343{ "strict_gop", "Strictly enforce gop size", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "mpv_flags" },\
344{ "qp_rd", "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_QP_RD }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "mpv_flags" },\
345{ "cbp_rd", "use rate distortion optimization for CBP", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "mpv_flags" },\
346{ "naq", "normalize adaptive quantization", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_NAQ }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "mpv_flags" },\
347{ "luma_elim_threshold", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
348 FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
349{ "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
350 FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
351{ "quantizer_noise_shaping", NULL, FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },\
352{ "error_rate", "Simulate errors in the bitstream to test error concealment.", \
353 FF_MPV_OFFSET(error_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },\
354{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", \
355 FF_RC_OFFSET(qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS}, \
356{"rc_qmod_amp", "experimental quantizer modulation", FF_RC_OFFSET(qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \
357{"rc_qmod_freq", "experimental quantizer modulation", FF_RC_OFFSET(qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS}, \
358{"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions " \
359 "defined in the section 'Expression Evaluation', the following functions are available: " \
360 "bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv " \
361 "fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.", \
362 FF_RC_OFFSET(rc_eq), AV_OPT_TYPE_STRING, .flags = FF_MPV_OPT_FLAGS }, \
363{"rc_init_cplx", "initial complexity for 1-pass encoding", FF_RC_OFFSET(initial_cplx), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \
364{"rc_buf_aggressivity", "currently useless", FF_RC_OFFSET(buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \
365{"border_mask", "increase the quantizer for macroblocks close to borders", FF_MPV_MAIN_OFFSET(border_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \
366{"lmin", "minimum Lagrange factor (VBR)", FF_MPV_MAIN_OFFSET(lmin), AV_OPT_TYPE_INT, {.i64 = 2*FF_QP2LAMBDA }, 0, INT_MAX, FF_MPV_OPT_FLAGS }, \
367{"lmax", "maximum Lagrange factor (VBR)", FF_MPV_MAIN_OFFSET(lmax), AV_OPT_TYPE_INT, {.i64 = 31*FF_QP2LAMBDA }, 0, INT_MAX, FF_MPV_OPT_FLAGS }, \
368{"skip_threshold", "Frame skip threshold", FF_MPV_MAIN_OFFSET(frame_skip_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
369{"skip_factor", "Frame skip factor", FF_MPV_MAIN_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
370{"skip_exp", "Frame skip exponent", FF_MPV_MAIN_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
371{"skip_cmp", "Frame skip compare function", FF_MPV_MAIN_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, .unit = "cmp_func" }, \
372{"noise_reduction", "Noise reduction", FF_MPV_MAIN_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
373{"ps", "RTP payload size in bytes", FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
374
375#define FF_MPV_COMMON_BFRAME_OPTS \
376{"b_strategy", "Strategy to choose between I/P/B-frames", FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS }, \
377{"b_sensitivity", "Adjust sensitivity of b_frame_strategy 1", FF_MPV_MAIN_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS }, \
378{"brd_scale", "Downscale frames for dynamic B-frame decision", FF_MPV_MAIN_OFFSET(brd_scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS },
379
380#define FF_MPV_COMMON_MOTION_EST_OPTS \
381{ "mv0", "always try a mb with mv=<0,0>", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_MV0 }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "mpv_flags" },\
382{"motion_est", "motion estimation algorithm", FF_MPV_OFFSET(me.motion_est), AV_OPT_TYPE_INT, {.i64 = FF_ME_EPZS }, FF_ME_ZERO, FF_ME_XONE, FF_MPV_OPT_FLAGS, .unit = "motion_est" }, \
383{ "zero", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ZERO }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "motion_est" }, \
384{ "epzs", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_EPZS }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "motion_est" }, \
385{ "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, FF_MPV_OPT_FLAGS, .unit = "motion_est" }, \
386{"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", FF_MPV_MAIN_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
387{"mepre", "pre motion estimation", FF_MPV_MAIN_OFFSET(me_pre), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
388{"intra_penalty", "Penalty for intra blocks in block decision", FF_MPV_OFFSET(intra_penalty), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX/2, FF_MPV_OPT_FLAGS }, \
389{"sc_threshold", "Scene change threshold", FF_MPV_MAIN_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
390
391extern const AVClass ff_mpv_enc_class;
392
394
397 const AVFrame *frame, int *got_packet);
398int ff_mpv_reallocate_putbitbuffer(MPVEncContext *s, size_t threshold, size_t size_increase);
399
400void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
401
404
405void ff_convert_matrix(MPVEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[2][64],
406 const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
407
408void ff_block_permute(int16_t *block, const uint8_t *permutation,
409 const uint8_t *scantable, int last);
410
411static inline int get_bits_diff(MPVEncContext *s)
412{
413 const int bits = put_bits_count(&s->pb);
414 const int last = s->last_bits;
415
416 s->last_bits = bits;
417
418 return bits - last;
419}
420
421#endif
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
static int16_t block[64]
Definition dct.c:125
static AVPacket * pkt
static AVFrame * frame
static const uint8_t bits[8]
Definition fastaudio.c:100
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition codec.h:102
int(* me_cmp_func)(MPVEncContext *c, const uint8_t *blk1, const uint8_t *blk2, ptrdiff_t stride, int h)
Definition me_cmp.h:45
#define MPV_MAX_PLANES
Definition mpegpicture.h:31
mpegvideo header.
const AVClass ff_mpv_enc_class
static int get_bits_diff(MPVEncContext *s)
#define MPVENC_MAX_B_FRAMES
void ff_dct_encode_init(MPVEncContext *s)
void ff_block_permute(int16_t *block, const uint8_t *permutation, const uint8_t *scantable, int last)
Permute an 8x8 block according to permutation.
int ff_mpv_encode_end(AVCodecContext *avctx)
void ff_convert_matrix(MPVEncContext *s, int(*qmat)[64], uint16_t(*qmat16)[2][64], const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra)
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
int ff_mpv_reallocate_putbitbuffer(MPVEncContext *s, size_t threshold, size_t size_increase)
void ff_dct_encode_init_x86(MPVEncContext *s)
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
int ff_mpv_encode_init(AVCodecContext *avctx)
static const MPVMainEncContext * slice_to_mainenc(const MPVEncContext *s)
AVOptions.
bitstream writer API
static int put_bits_count(PutBitContext *s)
Definition put_bits.h:90
ratecontrol header.
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
Holds JPEG frame data and Huffman table data.
Definition mjpegenc.h:44
int16_t(* b_back_mv_table)[2]
MV table (1MV per MB) backward mode B-frame.
int(* dct_error_sum)[64]
const uint8_t * intra_chroma_ac_vlc_last_length
int16_t(* b_direct_mv_table)[2]
MV table (1MV per MB) direct mode B-frame.
int(* sum_abs_dctelem)(const int16_t *block)
int(* dct_quantize)(struct MPVEncContext *s, int16_t *block, int n, int qscale, int *overflow)
int flipflop_rounding
also used for MPEG-4, H.263+
PixblockDSPContext pdsp
uint8_t permutated_intra_h_scantable[64]
const uint8_t * inter_ac_vlc_length
int last_bits
temp var used for calculating the above vars
MotionEstContext me
const uint8_t * intra_ac_vlc_last_length
PutBitContext pb
bit output
me_cmp_func sse_cmp[2]
int quantizer_noise_shaping
int partitioned_frame
is current frame partitioned
uint16_t(* q_intra_matrix16)[2][64]
identical to the above but for SSE & these are not permutated, second 64 entries are bias
uint16_t * mc_mb_var
Table for motion compensated MB variances.
int16_t(* p_mv_table)[2]
MV table (1MV per MB) P-frame.
me_cmp_func ildct_cmp[2]
0 = intra, 1 = non-intra
int adaptive_quant
use adaptive quantization
MpegvideoEncDSPContext mpvencdsp
int16_t(* b_forw_mv_table)[2]
MV table (1MV per MB) forward mode B-frame.
void(* encode_mb)(struct MPVEncContext *s, int16_t block[][64], int motion_x, int motion_y)
MpegEncContext c
the common base context
uint16_t(* dct_offset)[64]
uint16_t(* q_chroma_intra_matrix16)[2][64]
uint8_t *[2] p_field_select_table
Only the first element is allocated.
FDCTDSPContext fdsp
int chroma_elim_threshold
int misc_bits
cbp, mb_type
int data_partitioning
data partitioning flag, set via option
unsigned int lambda
Lagrange multiplier used in rate distortion.
int skipdct
skip dct and code zero residual
int b_code
backward MV resolution for B-frames
int intra_quant_bias
bias for the quantizer
me_cmp_func sad_cmp[2]
const uint8_t * luma_dc_vlc_length
int h263_slice_structured
int last_mv_dir
last mv_dir, used for B-frame encoding
int slice_height
in macroblocks
int(* q_inter_matrix)[64]
me_cmp_func n_sse_cmp[2]
either SSE or NSSE cmp func
const uint8_t * intra_ac_vlc_length
int last_dc[3]
last DC values
uint8_t * mb_mean
Table for MB luminance.
int dquant
qscale difference to prev qscale
int frame_reconstruction_bitfield
Bitfield containing information which frames to reconstruct.
uint8_t * mb_info_ptr
int16_t(* b_bidir_forw_mv_table)[2]
MV table (1MV per MB) bidir mode B-frame.
struct MPVMainEncContext * parent
uint8_t * ptr_lastgob
int f_code
forward MV resolution
struct MJpegContext * mjpeg_ctx
PutBitContext tex_pb
used for data partitioned VOPs
const uint8_t * intra_chroma_ac_vlc_length
int(* q_chroma_intra_matrix)[64]
int16_t(*[2][2][2] b_field_mv_table)[2]
MV table (4MV per MB) interlaced B-frame.
int coded_score[12]
int max_qcoeff
maximum encodable coefficient
int luma_elim_threshold
AVFrame * new_pic
Reference to the source picture.
int16_t(* block)[64]
points into blocks below
uint8_t *[2][2] b_field_select_table
allocated jointly with p_field_select_table
unsigned int lambda2
(lambda*lambda) >> FF_LAMBDA_SHIFT
const uint8_t * inter_ac_vlc_last_length
int ac_esc_length
num of bits needed to encode the longest esc
uint16_t(* q_inter_matrix16)[2][64]
int mb_info
interval for outputting info about mb offsets as side data
uint16_t * mb_type
Table for candidate MB types.
int inter_quant_bias
bias for the quantizer
int min_qcoeff
minimum encodable coefficient
DECLARE_ALIGNED_32(int16_t, blocks)[2][12][64]
int alt_inter_vlc
alternative inter vlc
PutBitContext pb2
used for data partitioned VOPs
uint16_t * mb_var
Table for MB variances.
uint8_t permutated_intra_v_scantable[64]
int(* q_intra_matrix)[64]
precomputed matrix (combine qscale and DCT renorm)
int umvplus
== H.263+ && unrestricted_mv
uint64_t encoding_error[MPV_MAX_PLANES]
int mpv_flags
flags set by private options
int16_t(* b_bidir_back_mv_table)[2]
MV table (1MV per MB) bidir mode B-frame.
int max_b_frames
max number of B-frames
int frame_bits
bits used for the current frame
int stuffing_bits
bits used for stuffing
MPVEncContext s
The main slicecontext.
char * me_map_base
backs MotionEstContext.(map|score_map)
RateControlContext rc_context
contains stuff only accessed in ratecontrol.c
int16_t(* mv_table_base)[2]
int vbv_delay_pos
offset of vbv_delay in the bitstream
int last_non_b_pict_type
used for MPEG-4 gmc B-frames & ratecontrol
int64_t mc_mb_var_sum
motion compensated MB variance for current frame
int last_lambda_for[5]
last lambda for a specific pict type
int64_t dts_delta
pts difference between the first and second input frame, used for calculating dts of the first frame ...
const uint8_t * fcode_tab
smallest fcode needed for each MV
int64_t mb_var_sum
sum of MB variance for current frame
char * dct_error_sum_base
backs dct_error_sum
AVFrame * tmp_frames[MPVENC_MAX_B_FRAMES+2]
temporary frames used by b_frame_strategy = 2
int picture_in_gop_number
0-> first pic in gop, ...
int coded_picture_number
used to set pic->coded_picture_number
int fixed_qscale
fixed qscale if non zero
int next_lambda
next lambda used for retrying to encode a frame
int64_t user_specified_pts
last non-zero pts from user-supplied AVFrame
int input_picture_number
used to set pic->display_picture_number
int64_t reordered_pts
reordered pts to be used as dts for the next output frame when there's a delay
MPVPicture * reordered_input_picture[MPVENC_MAX_B_FRAMES+1]
next pictures in coded order
MPVPicture * input_picture[MPVENC_MAX_B_FRAMES+1]
next pictures in display order
me_cmp_func frame_skip_cmp_fn
int intra_only
if true, only intra pictures are generated
int me_pre
prepass for motion estimation
int(* encode_picture_header)(struct MPVMainEncContext *m)
MPVPicture.
Definition mpegpicture.h:58
Motion estimation context.
Definition motion_est.h:49
MpegEncContext.
Definition mpegvideo.h:67
rate control context.
Definition ratecontrol.h:60
static int bias(int x, int c)
Definition vqcdec.c:115