FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
h263enc.h
Go to the documentation of this file.
1 /*
2  * H.263 encoder header
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 #ifndef AVCODEC_H263ENC_H
21 #define AVCODEC_H263ENC_H
22 
23 #include <stdint.h>
24 #include "h263data.h"
25 #include "mpegvideoenc.h"
26 
27 const uint8_t (*ff_h263_get_mv_penalty(void))[MAX_DMV*2+1];
28 
31 void ff_h263_encode_gob_header(MPVEncContext *s, int mb_line);
33 
35 
36 void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code);
38 
40  int x, int y, int f_code)
41 {
42  ff_h263_encode_motion(&s->pb, x, f_code);
43  ff_h263_encode_motion(&s->pb, y, f_code);
44 }
45 
46 static inline int get_p_cbp(MPVEncContext *const s,
47  int16_t block[6][64],
48  int motion_x, int motion_y){
49  int cbp;
50 
51  if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
52  int best_cbpy_score = INT_MAX;
53  int best_cbpc_score = INT_MAX;
54  int cbpc = (-1), cbpy = (-1);
55  const int offset = (s->c.mv_type == MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0);
56  const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
57 
58  for (int i = 0; i < 4; i++) {
59  int score = ff_h263_inter_MCBPC_bits[i + offset] * lambda;
60  if (i & 1) score += s->coded_score[5];
61  if (i & 2) score += s->coded_score[4];
62 
63  if (score < best_cbpc_score) {
64  best_cbpc_score = score;
65  cbpc = i;
66  }
67  }
68 
69  for (int i = 0; i < 16; i++) {
70  int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda;
71  if (i & 1) score += s->coded_score[3];
72  if (i & 2) score += s->coded_score[2];
73  if (i & 4) score += s->coded_score[1];
74  if (i & 8) score += s->coded_score[0];
75 
76  if (score < best_cbpy_score) {
77  best_cbpy_score = score;
78  cbpy = i;
79  }
80  }
81  cbp = cbpc + 4 * cbpy;
82  if (!(motion_x | motion_y | s->dquant) && s->c.mv_type == MV_TYPE_16X16) {
83  if (best_cbpy_score + best_cbpc_score + 2 * lambda >= 0)
84  cbp= 0;
85  }
86 
87  for (int i = 0; i < 6; i++) {
88  if (s->c.block_last_index[i] >= 0 && !((cbp >> (5 - i)) & 1)) {
89  s->c.block_last_index[i] = -1;
90  s->c.bdsp.clear_block(s->c.block[i]);
91  }
92  }
93  } else {
94  cbp = 0;
95  for (int i = 0; i < 6; i++) {
96  if (s->c.block_last_index[i] >= 0)
97  cbp |= 1 << (5 - i);
98  }
99  }
100  return cbp;
101 }
102 
103 #endif
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:185
h263data.h
MPVEncContext
Definition: mpegvideoenc.h:45
mpegvideoenc.h
ff_clean_h263_qscales
void ff_clean_h263_qscales(MPVEncContext *s)
MAX_DMV
#define MAX_DMV
Definition: motion_est.h:39
FF_LAMBDA_SHIFT
#define FF_LAMBDA_SHIFT
Definition: avutil.h:224
ff_h263_encode_init
void ff_h263_encode_init(MPVMainEncContext *m)
val
static double val(void *priv, double ch)
Definition: aeval.c:77
FF_MPV_FLAG_CBP_RD
#define FF_MPV_FLAG_CBP_RD
Definition: mpegvideoenc.h:290
ff_h263_encode_gob_header
void ff_h263_encode_gob_header(MPVEncContext *s, int mb_line)
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_h263_encode_mba
void ff_h263_encode_mba(MPVEncContext *s)
PutBitContext
Definition: put_bits.h:50
get_p_cbp
static int get_p_cbp(MPVEncContext *const s, int16_t block[6][64], int motion_x, int motion_y)
Definition: h263enc.h:46
MPVMainEncContext
Definition: mpegvideoenc.h:178
ff_h263_get_mv_penalty
const uint8_t(* ff_h263_get_mv_penalty(void))[MAX_DMV *2+1]
Definition: ituh263enc.c:157
ff_h263_cbpy_tab
const uint8_t ff_h263_cbpy_tab[16][2]
Definition: h263data.c:82
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
ff_h263_inter_MCBPC_bits
const uint8_t ff_h263_inter_MCBPC_bits[28]
Definition: h263data.c:47
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_h263_update_mb
void ff_h263_update_mb(MPVEncContext *s)
ff_h263_mpeg4_reset_dc
void ff_h263_mpeg4_reset_dc(MPVEncContext *s)
ff_h263_encode_motion_vector
static void ff_h263_encode_motion_vector(MPVEncContext *s, int x, int y, int f_code)
Definition: h263enc.h:39
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
ff_h263_encode_motion
void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
Definition: ituh263enc.c:166