FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_deshake_opencl.c File Reference
#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 int points_not_collinear (const cl_float2 **points)
 
static int check_subset (const MotionVector *pairs_subset)
 
static int 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 int 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 int 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 []
 
const AVFilter ff_vf_deshake_opencl
 

Macro Definition Documentation

◆ BREIFN

#define BREIFN   512

Definition at line 87 of file vf_deshake_opencl.c.

◆ BRIEF_PATCH_SIZE

#define BRIEF_PATCH_SIZE   31

Definition at line 90 of file vf_deshake_opencl.c.

◆ BRIEF_PATCH_SIZE_HALF

#define BRIEF_PATCH_SIZE_HALF   (BRIEF_PATCH_SIZE / 2)

Definition at line 91 of file vf_deshake_opencl.c.

◆ MATCHES_CONTIG_SIZE

#define MATCHES_CONTIG_SIZE   2000

Definition at line 93 of file vf_deshake_opencl.c.

◆ ROUNDED_UP_DIV

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

Definition at line 95 of file vf_deshake_opencl.c.

◆ OFFSET

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

Definition at line 2154 of file vf_deshake_opencl.c.

◆ FLAGS

Definition at line 2155 of file vf_deshake_opencl.c.

Enumeration Type Documentation

◆ RingbufferIndices

Enumerator
RingbufX 
RingbufY 
RingbufRot 
RingbufScaleX 
RingbufScaleY 
RingbufCount 

Definition at line 111 of file vf_deshake_opencl.c.

Function Documentation

◆ free_debug_matches()

static void free_debug_matches ( AbsoluteFrameMotion afm)
static

Definition at line 152 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_uninit().

◆ rand_in()

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

Definition at line 313 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init(), and get_subset().

◆ averaged_event_time_ms()

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

Definition at line 319 of file vf_deshake_opencl.c.

Referenced by activate().

◆ run_estimate_kernel()

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

Definition at line 329 of file vf_deshake_opencl.c.

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

◆ points_not_collinear()

static int points_not_collinear ( const cl_float2 **  points)
static

Definition at line 359 of file vf_deshake_opencl.c.

Referenced by check_subset().

◆ check_subset()

static int check_subset ( const MotionVector pairs_subset)
static

Definition at line 385 of file vf_deshake_opencl.c.

Referenced by get_subset().

◆ get_subset()

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

Definition at line 403 of file vf_deshake_opencl.c.

Referenced by estimate_affine_2d(), and minimize_error().

◆ compute_error()

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

Definition at line 445 of file vf_deshake_opencl.c.

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

◆ find_inliers()

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

Definition at line 469 of file vf_deshake_opencl.c.

Referenced by estimate_affine_2d().

◆ ransac_update_num_iters()

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

Definition at line 505 of file vf_deshake_opencl.c.

Referenced by estimate_affine_2d().

◆ estimate_affine_2d()

static int 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 527 of file vf_deshake_opencl.c.

◆ optimize_model()

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 610 of file vf_deshake_opencl.c.

Referenced by minimize_error().

◆ minimize_error()

static int 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 683 of file vf_deshake_opencl.c.

◆ decompose_transform()

static FrameDelta decompose_transform ( double *  model)
static

Definition at line 747 of file vf_deshake_opencl.c.

◆ make_vectors_contig()

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

Definition at line 787 of file vf_deshake_opencl.c.

◆ gaussian_for()

static float gaussian_for ( int  x,
float  sigma 
)
static

Definition at line 813 of file vf_deshake_opencl.c.

Referenced by make_gauss_kernel().

◆ make_gauss_kernel()

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

Definition at line 819 of file vf_deshake_opencl.c.

Referenced by smooth().

◆ start_end_for()

static IterIndices start_end_for ( DeshakeOpenCLContext deshake_ctx,
int  length 
)
static

Definition at line 843 of file vf_deshake_opencl.c.

Referenced by smooth().

◆ ringbuf_float_at()

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

Definition at line 854 of file vf_deshake_opencl.c.

Referenced by smooth().

◆ smooth()

static float smooth ( DeshakeOpenCLContext deshake_ctx,
float *  gauss_kernel,
int  length,
float  max_val,
AVFifoBuffer values 
)
static

◆ transformed_point()

static cl_float2 transformed_point ( float  x,
float  y,
float *  transform 
)
static

Definition at line 957 of file vf_deshake_opencl.c.

Referenced by transform_center_scale(), and update_needed_crop().

◆ transform_center_scale()

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 967 of file vf_deshake_opencl.c.

Referenced by filter_frame().

◆ update_needed_crop()

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

Definition at line 1005 of file vf_deshake_opencl.c.

Referenced by filter_frame().

◆ deshake_opencl_uninit()

static av_cold void deshake_opencl_uninit ( AVFilterContext avctx)
static

Definition at line 1066 of file vf_deshake_opencl.c.

◆ deshake_opencl_init()

static int deshake_opencl_init ( AVFilterContext avctx)
static

Definition at line 1125 of file vf_deshake_opencl.c.

Referenced by activate().

◆ transform_debug()

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().

◆ 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().

◆ queue_frame()

static int queue_frame ( AVFilterLink link,
AVFrame input_frame 
)
static

Definition at line 1749 of file vf_deshake_opencl.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 2039 of file vf_deshake_opencl.c.

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( deshake_opencl  )

Variable Documentation

◆ deshake_opencl_inputs

const AVFilterPad deshake_opencl_inputs[]
static
Initial value:
= {
{
.name = "default",
},
}

Definition at line 2138 of file vf_deshake_opencl.c.

◆ deshake_opencl_outputs

const AVFilterPad deshake_opencl_outputs[]
static
Initial value:
= {
{
.name = "default",
},
}

Definition at line 2146 of file vf_deshake_opencl.c.

◆ deshake_opencl_options

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 }
}

Definition at line 2157 of file vf_deshake_opencl.c.

◆ ff_vf_deshake_opencl

const 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
}

Definition at line 2188 of file vf_deshake_opencl.c.

deshake_opencl_inputs
static const AVFilterPad deshake_opencl_inputs[]
Definition: vf_deshake_opencl.c:2138
OFFSET
#define OFFSET(x)
Definition: vf_deshake_opencl.c:2154
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:371
init
static int init
Definition: av_tx.c:47
deshake_opencl_outputs
static const AVFilterPad deshake_opencl_outputs[]
Definition: vf_deshake_opencl.c:2146
ff_opencl_filter_config_output
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
Definition: opencl.c:81
deshake_opencl_uninit
static av_cold void deshake_opencl_uninit(AVFilterContext *avctx)
Definition: vf_deshake_opencl.c:1066
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_OPENCL
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
Definition: pixfmt.h:325
DeshakeOpenCLContext
Definition: vf_deshake_opencl.c:200
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
FLAGS
#define FLAGS
Definition: vf_deshake_opencl.c:2155
ff_opencl_filter_config_input
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:45
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:181
activate
static int activate(AVFilterContext *ctx)
Definition: vf_deshake_opencl.c:2039
ff_opencl_filter_init
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
Definition: opencl.c:132
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:282