35 #define ME_MODE_BIDIR 0 36 #define ME_MODE_BILAT 1 38 #define MC_MODE_OBMC 0 39 #define MC_MODE_AOBMC 1 41 #define SCD_METHOD_NONE 0 42 #define SCD_METHOD_FDIFF 1 45 #define NB_PIXEL_MVS 32 46 #define NB_CLUSTERS 128 48 #define ALPHA_MAX 1024 49 #define CLUSTER_THRESHOLD 4 50 #define PX_WEIGHT_MAX 255 51 #define COST_PRED_SCALE 64 54 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
55 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
56 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
57 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
58 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
59 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
60 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
61 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
62 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
63 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
64 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
65 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
66 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
67 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
68 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
69 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
70 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
71 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
72 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
73 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
74 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
75 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
76 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
77 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
78 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
79 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
80 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
81 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
82 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
83 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
84 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
85 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
89 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
90 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
91 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
92 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
93 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
94 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
95 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
96 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
97 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
98 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
99 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
100 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
101 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
102 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
103 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
104 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
108 4, 12, 20, 28, 28, 20, 12, 4,
109 12, 36, 60, 84, 84, 60, 36, 12,
110 20, 60,100,140,140,100, 60, 20,
111 28, 84,140,196,196,140, 84, 28,
112 28, 84,140,196,196,140, 84, 28,
113 20, 60,100,140,140,100, 60, 20,
114 12, 36, 60, 84, 84, 60, 36, 12,
115 4, 12, 20, 28, 28, 20, 12, 4,
140 typedef struct Block {
161 typedef struct Frame {
201 #define OFFSET(x) offsetof(MIContext, x) 202 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 203 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit } 213 CONST(
"aobmc",
"adaptive overlapped block motion compensation",
MC_MODE_AOBMC,
"mc_mode"),
228 {
"search_param",
"search parameter",
OFFSET(search_param),
AV_OPT_TYPE_INT, {.i64 = 32}, 4, INT_MAX, FLAGS },
229 {
"vsbmc",
"variable-size block motion compensation",
OFFSET(vsbmc),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
233 {
"scd_threshold",
"scene change threshold",
OFFSET(scd_threshold),
AV_OPT_TYPE_DOUBLE, {.dbl = 10.}, 0, 100.0, FLAGS },
264 int mv_x1 = x_mv - x;
265 int mv_y1 = y_mv - y;
266 int mv_x, mv_y,
i, j;
274 data_cur += (y + mv_y) * linesize;
275 data_next += (y - mv_y) * linesize;
277 for (j = 0; j < me_ctx->
mb_size; j++)
278 for (i = 0; i < me_ctx->
mb_size; i++)
279 sbad +=
FFABS(data_cur[x + mv_x + i + j * linesize] - data_next[x - mv_x + i + j * linesize]);
293 int mv_x1 = x_mv - x;
294 int mv_y1 = y_mv - y;
295 int mv_x, mv_y,
i, j;
298 x = av_clip(x, x_min, x_max);
299 y = av_clip(y, y_min, y_max);
300 mv_x = av_clip(x_mv - x, -
FFMIN(x - x_min, x_max - x),
FFMIN(x - x_min, x_max - x));
301 mv_y = av_clip(y_mv - y, -
FFMIN(y - y_min, y_max - y),
FFMIN(y - y_min, y_max - y));
303 for (j = -me_ctx->
mb_size / 2; j < me_ctx->mb_size * 3 / 2; j++)
304 for (i = -me_ctx->
mb_size / 2; i < me_ctx->mb_size * 3 / 2; i++)
305 sbad +=
FFABS(data_cur[x + mv_x + i + (y + mv_y + j) * linesize] - data_next[x - mv_x + i + (y - mv_y + j) * linesize]);
324 x = av_clip(x, x_min, x_max);
325 y = av_clip(y, y_min, y_max);
326 x_mv = av_clip(x_mv, x_min, x_max);
327 y_mv = av_clip(y_mv, y_min, y_max);
329 for (j = -me_ctx->
mb_size / 2; j < me_ctx->mb_size * 3 / 2; j++)
330 for (i = -me_ctx->
mb_size / 2; i < me_ctx->mb_size * 3 / 2; i++)
331 sad +=
FFABS(data_ref[x_mv + i + (y_mv + j) * linesize] - data_cur[x + i + (y + j) * linesize]);
342 const int width = inlink->
w;
391 for (i = 0; i < 3; i++) {
418 #define ADD_PRED(preds, px, py)\ 420 preds.mvs[preds.nb][0] = px;\ 421 preds.mvs[preds.nb][1] = py;\ 433 const int mb_i = mb_x + mb_y * mi_ctx->
b_width;
434 int mv[2] = {x_mb, y_mb};
474 if (mb_y > 0 && mb_x + 1 < mi_ctx->
b_width)
478 if (preds[0].
nb == 4) {
479 me_ctx->
pred_x =
mid_pred(preds[0].mvs[1][0], preds[0].mvs[2][0], preds[0].mvs[3][0]);
480 me_ctx->
pred_y =
mid_pred(preds[0].mvs[1][1], preds[0].mvs[2][1], preds[0].mvs[3][1]);
481 }
else if (preds[0].
nb == 3) {
482 me_ctx->
pred_x =
mid_pred(0, preds[0].mvs[1][0], preds[0].mvs[2][0]);
483 me_ctx->
pred_y =
mid_pred(0, preds[0].mvs[1][1], preds[0].mvs[2][1]);
484 }
else if (preds[0].
nb == 2) {
508 if (mb_x + 1 < mi_ctx->
b_width)
517 mi_ctx->
mv_table[0][mb_i][dir][0] = mv[0] - x_mb;
518 mi_ctx->
mv_table[0][mb_i][dir][1] = mv[1] - y_mb;
529 ADD_PRED(preds[0], blocks[mb_i - 1].mvs[dir][0], blocks[mb_i - 1].mvs[dir][1]);
536 if (mb_x + 1 < mi_ctx->
b_width)
544 if (preds[0].
nb == 4) {
545 me_ctx->
pred_x =
mid_pred(preds[0].mvs[1][0], preds[0].mvs[2][0], preds[0].mvs[3][0]);
546 me_ctx->
pred_y =
mid_pred(preds[0].mvs[1][1], preds[0].mvs[2][1], preds[0].mvs[3][1]);
547 }
else if (preds[0].
nb == 3) {
548 me_ctx->
pred_x =
mid_pred(0, preds[0].mvs[1][0], preds[0].mvs[2][0]);
549 me_ctx->
pred_y =
mid_pred(0, preds[0].mvs[1][1], preds[0].mvs[2][1]);
550 }
else if (preds[0].
nb == 2) {
563 block->
mvs[dir][0] = mv[0] - x_mb;
564 block->
mvs[dir][1] = mv[1] - y_mb;
572 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
573 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++) {
579 block->
mvs[0][0] = 0;
580 block->
mvs[0][1] = 0;
583 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
584 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++)
591 uint64_t cost_sb, cost_old;
599 cost_old = me_ctx->
get_cost(me_ctx, x_mb, y_mb, x_mb + block->
mvs[0][0], y_mb + block->
mvs[0][1]);
615 for (y = 0; y < 2; y++)
616 for (x = 0; x < 2; x++) {
618 int mv[2] = {x_mb + block->
mvs[0][0], y_mb + block->
mvs[0][1]};
620 me_ctx->
mb_size = 1 << (n - 1);
632 if (cost_sb < cost_old / 4) {
633 sb->
mvs[0][0] = mv_x;
634 sb->
mvs[0][1] = mv_y;
637 if (ret =
var_size_bme(mi_ctx, sb, x_mb + (x << (n - 1)), y_mb + (y << (n - 1)), n - 1))
652 int changed,
c, c_max = 0;
653 int mb_x, mb_y, x, y;
654 int mv_x, mv_y, avg_x, avg_y, dx, dy;
657 Cluster *cluster, *cluster_new;
661 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
662 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++) {
666 mv_x = block->
mvs[0][0];
667 mv_y = block->
mvs[0][1];
672 avg_x = cluster->
sum[0] / cluster->
nb;
673 avg_y = cluster->
sum[1] / cluster->
nb;
679 for (d = 1; d < 5; d++)
683 if (nb->
cid > block->
cid) {
684 if (nb->
cid < c || c == block->
cid)
697 cluster_new->
sum[0] += mv_x;
698 cluster_new->
sum[1] += mv_y;
699 cluster->
sum[0] -= mv_x;
700 cluster->
sum[1] -= mv_y;
704 c_max =
FFMAX(c_max, c);
713 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
714 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++) {
721 if ((x - mb_x) && (y - mb_y) || !dx && !dy)
724 if (!mb_x || !mb_y || mb_x == mi_ctx->
b_width - 1 || mb_y == mi_ctx->
b_height - 1)
748 frame_tmp = mi_ctx->
frames[0];
763 for (dir = 0; dir < 2; dir++) {
768 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
769 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++)
789 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
790 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++) {
807 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
808 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++) {
838 mi_ctx->
sad(p1, linesize1, p2, linesize2, input->
w, input->
h, &sad);
840 mafd = (double) sad * 100.0 / (input->
h * input->
w) / (1 << mi_ctx->
bitdepth);
842 ret = av_clipf(
FFMIN(mafd, diff), 0, 100.0);
851 #define ADD_PIXELS(b_weight, mv_x, mv_y)\ 853 if (!b_weight || pixel_refs->nb + 1 >= NB_PIXEL_MVS)\ 855 pixel_refs->refs[pixel_refs->nb] = 1;\ 856 pixel_weights->weights[pixel_refs->nb] = b_weight * (ALPHA_MAX - alpha);\ 857 pixel_mvs->mvs[pixel_refs->nb][0] = av_clip((mv_x * alpha) / ALPHA_MAX, x_min, x_max);\ 858 pixel_mvs->mvs[pixel_refs->nb][1] = av_clip((mv_y * alpha) / ALPHA_MAX, y_min, y_max);\ 860 pixel_refs->refs[pixel_refs->nb] = 2;\ 861 pixel_weights->weights[pixel_refs->nb] = b_weight * alpha;\ 862 pixel_mvs->mvs[pixel_refs->nb][0] = av_clip(-mv_x * (ALPHA_MAX - alpha) / ALPHA_MAX, x_min, x_max);\ 863 pixel_mvs->mvs[pixel_refs->nb][1] = av_clip(-mv_y * (ALPHA_MAX - alpha) / ALPHA_MAX, y_min, y_max);\ 874 for (y = 0; y <
height; y++)
875 for (x = 0; x <
width; x++)
878 for (dir = 0; dir < 2; dir++)
879 for (mb_y = 0; mb_y < mi_ctx->
b_height; mb_y++)
880 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++) {
884 int start_x, start_y;
885 int startc_x, startc_y, endc_x, endc_y;
890 startc_x = av_clip(start_x, 0, width - 1);
891 startc_y = av_clip(start_y, 0, height - 1);
892 endc_x = av_clip(start_x + (2 << mi_ctx->
log2_mb_size), 0, width - 1);
893 endc_y = av_clip(start_y + (2 << mi_ctx->
log2_mb_size), 0, height - 1);
900 for (y = startc_y; y < endc_y; y++) {
902 int y_max = height - y - 1;
903 for (x = startc_x; x < endc_x; x++) {
905 int x_max = width - x - 1;
921 for (plane = 0; plane < mi_ctx->
nb_planes; plane++) {
924 int chroma = plane == 1 || plane == 2;
926 for (y = 0; y <
height; y++)
927 for (x = 0; x <
width; x++) {
935 for (i = 0; i < pixel_refs->
nb; i++)
936 weight_sum += pixel_weights->
weights[i];
938 if (!weight_sum || !pixel_refs->
nb) {
940 pixel_refs->
refs[0] = 1;
941 pixel_mvs->
mvs[0][0] = 0;
942 pixel_mvs->
mvs[0][1] = 0;
944 pixel_refs->
refs[1] = 2;
945 pixel_mvs->
mvs[1][0] = 0;
946 pixel_mvs->
mvs[1][1] = 0;
952 for (i = 0; i < pixel_refs->
nb; i++) {
958 x_mv = x + pixel_mvs->
mvs[
i][0];
959 y_mv = y + pixel_mvs->
mvs[
i][1];
981 for (sb_y = 0; sb_y < 2; sb_y++)
982 for (sb_x = 0; sb_x < 2; sb_x++) {
983 Block *sb = &block->
subs[sb_x + sb_y * 2];
986 var_size_bmc(mi_ctx, sb, x_mb + (sb_x << (n - 1)), y_mb + (sb_y << (n - 1)), n - 1, alpha);
989 int mv_x = sb->
mvs[0][0] * 2;
990 int mv_y = sb->
mvs[0][1] * 2;
992 int start_x = x_mb + (sb_x << (n - 1));
993 int start_y = y_mb + (sb_y << (n - 1));
994 int end_x = start_x + (1 << (n - 1));
995 int end_y = start_y + (1 << (n - 1));
997 for (y = start_y; y < end_y; y++) {
999 int y_max = height - y - 1;
1000 for (x = start_x; x < end_x; x++) {
1002 int x_max = width - x - 1;
1024 int mv_x = block->
mvs[0][0] * 2;
1025 int mv_y = block->
mvs[0][1] * 2;
1026 int start_x, start_y;
1027 int startc_x, startc_y, endc_x, endc_y;
1031 for (nb_x =
FFMAX(0, mb_x - 1); nb_x <
FFMIN(mb_x + 2, mi_ctx->
b_width); nb_x++) {
1035 if (nb_x - mb_x || nb_y - mb_y)
1036 sbads[nb_x - mb_x + 1 + (nb_y - mb_y + 1) * 3] =
get_sbad(&mi_ctx->
me_ctx, x_nb, y_nb, x_nb + block->
mvs[0][0], y_nb + block->
mvs[0][1]);
1042 startc_x = av_clip(start_x, 0, width - 1);
1043 startc_y = av_clip(start_y, 0, height - 1);
1044 endc_x = av_clip(start_x + (2 << mi_ctx->
log2_mb_size), 0, width - 1);
1045 endc_y = av_clip(start_y + (2 << mi_ctx->
log2_mb_size), 0, height - 1);
1047 for (y = startc_y; y < endc_y; y++) {
1049 int y_max = height - y - 1;
1050 for (x = startc_x; x < endc_x; x++) {
1052 int x_max = width - x - 1;
1059 nb_x = (((x - start_x) >> (mi_ctx->
log2_mb_size - 1)) * 2 - 3) / 2;
1060 nb_y = (((y - start_y) >> (mi_ctx->
log2_mb_size - 1)) * 2 - 3) / 2;
1063 uint64_t sbad = sbads[nb_x + 1 + (nb_y + 1) * 3];
1066 if (sbad && sbad != UINT64_MAX && nb->sbad != UINT64_MAX) {
1068 obmc_weight = obmc_weight * phi /
ALPHA_MAX;
1091 alpha = av_clip(alpha, 0, ALPHA_MAX);
1093 if (alpha == 0 || alpha == ALPHA_MAX) {
1111 for (plane = 0; plane < mi_ctx->
nb_planes; plane++) {
1115 if (plane == 1 || plane == 2) {
1120 for (y = 0; y <
height; y++) {
1121 for (x = 0; x <
width; x++) {
1122 avf_out->
data[plane][x + y * avf_out->
linesize[plane]] =
1144 for (mb_x = 0; mb_x < mi_ctx->
b_width; mb_x++) {
1228 for (m = 0; m < mi_ctx->
b_count; m++)
1238 for (i = 0; i < 3; i++)
1262 .
name =
"minterpolate",
1265 .priv_class = &minterpolate_class,
1268 .
inputs = minterpolate_inputs,
1269 .
outputs = minterpolate_outputs,
uint64_t ff_me_search_hexbs(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
static const uint8_t obmc_linear32[1024]
void(* ff_scene_sad_fn)(SCENE_SAD_PARAMS)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
int8_t refs[NB_PIXEL_MVS]
static const AVFilterPad minterpolate_outputs[]
static const uint8_t obmc_linear4[16]
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Main libavfilter public API header.
ff_scene_sad_fn ff_scene_sad_get_fn(int depth)
int h
agreed upon image height
int pred_y
median predictor y
#define AV_ME_METHOD_TDLS
static av_cold void free_blocks(Block *block, int sb)
uint64_t(* get_cost)(struct AVMotionEstContext *me_ctx, int x_mb, int y_mb, int mv_x, int mv_y)
static const AVOption minterpolate_options[]
static void bilateral_obmc(MIContext *mi_ctx, Block *block, int mb_x, int mb_y, int alpha)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
if it could not because there are no more frames
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static int detect_scene_change(AVFilterContext *ctx)
AVMotionEstPredictor preds[2]
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
uint64_t ff_me_search_fss(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
The exact code depends on how similar the blocks are and how related they are to the block
#define AV_ME_METHOD_NTSS
static void interpolate(AVFilterLink *inlink, AVFrame *avf_out)
uint32_t weights[NB_PIXEL_MVS]
int pred_x
median predictor x
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
uint64_t ff_me_search_ds(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
Cluster clusters[NB_CLUSTERS]
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AV_ME_METHOD_EPZS
static uint64_t get_sbad(AVMotionEstContext *me_ctx, int x, int y, int x_mv, int y_mv)
uint64_t ff_me_search_umh(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_LOG_VERBOSE
Detailed information.
#define CONST(name, help, val, unit)
static void set_frame_data(MIContext *mi_ctx, int alpha, AVFrame *avf_out)
static void bilateral_me(MIContext *mi_ctx)
#define ROUNDED_DIV(a, b)
static const uint8_t obmc_linear16[256]
#define AV_ME_METHOD_HEXBS
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static uint64_t get_sad_ob(AVMotionEstContext *me_ctx, int x, int y, int x_mv, int y_mv)
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
static __device__ float fabs(float a)
static const int weights[]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint64_t ff_me_search_epzs(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
static int var_size_bme(MIContext *mi_ctx, Block *block, int x_mb, int y_mb, int n)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static int filter_frame(AVFilterLink *inlink, AVFrame *avf_in)
simple assert() macros that are a bit more flexible than ISO C assert().
static const uint8_t *const obmc_tab_linear[4]
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
static int cluster_mvs(MIContext *mi_ctx)
AVFilter ff_vf_minterpolate
uint64_t ff_me_search_tdls(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
PixelWeights * pixel_weights
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
AVFilterContext * src
source filter
uint64_t ff_me_search_ntss(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
static const AVFilterPad outputs[]
int format
agreed upon media format
static const int8_t mv[256][2]
void ff_me_init_context(AVMotionEstContext *me_ctx, int mb_size, int search_param, int width, int height, int x_min, int x_max, int y_min, int y_max)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const int16_t alpha[]
static int config_input(AVFilterLink *inlink)
#define ME_MODE_BIDIR
Copyright (c) 2014-2015 Michael Niedermayer michaelni@gmx.at Copyright (c) 2016 Davinder Singh (DSM_)...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
static void var_size_bmc(MIContext *mi_ctx, Block *block, int x_mb, int y_mb, int n, int alpha)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
#define ADD_PIXELS(b_weight, mv_x, mv_y)
Describe the class of an AVClass context structure.
static const AVFilterPad minterpolate_inputs[]
Rational number (pair of numerator and denominator).
offset must point to AVRational
const char * name
Filter name.
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
uint64_t ff_me_search_esa(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int config_output(AVFilterLink *outlink)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
AVFILTER_DEFINE_CLASS(minterpolate)
AVMotionEstContext me_ctx
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AV_ME_METHOD_ESA
Copyright (c) 2016 Davinder Singh (DSM_) <ds.mudhar<.com>
uint64_t ff_me_search_tss(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
static int query_formats(AVFilterContext *ctx)
static void search_mv(MIContext *mi_ctx, Block *blocks, int mb_x, int mb_y, int dir)
#define ADD_PRED(preds, px, py)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
AVFilterContext * dst
dest filter
int16_t mvs[NB_PIXEL_MVS][2]
#define CLUSTER_THRESHOLD
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static int inject_frame(AVFilterLink *inlink, AVFrame *avf_in)
static void bidirectional_obmc(MIContext *mi_ctx, int alpha)
static av_always_inline av_const int av_ceil_log2_c(int x)
Compute ceil(log2(x)).
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int depth
Number of bits in the component.
static const uint8_t obmc_linear8[64]
static uint64_t get_sbad_ob(AVMotionEstContext *me_ctx, int x, int y, int x_mv, int y_mv)
AVPixelFormat
Pixel format.
static double val(void *priv, double ch)
static av_cold void uninit(AVFilterContext *ctx)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_CEIL_RSHIFT(a, b)
void * av_mallocz_array(size_t nmemb, size_t size)