deshake.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
  3. * Copyright (C) 2013 Lenny Wang
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVFILTER_DESHAKE_H
  22. #define AVFILTER_DESHAKE_H
  23. #include "config.h"
  24. #include "avfilter.h"
  25. #include "transform.h"
  26. #include "libavutil/pixelutils.h"
  27. #if CONFIG_OPENCL
  28. #include "libavutil/opencl.h"
  29. #endif
  30. enum SearchMethod {
  31. EXHAUSTIVE, ///< Search all possible positions
  32. SMART_EXHAUSTIVE, ///< Search most possible positions (faster)
  33. SEARCH_COUNT
  34. };
  35. typedef struct {
  36. int x; ///< Horizontal shift
  37. int y; ///< Vertical shift
  38. } IntMotionVector;
  39. typedef struct {
  40. double x; ///< Horizontal shift
  41. double y; ///< Vertical shift
  42. } MotionVector;
  43. typedef struct {
  44. MotionVector vec; ///< Motion vector
  45. double angle; ///< Angle of rotation
  46. double zoom; ///< Zoom percentage
  47. } Transform;
  48. #if CONFIG_OPENCL
  49. typedef struct {
  50. cl_command_queue command_queue;
  51. cl_program program;
  52. cl_kernel kernel_luma;
  53. cl_kernel kernel_chroma;
  54. int in_plane_size[8];
  55. int out_plane_size[8];
  56. int plane_num;
  57. cl_mem cl_inbuf;
  58. size_t cl_inbuf_size;
  59. cl_mem cl_outbuf;
  60. size_t cl_outbuf_size;
  61. } DeshakeOpenclContext;
  62. #endif
  63. #define MAX_R 64
  64. typedef struct {
  65. const AVClass *class;
  66. int counts[2*MAX_R+1][2*MAX_R+1]; /// < Scratch buffer for motion search
  67. double *angles; ///< Scratch buffer for block angles
  68. unsigned angles_size;
  69. AVFrame *ref; ///< Previous frame
  70. int rx; ///< Maximum horizontal shift
  71. int ry; ///< Maximum vertical shift
  72. int edge; ///< Edge fill method
  73. int blocksize; ///< Size of blocks to compare
  74. int contrast; ///< Contrast threshold
  75. int search; ///< Motion search method
  76. av_pixelutils_sad_fn sad; ///< Sum of the absolute difference function
  77. Transform last; ///< Transform from last frame
  78. int refcount; ///< Number of reference frames (defines averaging window)
  79. FILE *fp;
  80. Transform avg;
  81. int cw; ///< Crop motion search to this box
  82. int ch;
  83. int cx;
  84. int cy;
  85. char *filename; ///< Motion search detailed log filename
  86. int opencl;
  87. #if CONFIG_OPENCL
  88. DeshakeOpenclContext opencl_ctx;
  89. #endif
  90. int (* transform)(AVFilterContext *ctx, int width, int height, int cw, int ch,
  91. const float *matrix_y, const float *matrix_uv, enum InterpolateMethod interpolate,
  92. enum FillMethod fill, AVFrame *in, AVFrame *out);
  93. } DeshakeContext;
  94. #endif /* AVFILTER_DESHAKE_H */