FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_deshake_opencl.c File Reference
#include <stdbool.h>
#include <float.h>
#include <libavutil/lfg.h>
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/fifo.h"
#include "libavutil/common.h"
#include "libavutil/avassert.h"
#include "libavutil/pixfmt.h"
#include "avfilter.h"
#include "framequeue.h"
#include "filters.h"
#include "transform.h"
#include "formats.h"
#include "internal.h"
#include "opencl.h"
#include "opencl_source.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  PointPair
 
struct  MotionVector
 
struct  DebugMatches
 
struct  AbsoluteFrameMotion
 
struct  FrameDelta
 
struct  SimilarityMatrix
 
struct  CropInfo
 
struct  IterIndices
 
struct  DeshakeOpenCLContext
 

Macros

#define BREIFN   512
 
#define BRIEF_PATCH_SIZE   31
 
#define BRIEF_PATCH_SIZE_HALF   (BRIEF_PATCH_SIZE / 2)
 
#define MATCHES_CONTIG_SIZE   2000
 
#define ROUNDED_UP_DIV(a, b)   ((a + (b - 1)) / b)
 
#define OFFSET(x)   offsetof(DeshakeOpenCLContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 

Enumerations

enum  RingbufferIndices {
  RingbufX, RingbufY, RingbufRot, RingbufScaleX,
  RingbufScaleY, RingbufCount
}
 

Functions

static void free_debug_matches (AbsoluteFrameMotion *afm)
 
static int rand_in (int low, int high, AVLFG *alfg)
 
static double averaged_event_time_ms (unsigned long long total_time, int num_frames)
 
static void run_estimate_kernel (const MotionVector *point_pairs, double *model)
 
static bool points_not_collinear (const cl_float2 **points)
 
static bool check_subset (const MotionVector *pairs_subset)
 
static bool get_subset (AVLFG *alfg, const MotionVector *point_pairs, const int num_point_pairs, MotionVector *pairs_subset, int max_attempts)
 
static void compute_error (const MotionVector *point_pairs, const int num_point_pairs, const double *model, float *err)
 
static int find_inliers (MotionVector *point_pairs, const int num_point_pairs, const double *model, float *err, double thresh)
 
static int ransac_update_num_iters (double confidence, double num_outliers, int max_iters)
 
static bool estimate_affine_2d (DeshakeOpenCLContext *deshake_ctx, MotionVector *point_pairs, DebugMatches *debug_matches, const int num_point_pairs, double *model_out, const double threshold, const int max_iters, const double confidence)
 
static void optimize_model (DeshakeOpenCLContext *deshake_ctx, MotionVector *best_pairs, MotionVector *inliers, const int num_inliers, float best_err, double *model_out)
 
static bool minimize_error (DeshakeOpenCLContext *deshake_ctx, MotionVector *inliers, DebugMatches *debug_matches, const int num_inliers, double *model_out, const int max_iters)
 
static FrameDelta decompose_transform (double *model)
 
static int make_vectors_contig (DeshakeOpenCLContext *deshake_ctx, int size_y, int size_x)
 
static float gaussian_for (int x, float sigma)
 
static void make_gauss_kernel (float *gauss_kernel, float length, float sigma)
 
static IterIndices start_end_for (DeshakeOpenCLContext *deshake_ctx, int length)
 
static void ringbuf_float_at (DeshakeOpenCLContext *deshake_ctx, AVFifoBuffer *values, float *val, int offset)
 
static float smooth (DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifoBuffer *values)
 
static cl_float2 transformed_point (float x, float y, float *transform)
 
static void transform_center_scale (float x_shift, float y_shift, float angle, float scale_x, float scale_y, float center_w, float center_h, float *matrix)
 
static void update_needed_crop (CropInfo *crop, float *transform, float frame_width, float frame_height)
 
static av_cold void deshake_opencl_uninit (AVFilterContext *avctx)
 
static int deshake_opencl_init (AVFilterContext *avctx)
 
static void transform_debug (AVFilterContext *avctx, float *new_vals, float *old_vals, int curr_frame)
 
static int filter_frame (AVFilterLink *link, AVFrame *input_frame)
 
static int queue_frame (AVFilterLink *link, AVFrame *input_frame)
 
static int activate (AVFilterContext *ctx)
 
 AVFILTER_DEFINE_CLASS (deshake_opencl)
 

Variables

static const AVFilterPad deshake_opencl_inputs []
 
static const AVFilterPad deshake_opencl_outputs []
 
static const AVOption deshake_opencl_options []
 
AVFilter ff_vf_deshake_opencl
 

Macro Definition Documentation

#define BREIFN   512

Definition at line 88 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init().

#define BRIEF_PATCH_SIZE   31

Definition at line 91 of file vf_deshake_opencl.c.

#define BRIEF_PATCH_SIZE_HALF   (BRIEF_PATCH_SIZE / 2)

Definition at line 92 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init().

#define MATCHES_CONTIG_SIZE   2000

Definition at line 94 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init(), and make_vectors_contig().

#define ROUNDED_UP_DIV (   a,
  b 
)    ((a + (b - 1)) / b)

Definition at line 96 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init(), and queue_frame().

#define OFFSET (   x)    offsetof(DeshakeOpenCLContext, x)

Definition at line 2156 of file vf_deshake_opencl.c.

Definition at line 2157 of file vf_deshake_opencl.c.

Enumeration Type Documentation

Enumerator
RingbufX 
RingbufY 
RingbufRot 
RingbufScaleX 
RingbufScaleY 
RingbufCount 

Definition at line 112 of file vf_deshake_opencl.c.

Function Documentation

static void free_debug_matches ( AbsoluteFrameMotion afm)
static

Definition at line 153 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_uninit().

static int rand_in ( int  low,
int  high,
AVLFG alfg 
)
static

Definition at line 314 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init(), and get_subset().

static double averaged_event_time_ms ( unsigned long long  total_time,
int  num_frames 
)
static

Definition at line 320 of file vf_deshake_opencl.c.

Referenced by activate().

static void run_estimate_kernel ( const MotionVector point_pairs,
double *  model 
)
static

Definition at line 330 of file vf_deshake_opencl.c.

Referenced by estimate_affine_2d(), minimize_error(), and optimize_model().

static bool points_not_collinear ( const cl_float2 **  points)
static

Definition at line 360 of file vf_deshake_opencl.c.

Referenced by check_subset().

static bool check_subset ( const MotionVector pairs_subset)
static

Definition at line 386 of file vf_deshake_opencl.c.

Referenced by get_subset().

static bool get_subset ( AVLFG alfg,
const MotionVector point_pairs,
const int  num_point_pairs,
MotionVector pairs_subset,
int  max_attempts 
)
static

Definition at line 404 of file vf_deshake_opencl.c.

Referenced by estimate_affine_2d(), and minimize_error().

static void compute_error ( const MotionVector point_pairs,
const int  num_point_pairs,
const double *  model,
float *  err 
)
static

Definition at line 446 of file vf_deshake_opencl.c.

Referenced by find_inliers(), minimize_error(), and optimize_model().

static int find_inliers ( MotionVector point_pairs,
const int  num_point_pairs,
const double *  model,
float *  err,
double  thresh 
)
static

Definition at line 470 of file vf_deshake_opencl.c.

Referenced by estimate_affine_2d().

static int ransac_update_num_iters ( double  confidence,
double  num_outliers,
int  max_iters 
)
static

Definition at line 506 of file vf_deshake_opencl.c.

Referenced by estimate_affine_2d().

static bool estimate_affine_2d ( DeshakeOpenCLContext deshake_ctx,
MotionVector point_pairs,
DebugMatches debug_matches,
const int  num_point_pairs,
double *  model_out,
const double  threshold,
const int  max_iters,
const double  confidence 
)
static

Definition at line 528 of file vf_deshake_opencl.c.

Referenced by queue_frame().

static void optimize_model ( DeshakeOpenCLContext deshake_ctx,
MotionVector best_pairs,
MotionVector inliers,
const int  num_inliers,
float  best_err,
double *  model_out 
)
static

Definition at line 611 of file vf_deshake_opencl.c.

Referenced by minimize_error().

static bool minimize_error ( DeshakeOpenCLContext deshake_ctx,
MotionVector inliers,
DebugMatches debug_matches,
const int  num_inliers,
double *  model_out,
const int  max_iters 
)
static

Definition at line 684 of file vf_deshake_opencl.c.

Referenced by queue_frame().

static FrameDelta decompose_transform ( double *  model)
static

Definition at line 748 of file vf_deshake_opencl.c.

Referenced by queue_frame().

static int make_vectors_contig ( DeshakeOpenCLContext deshake_ctx,
int  size_y,
int  size_x 
)
static

Definition at line 786 of file vf_deshake_opencl.c.

Referenced by queue_frame().

static float gaussian_for ( int  x,
float  sigma 
)
static

Definition at line 812 of file vf_deshake_opencl.c.

Referenced by make_gauss_kernel().

static void make_gauss_kernel ( float *  gauss_kernel,
float  length,
float  sigma 
)
static

Definition at line 818 of file vf_deshake_opencl.c.

Referenced by smooth().

static IterIndices start_end_for ( DeshakeOpenCLContext deshake_ctx,
int  length 
)
static

Definition at line 842 of file vf_deshake_opencl.c.

Referenced by smooth().

static void ringbuf_float_at ( DeshakeOpenCLContext deshake_ctx,
AVFifoBuffer values,
float *  val,
int  offset 
)
static

Definition at line 853 of file vf_deshake_opencl.c.

Referenced by smooth().

static float smooth ( DeshakeOpenCLContext deshake_ctx,
float *  gauss_kernel,
int  length,
float  max_val,
AVFifoBuffer values 
)
static
static cl_float2 transformed_point ( float  x,
float  y,
float *  transform 
)
static

Definition at line 956 of file vf_deshake_opencl.c.

Referenced by transform_center_scale(), and update_needed_crop().

static void transform_center_scale ( float  x_shift,
float  y_shift,
float  angle,
float  scale_x,
float  scale_y,
float  center_w,
float  center_h,
float *  matrix 
)
static

Definition at line 966 of file vf_deshake_opencl.c.

Referenced by filter_frame().

static void update_needed_crop ( CropInfo crop,
float *  transform,
float  frame_width,
float  frame_height 
)
static

Definition at line 1004 of file vf_deshake_opencl.c.

Referenced by filter_frame().

static av_cold void deshake_opencl_uninit ( AVFilterContext avctx)
static

Definition at line 1065 of file vf_deshake_opencl.c.

static int deshake_opencl_init ( AVFilterContext avctx)
static

Definition at line 1124 of file vf_deshake_opencl.c.

Referenced by activate().

static void transform_debug ( AVFilterContext avctx,
float *  new_vals,
float *  old_vals,
int  curr_frame 
)
static

Definition at line 1357 of file vf_deshake_opencl.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink link,
AVFrame input_frame 
)
static

Definition at line 1385 of file vf_deshake_opencl.c.

Referenced by activate().

static int queue_frame ( AVFilterLink link,
AVFrame input_frame 
)
static

Definition at line 1749 of file vf_deshake_opencl.c.

Referenced by activate().

static int activate ( AVFilterContext ctx)
static

Definition at line 2039 of file vf_deshake_opencl.c.

AVFILTER_DEFINE_CLASS ( deshake_opencl  )

Variable Documentation

const AVFilterPad deshake_opencl_inputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
int ff_opencl_filter_config_input(AVFilterLink *inlink)
Check that the input link contains a suitable hardware frames context and extract the device from it...
Definition: opencl.c:60

Definition at line 2138 of file vf_deshake_opencl.c.

const AVFilterPad deshake_opencl_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
Definition: opencl.c:96

Definition at line 2147 of file vf_deshake_opencl.c.

const AVOption deshake_opencl_options[]
static
Initial value:
= {
{
"tripod", "simulates a tripod by preventing any camera movement whatsoever "
"from the original frame",
OFFSET(tripod_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS
},
{
"debug", "turn on additional debugging information",
OFFSET(debug_on), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS
},
{
"adaptive_crop", "attempt to subtly crop borders to reduce mirrored content",
OFFSET(should_crop), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS
},
{
"refine_features", "refine feature point locations at a sub-pixel level",
OFFSET(refine_features), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS
},
{
"smooth_strength", "smoothing strength (0 attempts to adaptively determine optimal strength)",
OFFSET(smooth_percent), AV_OPT_TYPE_FLOAT, {.dbl = 0.0f}, 0.0f, 1.0f, FLAGS
},
{
"smooth_window_multiplier", "multiplier for number of frames to buffer for motion data",
OFFSET(smooth_window_multiplier), AV_OPT_TYPE_FLOAT, {.dbl = 2.0}, 0.1, 10.0, FLAGS
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
#define FLAGS

Definition at line 2159 of file vf_deshake_opencl.c.

AVFilter ff_vf_deshake_opencl
Initial value:
= {
.name = "deshake_opencl",
.description = NULL_IF_CONFIG_SMALL("Feature-point based video stabilization filter"),
.priv_size = sizeof(DeshakeOpenCLContext),
.priv_class = &deshake_opencl_class,
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE
}
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:385
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
Definition: opencl.c:28
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
Definition: opencl.c:147
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
static av_cold void deshake_opencl_uninit(AVFilterContext *avctx)
static const AVFilterPad deshake_opencl_outputs[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static int activate(AVFilterContext *ctx)
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 int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
static const AVFilterPad deshake_opencl_inputs[]

Definition at line 2190 of file vf_deshake_opencl.c.