FFmpeg
|
#include "avfilter.h"
#include "internal.h"
#include "video.h"
#include "libavutil/common.h"
#include "libavutil/emms.h"
#include "libavutil/file_open.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/qsort.h"
#include "deshake.h"
Go to the source code of this file.
Macros | |
#define | OFFSET(x) offsetof(DeshakeContext, x) |
#define | FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM |
#define | CMP(i, j) |
Functions | |
AVFILTER_DEFINE_CLASS (deshake) | |
static int | cmp (const void *a, const void *b) |
static double | clean_mean (double *values, int count) |
Cleaned mean (cuts off 20% of values to remove outliers and then averages) More... | |
static void | find_block_motion (DeshakeContext *deshake, uint8_t *src1, uint8_t *src2, int cx, int cy, int stride, IntMotionVector *mv) |
Find the most likely shift in motion between two frames for a given macroblock. More... | |
static int | block_contrast (uint8_t *src, int x, int y, int stride, int blocksize) |
Find the contrast of a given block. More... | |
static double | block_angle (int x, int y, int cx, int cy, IntMotionVector *shift) |
Find the rotation for a given block. More... | |
static void | find_motion (DeshakeContext *deshake, uint8_t *src1, uint8_t *src2, int width, int height, int stride, Transform *t) |
Find the estimated global motion for a scene given the most likely shift for each block in the frame. More... | |
static int | deshake_transform_c (AVFilterContext *ctx, int width, int height, int cw, int ch, const float *matrix_y, const float *matrix_uv, enum InterpolateMethod interpolate, enum FillMethod fill, AVFrame *in, AVFrame *out) |
static av_cold int | init (AVFilterContext *ctx) |
static int | config_props (AVFilterLink *link) |
static av_cold void | uninit (AVFilterContext *ctx) |
static int | filter_frame (AVFilterLink *link, AVFrame *in) |
Variables | |
static const AVOption | deshake_options [] |
static enum AVPixelFormat | pix_fmts [] |
static const AVFilterPad | deshake_inputs [] |
const AVFilter | ff_vf_deshake |
fast deshake / depan video filter
SAD block-matching motion compensation to fix small changes in horizontal and/or vertical shift. This filter helps remove camera shake from hand-holding a camera, bumping a tripod, moving on a vehicle, etc.
Algorithm:
TODO:
Dark Shikari links to http://wiki.videolan.org/SoC_x264_2010#GPU_Motion_Estimation_2 for an algorithm similar to what could be used here to get the gmv It requires only a couple diamond searches + fast downscaling
Special thanks to Jason Kotenko for his help with the algorithm and my inability to see simple errors in C code.
Definition in file vf_deshake.c.
#define OFFSET | ( | x | ) | offsetof(DeshakeContext, x) |
Definition at line 65 of file vf_deshake.c.
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM |
Definition at line 66 of file vf_deshake.c.
#define CMP | ( | i, | |
j | |||
) |
AVFILTER_DEFINE_CLASS | ( | deshake | ) |
|
static |
Definition at line 92 of file vf_deshake.c.
Referenced by clean_mean().
Cleaned mean (cuts off 20% of values to remove outliers and then averages)
Definition at line 100 of file vf_deshake.c.
Referenced by find_motion().
|
static |
Find the most likely shift in motion between two frames for a given macroblock.
Test each block against several shifts given by the rx and ry attributes. Searches using a simple matrix of those shifts and chooses the most likely shift by the smallest difference in blocks.
Definition at line 121 of file vf_deshake.c.
Referenced by find_motion().
Find the contrast of a given block.
When searching for global motion we really only care about the high contrast blocks, so using this method we can actually skip blocks we don't care much about.
Definition at line 191 of file vf_deshake.c.
Referenced by find_motion().
Find the rotation for a given block.
Definition at line 215 of file vf_deshake.c.
Referenced by find_motion().
|
static |
Find the estimated global motion for a scene given the most likely shift for each block in the frame.
The global motion is estimated to be the same as the motion from most blocks in the frame, so if most blocks move one pixel to the right and two pixels down, this would yield a motion vector (1, -2).
Definition at line 236 of file vf_deshake.c.
Referenced by filter_frame().
|
static |
Definition at line 316 of file vf_deshake.c.
Referenced by init().
|
static |
Definition at line 343 of file vf_deshake.c.
|
static |
Definition at line 382 of file vf_deshake.c.
|
static |
Definition at line 395 of file vf_deshake.c.
|
static |
Definition at line 405 of file vf_deshake.c.
|
static |
Definition at line 68 of file vf_deshake.c.
|
static |
Definition at line 376 of file vf_deshake.c.
|
static |
Definition at line 530 of file vf_deshake.c.
const AVFilter ff_vf_deshake |
Definition at line 539 of file vf_deshake.c.