FFmpeg
Loading...
Searching...
No Matches
vf_deshake_opencl.c File Reference
#include <float.h>
#include "libavutil/lfg.h"
#include "libavutil/opt.h"
#include "libavutil/mem.h"
#include "libavutil/fifo.h"
#include "libavutil/common.h"
#include "libavutil/avassert.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
#include "avfilter.h"
#include "framequeue.h"
#include "filters.h"
#include "transform.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)
 
#define OFFSET(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, AVFifo *values, float *val, int offset)
 
static float smooth (DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifo *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 FFFilter ff_vf_deshake_opencl
 

Macro Definition Documentation

◆ BREIFN

#define BREIFN   512

Definition at line 85 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init().

◆ BRIEF_PATCH_SIZE

#define BRIEF_PATCH_SIZE   31

Definition at line 88 of file vf_deshake_opencl.c.

◆ BRIEF_PATCH_SIZE_HALF

#define BRIEF_PATCH_SIZE_HALF   (BRIEF_PATCH_SIZE / 2)

Definition at line 89 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init().

◆ MATCHES_CONTIG_SIZE

#define MATCHES_CONTIG_SIZE   2000

Definition at line 91 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init(), and make_vectors_contig().

◆ ROUNDED_UP_DIV

#define ROUNDED_UP_DIV ( a,
b )
Value:
((a + (b - 1)) / b)
int a
#define b
Definition input.c:43

Definition at line 93 of file vf_deshake_opencl.c.

Referenced by deshake_opencl_init(), and queue_frame().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 2120 of file vf_deshake_opencl.c.

◆ FLAGS

Definition at line 2121 of file vf_deshake_opencl.c.

Enumeration Type Documentation

◆ RingbufferIndices

Enumerator
RingbufX 
RingbufY 
RingbufRot 
RingbufScaleX 
RingbufScaleY 
RingbufCount 

Definition at line 109 of file vf_deshake_opencl.c.

Function Documentation

◆ free_debug_matches()

static void free_debug_matches ( AbsoluteFrameMotion * afm)
static

Definition at line 150 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 303 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 309 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 319 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 349 of file vf_deshake_opencl.c.

Referenced by check_subset().

◆ check_subset()

static int check_subset ( const MotionVector * pairs_subset)
static

Definition at line 375 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 393 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 435 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 459 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 495 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 517 of file vf_deshake_opencl.c.

Referenced by queue_frame().

◆ 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 600 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 673 of file vf_deshake_opencl.c.

Referenced by queue_frame().

◆ decompose_transform()

static FrameDelta decompose_transform ( double * model)
static

Definition at line 737 of file vf_deshake_opencl.c.

Referenced by queue_frame().

◆ make_vectors_contig()

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

Definition at line 777 of file vf_deshake_opencl.c.

Referenced by queue_frame().

◆ gaussian_for()

static float gaussian_for ( int x,
float sigma )
static

Definition at line 803 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 809 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 833 of file vf_deshake_opencl.c.

Referenced by smooth().

◆ ringbuf_float_at()

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

Definition at line 844 of file vf_deshake_opencl.c.

Referenced by smooth().

◆ smooth()

◆ transformed_point()

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

Definition at line 941 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 951 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 989 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 1050 of file vf_deshake_opencl.c.

◆ deshake_opencl_init()

static int deshake_opencl_init ( AVFilterContext * avctx)
static

Definition at line 1109 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 1340 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 1368 of file vf_deshake_opencl.c.

Referenced by activate().

◆ queue_frame()

static int queue_frame ( AVFilterLink * link,
AVFrame * input_frame )
static

Definition at line 1726 of file vf_deshake_opencl.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext * ctx)
static

Definition at line 2005 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",
},
}
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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:46

Definition at line 2104 of file vf_deshake_opencl.c.

◆ deshake_opencl_outputs

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

Definition at line 2112 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 }
}
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326

Definition at line 2123 of file vf_deshake_opencl.c.

◆ ff_vf_deshake_opencl

const FFFilter ff_vf_deshake_opencl
Initial value:
= {
.p.name = "deshake_opencl",
.p.description = NULL_IF_CONFIG_SMALL("Feature-point based video stabilization filter"),
.p.priv_class = &deshake_opencl_class,
.priv_size = sizeof(DeshakeOpenCLContext),
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
}
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition avfilter.h:187
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition filters.h:208
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition filters.h:254
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
Definition opencl.c:135
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
Definition pixfmt.h:358
static const AVFilterPad deshake_opencl_outputs[]
static av_cold void deshake_opencl_uninit(AVFilterContext *avctx)
static const AVFilterPad deshake_opencl_inputs[]

Definition at line 2154 of file vf_deshake_opencl.c.