Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Michael Niedermayer authored on 2011/10/04 15:25:23... | ... |
@@ -90,6 +90,7 @@ typedef struct { |
90 | 90 |
Transform last; ///< Transform from last frame |
91 | 91 |
int refcount; ///< Number of reference frames (defines averaging window) |
92 | 92 |
FILE *fp; |
93 |
+ Transform avg; |
|
93 | 94 |
} DeshakeContext; |
94 | 95 |
|
95 | 96 |
static int cmp(void const *ca, void const *cb) |
... | ... |
@@ -404,15 +405,7 @@ static void end_frame(AVFilterLink *link) |
404 | 404 |
AVFilterBufferRef *in = link->cur_buf; |
405 | 405 |
AVFilterBufferRef *out = link->dst->outputs[0]->out_buf; |
406 | 406 |
Transform t; |
407 |
- static float matrix[9]; |
|
408 |
- static Transform avg = { |
|
409 |
- .vector = { |
|
410 |
- .x = 0, |
|
411 |
- .y = 0 |
|
412 |
- }, |
|
413 |
- .angle = 0, |
|
414 |
- .zoom = 0.0f |
|
415 |
- }; |
|
407 |
+ float matrix[9]; |
|
416 | 408 |
float alpha = 2.0 / deshake->refcount; |
417 | 409 |
char tmp[256]; |
418 | 410 |
Transform orig; |
... | ... |
@@ -427,17 +420,17 @@ static void end_frame(AVFilterLink *link) |
427 | 427 |
orig.zoom = t.zoom; |
428 | 428 |
|
429 | 429 |
// Generate a one-sided moving exponential average |
430 |
- avg.vector.x = alpha * t.vector.x + (1.0 - alpha) * avg.vector.x; |
|
431 |
- avg.vector.y = alpha * t.vector.y + (1.0 - alpha) * avg.vector.y; |
|
432 |
- avg.angle = alpha * t.angle + (1.0 - alpha) * avg.angle; |
|
433 |
- avg.zoom = alpha * t.zoom + (1.0 - alpha) * avg.zoom; |
|
430 |
+ deshake->avg.vector.x = alpha * t.vector.x + (1.0 - alpha) * deshake->avg.vector.x; |
|
431 |
+ deshake->avg.vector.y = alpha * t.vector.y + (1.0 - alpha) * deshake->avg.vector.y; |
|
432 |
+ deshake->avg.angle = alpha * t.angle + (1.0 - alpha) * deshake->avg.angle; |
|
433 |
+ deshake->avg.zoom = alpha * t.zoom + (1.0 - alpha) * deshake->avg.zoom; |
|
434 | 434 |
|
435 | 435 |
// Remove the average from the current motion to detect the motion that |
436 | 436 |
// is not on purpose, just as jitter from bumping the camera |
437 |
- t.vector.x -= avg.vector.x; |
|
438 |
- t.vector.y -= avg.vector.y; |
|
439 |
- t.angle -= avg.angle; |
|
440 |
- t.zoom -= avg.zoom; |
|
437 |
+ t.vector.x -= deshake->avg.vector.x; |
|
438 |
+ t.vector.y -= deshake->avg.vector.y; |
|
439 |
+ t.angle -= deshake->avg.angle; |
|
440 |
+ t.zoom -= deshake->avg.zoom; |
|
441 | 441 |
|
442 | 442 |
// Invert the motion to undo it |
443 | 443 |
t.vector.x *= -1; |
... | ... |
@@ -445,7 +438,7 @@ static void end_frame(AVFilterLink *link) |
445 | 445 |
t.angle *= -1; |
446 | 446 |
|
447 | 447 |
// Write statistics to file |
448 |
- snprintf(tmp, 256, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n", orig.vector.x, avg.vector.x, t.vector.x, orig.vector.y, avg.vector.y, t.vector.y, orig.angle, avg.angle, t.angle, orig.zoom, avg.zoom, t.zoom); |
|
448 |
+ snprintf(tmp, 256, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n", orig.vector.x, deshake->avg.vector.x, t.vector.x, orig.vector.y, deshake->avg.vector.y, t.vector.y, orig.angle, deshake->avg.angle, t.angle, orig.zoom, deshake->avg.zoom, t.zoom); |
|
449 | 449 |
fwrite(tmp, sizeof(char), strlen(tmp), deshake->fp); |
450 | 450 |
|
451 | 451 |
// Turn relative current frame motion into absolute by adding it to the |