You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

610 lines
19KB

  1. /*
  2. * Copyright (c) 2003-2013 Loren Merritt
  3. * Copyright (c) 2015 Paul B Mahol
  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. /* Computes the Structural Similarity Metric between two video streams.
  22. * original algorithm:
  23. * Z. Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli,
  24. * "Image quality assessment: From error visibility to structural similarity,"
  25. * IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, Apr. 2004.
  26. *
  27. * To improve speed, this implementation uses the standard approximation of
  28. * overlapped 8x8 block sums, rather than the original gaussian weights.
  29. */
  30. /*
  31. * @file
  32. * Caculate the SSIM between two input videos.
  33. */
  34. #include "libavutil/avstring.h"
  35. #include "libavutil/opt.h"
  36. #include "libavutil/pixdesc.h"
  37. #include "avfilter.h"
  38. #include "drawutils.h"
  39. #include "formats.h"
  40. #include "framesync.h"
  41. #include "internal.h"
  42. #include "ssim.h"
  43. #include "video.h"
  44. typedef struct SSIMContext {
  45. const AVClass *class;
  46. FFFrameSync fs;
  47. FILE *stats_file;
  48. char *stats_file_str;
  49. int nb_components;
  50. int nb_threads;
  51. int max;
  52. uint64_t nb_frames;
  53. double ssim[4], ssim_total;
  54. char comps[4];
  55. double coefs[4];
  56. uint8_t rgba_map[4];
  57. int planewidth[4];
  58. int planeheight[4];
  59. int **temp;
  60. int is_rgb;
  61. double **score;
  62. int (*ssim_plane)(AVFilterContext *ctx, void *arg,
  63. int jobnr, int nb_jobs);
  64. SSIMDSPContext dsp;
  65. } SSIMContext;
  66. #define OFFSET(x) offsetof(SSIMContext, x)
  67. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  68. static const AVOption ssim_options[] = {
  69. {"stats_file", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
  70. {"f", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
  71. { NULL }
  72. };
  73. FRAMESYNC_DEFINE_CLASS(ssim, SSIMContext, fs);
  74. static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
  75. {
  76. char value[128];
  77. snprintf(value, sizeof(value), "%f", d);
  78. if (comp) {
  79. char key2[128];
  80. snprintf(key2, sizeof(key2), "%s%c", key, comp);
  81. av_dict_set(metadata, key2, value, 0);
  82. } else {
  83. av_dict_set(metadata, key, value, 0);
  84. }
  85. }
  86. static void ssim_4x4xn_16bit(const uint8_t *main8, ptrdiff_t main_stride,
  87. const uint8_t *ref8, ptrdiff_t ref_stride,
  88. int64_t (*sums)[4], int width)
  89. {
  90. const uint16_t *main16 = (const uint16_t *)main8;
  91. const uint16_t *ref16 = (const uint16_t *)ref8;
  92. int x, y, z;
  93. main_stride >>= 1;
  94. ref_stride >>= 1;
  95. for (z = 0; z < width; z++) {
  96. uint64_t s1 = 0, s2 = 0, ss = 0, s12 = 0;
  97. for (y = 0; y < 4; y++) {
  98. for (x = 0; x < 4; x++) {
  99. unsigned a = main16[x + y * main_stride];
  100. unsigned b = ref16[x + y * ref_stride];
  101. s1 += a;
  102. s2 += b;
  103. ss += a*a;
  104. ss += b*b;
  105. s12 += a*b;
  106. }
  107. }
  108. sums[z][0] = s1;
  109. sums[z][1] = s2;
  110. sums[z][2] = ss;
  111. sums[z][3] = s12;
  112. main16 += 4;
  113. ref16 += 4;
  114. }
  115. }
  116. static void ssim_4x4xn_8bit(const uint8_t *main, ptrdiff_t main_stride,
  117. const uint8_t *ref, ptrdiff_t ref_stride,
  118. int (*sums)[4], int width)
  119. {
  120. int x, y, z;
  121. for (z = 0; z < width; z++) {
  122. uint32_t s1 = 0, s2 = 0, ss = 0, s12 = 0;
  123. for (y = 0; y < 4; y++) {
  124. for (x = 0; x < 4; x++) {
  125. int a = main[x + y * main_stride];
  126. int b = ref[x + y * ref_stride];
  127. s1 += a;
  128. s2 += b;
  129. ss += a*a;
  130. ss += b*b;
  131. s12 += a*b;
  132. }
  133. }
  134. sums[z][0] = s1;
  135. sums[z][1] = s2;
  136. sums[z][2] = ss;
  137. sums[z][3] = s12;
  138. main += 4;
  139. ref += 4;
  140. }
  141. }
  142. static float ssim_end1x(int64_t s1, int64_t s2, int64_t ss, int64_t s12, int max)
  143. {
  144. int64_t ssim_c1 = (int64_t)(.01*.01*max*max*64 + .5);
  145. int64_t ssim_c2 = (int64_t)(.03*.03*max*max*64*63 + .5);
  146. int64_t fs1 = s1;
  147. int64_t fs2 = s2;
  148. int64_t fss = ss;
  149. int64_t fs12 = s12;
  150. int64_t vars = fss * 64 - fs1 * fs1 - fs2 * fs2;
  151. int64_t covar = fs12 * 64 - fs1 * fs2;
  152. return (float)(2 * fs1 * fs2 + ssim_c1) * (float)(2 * covar + ssim_c2)
  153. / ((float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (float)(vars + ssim_c2));
  154. }
  155. static float ssim_end1(int s1, int s2, int ss, int s12)
  156. {
  157. static const int ssim_c1 = (int)(.01*.01*255*255*64 + .5);
  158. static const int ssim_c2 = (int)(.03*.03*255*255*64*63 + .5);
  159. int fs1 = s1;
  160. int fs2 = s2;
  161. int fss = ss;
  162. int fs12 = s12;
  163. int vars = fss * 64 - fs1 * fs1 - fs2 * fs2;
  164. int covar = fs12 * 64 - fs1 * fs2;
  165. return (float)(2 * fs1 * fs2 + ssim_c1) * (float)(2 * covar + ssim_c2)
  166. / ((float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (float)(vars + ssim_c2));
  167. }
  168. static float ssim_endn_16bit(const int64_t (*sum0)[4], const int64_t (*sum1)[4], int width, int max)
  169. {
  170. float ssim = 0.0;
  171. int i;
  172. for (i = 0; i < width; i++)
  173. ssim += ssim_end1x(sum0[i][0] + sum0[i + 1][0] + sum1[i][0] + sum1[i + 1][0],
  174. sum0[i][1] + sum0[i + 1][1] + sum1[i][1] + sum1[i + 1][1],
  175. sum0[i][2] + sum0[i + 1][2] + sum1[i][2] + sum1[i + 1][2],
  176. sum0[i][3] + sum0[i + 1][3] + sum1[i][3] + sum1[i + 1][3],
  177. max);
  178. return ssim;
  179. }
  180. static double ssim_endn_8bit(const int (*sum0)[4], const int (*sum1)[4], int width)
  181. {
  182. double ssim = 0.0;
  183. int i;
  184. for (i = 0; i < width; i++)
  185. ssim += ssim_end1(sum0[i][0] + sum0[i + 1][0] + sum1[i][0] + sum1[i + 1][0],
  186. sum0[i][1] + sum0[i + 1][1] + sum1[i][1] + sum1[i + 1][1],
  187. sum0[i][2] + sum0[i + 1][2] + sum1[i][2] + sum1[i + 1][2],
  188. sum0[i][3] + sum0[i + 1][3] + sum1[i][3] + sum1[i + 1][3]);
  189. return ssim;
  190. }
  191. #define SUM_LEN(w) (((w) >> 2) + 3)
  192. typedef struct ThreadData {
  193. const uint8_t *main_data[4];
  194. const uint8_t *ref_data[4];
  195. int main_linesize[4];
  196. int ref_linesize[4];
  197. int planewidth[4];
  198. int planeheight[4];
  199. double **score;
  200. int **temp;
  201. int nb_components;
  202. int max;
  203. SSIMDSPContext *dsp;
  204. } ThreadData;
  205. static int ssim_plane_16bit(AVFilterContext *ctx, void *arg,
  206. int jobnr, int nb_jobs)
  207. {
  208. ThreadData *td = arg;
  209. double *score = td->score[jobnr];
  210. void *temp = td->temp[jobnr];
  211. const int max = td->max;
  212. for (int c = 0; c < td->nb_components; c++) {
  213. const uint8_t *main_data = td->main_data[c];
  214. const uint8_t *ref_data = td->ref_data[c];
  215. const int main_stride = td->main_linesize[c];
  216. const int ref_stride = td->ref_linesize[c];
  217. int width = td->planewidth[c];
  218. int height = td->planeheight[c];
  219. const int slice_start = ((height >> 2) * jobnr) / nb_jobs;
  220. const int slice_end = ((height >> 2) * (jobnr+1)) / nb_jobs;
  221. const int ystart = FFMAX(1, slice_start);
  222. int z = ystart - 1;
  223. double ssim = 0.0;
  224. int64_t (*sum0)[4] = temp;
  225. int64_t (*sum1)[4] = sum0 + SUM_LEN(width);
  226. width >>= 2;
  227. height >>= 2;
  228. for (int y = ystart; y < slice_end; y++) {
  229. for (; z <= y; z++) {
  230. FFSWAP(void*, sum0, sum1);
  231. ssim_4x4xn_16bit(&main_data[4 * z * main_stride], main_stride,
  232. &ref_data[4 * z * ref_stride], ref_stride,
  233. sum0, width);
  234. }
  235. ssim += ssim_endn_16bit((const int64_t (*)[4])sum0, (const int64_t (*)[4])sum1, width - 1, max);
  236. }
  237. score[c] = ssim;
  238. }
  239. return 0;
  240. }
  241. static int ssim_plane(AVFilterContext *ctx, void *arg,
  242. int jobnr, int nb_jobs)
  243. {
  244. ThreadData *td = arg;
  245. double *score = td->score[jobnr];
  246. void *temp = td->temp[jobnr];
  247. SSIMDSPContext *dsp = td->dsp;
  248. for (int c = 0; c < td->nb_components; c++) {
  249. const uint8_t *main_data = td->main_data[c];
  250. const uint8_t *ref_data = td->ref_data[c];
  251. const int main_stride = td->main_linesize[c];
  252. const int ref_stride = td->ref_linesize[c];
  253. int width = td->planewidth[c];
  254. int height = td->planeheight[c];
  255. const int slice_start = ((height >> 2) * jobnr) / nb_jobs;
  256. const int slice_end = ((height >> 2) * (jobnr+1)) / nb_jobs;
  257. const int ystart = FFMAX(1, slice_start);
  258. int z = ystart - 1;
  259. double ssim = 0.0;
  260. int (*sum0)[4] = temp;
  261. int (*sum1)[4] = sum0 + SUM_LEN(width);
  262. width >>= 2;
  263. height >>= 2;
  264. for (int y = ystart; y < slice_end; y++) {
  265. for (; z <= y; z++) {
  266. FFSWAP(void*, sum0, sum1);
  267. dsp->ssim_4x4_line(&main_data[4 * z * main_stride], main_stride,
  268. &ref_data[4 * z * ref_stride], ref_stride,
  269. sum0, width);
  270. }
  271. ssim += dsp->ssim_end_line((const int (*)[4])sum0, (const int (*)[4])sum1, width - 1);
  272. }
  273. score[c] = ssim;
  274. }
  275. return 0;
  276. }
  277. static double ssim_db(double ssim, double weight)
  278. {
  279. return (fabs(weight - ssim) > 1e-9) ? 10.0 * log10(weight / (weight - ssim)) : INFINITY;
  280. }
  281. static int do_ssim(FFFrameSync *fs)
  282. {
  283. AVFilterContext *ctx = fs->parent;
  284. SSIMContext *s = ctx->priv;
  285. AVFrame *master, *ref;
  286. AVDictionary **metadata;
  287. double c[4] = {0}, ssimv = 0.0;
  288. ThreadData td;
  289. int ret, i;
  290. ret = ff_framesync_dualinput_get(fs, &master, &ref);
  291. if (ret < 0)
  292. return ret;
  293. if (ctx->is_disabled || !ref)
  294. return ff_filter_frame(ctx->outputs[0], master);
  295. metadata = &master->metadata;
  296. s->nb_frames++;
  297. td.nb_components = s->nb_components;
  298. td.dsp = &s->dsp;
  299. td.score = s->score;
  300. td.temp = s->temp;
  301. td.max = s->max;
  302. for (int n = 0; n < s->nb_components; n++) {
  303. td.main_data[n] = master->data[n];
  304. td.ref_data[n] = ref->data[n];
  305. td.main_linesize[n] = master->linesize[n];
  306. td.ref_linesize[n] = ref->linesize[n];
  307. td.planewidth[n] = s->planewidth[n];
  308. td.planeheight[n] = s->planeheight[n];
  309. }
  310. ctx->internal->execute(ctx, s->ssim_plane, &td, NULL, FFMIN((s->planeheight[1] + 3) >> 2, s->nb_threads));
  311. for (i = 0; i < s->nb_components; i++) {
  312. for (int j = 0; j < s->nb_threads; j++)
  313. c[i] += s->score[j][i];
  314. c[i] = c[i] / (((s->planewidth[i] >> 2) - 1) * ((s->planeheight[i] >> 2) - 1));
  315. }
  316. for (i = 0; i < s->nb_components; i++) {
  317. ssimv += s->coefs[i] * c[i];
  318. s->ssim[i] += c[i];
  319. }
  320. for (i = 0; i < s->nb_components; i++) {
  321. int cidx = s->is_rgb ? s->rgba_map[i] : i;
  322. set_meta(metadata, "lavfi.ssim.", s->comps[i], c[cidx]);
  323. }
  324. s->ssim_total += ssimv;
  325. set_meta(metadata, "lavfi.ssim.All", 0, ssimv);
  326. set_meta(metadata, "lavfi.ssim.dB", 0, ssim_db(ssimv, 1.0));
  327. if (s->stats_file) {
  328. fprintf(s->stats_file, "n:%"PRId64" ", s->nb_frames);
  329. for (i = 0; i < s->nb_components; i++) {
  330. int cidx = s->is_rgb ? s->rgba_map[i] : i;
  331. fprintf(s->stats_file, "%c:%f ", s->comps[i], c[cidx]);
  332. }
  333. fprintf(s->stats_file, "All:%f (%f)\n", ssimv, ssim_db(ssimv, 1.0));
  334. }
  335. return ff_filter_frame(ctx->outputs[0], master);
  336. }
  337. static av_cold int init(AVFilterContext *ctx)
  338. {
  339. SSIMContext *s = ctx->priv;
  340. if (s->stats_file_str) {
  341. if (!strcmp(s->stats_file_str, "-")) {
  342. s->stats_file = stdout;
  343. } else {
  344. s->stats_file = fopen(s->stats_file_str, "w");
  345. if (!s->stats_file) {
  346. int err = AVERROR(errno);
  347. char buf[128];
  348. av_strerror(err, buf, sizeof(buf));
  349. av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n",
  350. s->stats_file_str, buf);
  351. return err;
  352. }
  353. }
  354. }
  355. s->fs.on_event = do_ssim;
  356. return 0;
  357. }
  358. static int query_formats(AVFilterContext *ctx)
  359. {
  360. static const enum AVPixelFormat pix_fmts[] = {
  361. AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10,
  362. AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
  363. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
  364. AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
  365. AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
  366. AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
  367. AV_PIX_FMT_GBRP,
  368. #define PF(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf, AV_PIX_FMT_GBR##suf
  369. PF(P9), PF(P10), PF(P12), PF(P14), PF(P16),
  370. AV_PIX_FMT_NONE
  371. };
  372. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  373. if (!fmts_list)
  374. return AVERROR(ENOMEM);
  375. return ff_set_common_formats(ctx, fmts_list);
  376. }
  377. static int config_input_ref(AVFilterLink *inlink)
  378. {
  379. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  380. AVFilterContext *ctx = inlink->dst;
  381. SSIMContext *s = ctx->priv;
  382. int sum = 0, i;
  383. s->nb_threads = ff_filter_get_nb_threads(ctx);
  384. s->nb_components = desc->nb_components;
  385. if (ctx->inputs[0]->w != ctx->inputs[1]->w ||
  386. ctx->inputs[0]->h != ctx->inputs[1]->h) {
  387. av_log(ctx, AV_LOG_ERROR, "Width and height of input videos must be same.\n");
  388. return AVERROR(EINVAL);
  389. }
  390. if (ctx->inputs[0]->format != ctx->inputs[1]->format) {
  391. av_log(ctx, AV_LOG_ERROR, "Inputs must be of same pixel format.\n");
  392. return AVERROR(EINVAL);
  393. }
  394. s->is_rgb = ff_fill_rgba_map(s->rgba_map, inlink->format) >= 0;
  395. s->comps[0] = s->is_rgb ? 'R' : 'Y';
  396. s->comps[1] = s->is_rgb ? 'G' : 'U';
  397. s->comps[2] = s->is_rgb ? 'B' : 'V';
  398. s->comps[3] = 'A';
  399. s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
  400. s->planeheight[0] = s->planeheight[3] = inlink->h;
  401. s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
  402. s->planewidth[0] = s->planewidth[3] = inlink->w;
  403. for (i = 0; i < s->nb_components; i++)
  404. sum += s->planeheight[i] * s->planewidth[i];
  405. for (i = 0; i < s->nb_components; i++)
  406. s->coefs[i] = (double) s->planeheight[i] * s->planewidth[i] / sum;
  407. s->temp = av_calloc(s->nb_threads, sizeof(*s->temp));
  408. if (!s->temp)
  409. return AVERROR(ENOMEM);
  410. for (int t = 0; t < s->nb_threads; t++) {
  411. s->temp[t] = av_mallocz_array(2 * SUM_LEN(inlink->w), (desc->comp[0].depth > 8) ? sizeof(int64_t[4]) : sizeof(int[4]));
  412. if (!s->temp[t])
  413. return AVERROR(ENOMEM);
  414. }
  415. s->max = (1 << desc->comp[0].depth) - 1;
  416. s->ssim_plane = desc->comp[0].depth > 8 ? ssim_plane_16bit : ssim_plane;
  417. s->dsp.ssim_4x4_line = ssim_4x4xn_8bit;
  418. s->dsp.ssim_end_line = ssim_endn_8bit;
  419. if (ARCH_X86)
  420. ff_ssim_init_x86(&s->dsp);
  421. s->score = av_calloc(s->nb_threads, sizeof(*s->score));
  422. if (!s->score)
  423. return AVERROR(ENOMEM);
  424. for (int t = 0; t < s->nb_threads && s->score; t++) {
  425. s->score[t] = av_calloc(s->nb_components, sizeof(*s->score[0]));
  426. if (!s->score[t])
  427. return AVERROR(ENOMEM);
  428. }
  429. return 0;
  430. }
  431. static int config_output(AVFilterLink *outlink)
  432. {
  433. AVFilterContext *ctx = outlink->src;
  434. SSIMContext *s = ctx->priv;
  435. AVFilterLink *mainlink = ctx->inputs[0];
  436. int ret;
  437. ret = ff_framesync_init_dualinput(&s->fs, ctx);
  438. if (ret < 0)
  439. return ret;
  440. outlink->w = mainlink->w;
  441. outlink->h = mainlink->h;
  442. outlink->time_base = mainlink->time_base;
  443. outlink->sample_aspect_ratio = mainlink->sample_aspect_ratio;
  444. outlink->frame_rate = mainlink->frame_rate;
  445. if ((ret = ff_framesync_configure(&s->fs)) < 0)
  446. return ret;
  447. outlink->time_base = s->fs.time_base;
  448. if (av_cmp_q(mainlink->time_base, outlink->time_base) ||
  449. av_cmp_q(ctx->inputs[1]->time_base, outlink->time_base))
  450. av_log(ctx, AV_LOG_WARNING, "not matching timebases found between first input: %d/%d and second input %d/%d, results may be incorrect!\n",
  451. mainlink->time_base.num, mainlink->time_base.den,
  452. ctx->inputs[1]->time_base.num, ctx->inputs[1]->time_base.den);
  453. return 0;
  454. }
  455. static int activate(AVFilterContext *ctx)
  456. {
  457. SSIMContext *s = ctx->priv;
  458. return ff_framesync_activate(&s->fs);
  459. }
  460. static av_cold void uninit(AVFilterContext *ctx)
  461. {
  462. SSIMContext *s = ctx->priv;
  463. if (s->nb_frames > 0) {
  464. char buf[256];
  465. int i;
  466. buf[0] = 0;
  467. for (i = 0; i < s->nb_components; i++) {
  468. int c = s->is_rgb ? s->rgba_map[i] : i;
  469. av_strlcatf(buf, sizeof(buf), " %c:%f (%f)", s->comps[i], s->ssim[c] / s->nb_frames,
  470. ssim_db(s->ssim[c], s->nb_frames));
  471. }
  472. av_log(ctx, AV_LOG_INFO, "SSIM%s All:%f (%f)\n", buf,
  473. s->ssim_total / s->nb_frames, ssim_db(s->ssim_total, s->nb_frames));
  474. }
  475. ff_framesync_uninit(&s->fs);
  476. if (s->stats_file && s->stats_file != stdout)
  477. fclose(s->stats_file);
  478. for (int t = 0; t < s->nb_threads && s->score; t++)
  479. av_freep(&s->score[t]);
  480. av_freep(&s->score);
  481. for (int t = 0; t < s->nb_threads && s->temp; t++)
  482. av_freep(&s->temp[t]);
  483. av_freep(&s->temp);
  484. }
  485. static const AVFilterPad ssim_inputs[] = {
  486. {
  487. .name = "main",
  488. .type = AVMEDIA_TYPE_VIDEO,
  489. },{
  490. .name = "reference",
  491. .type = AVMEDIA_TYPE_VIDEO,
  492. .config_props = config_input_ref,
  493. },
  494. { NULL }
  495. };
  496. static const AVFilterPad ssim_outputs[] = {
  497. {
  498. .name = "default",
  499. .type = AVMEDIA_TYPE_VIDEO,
  500. .config_props = config_output,
  501. },
  502. { NULL }
  503. };
  504. AVFilter ff_vf_ssim = {
  505. .name = "ssim",
  506. .description = NULL_IF_CONFIG_SMALL("Calculate the SSIM between two video streams."),
  507. .preinit = ssim_framesync_preinit,
  508. .init = init,
  509. .uninit = uninit,
  510. .query_formats = query_formats,
  511. .activate = activate,
  512. .priv_size = sizeof(SSIMContext),
  513. .priv_class = &ssim_class,
  514. .inputs = ssim_inputs,
  515. .outputs = ssim_outputs,
  516. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
  517. };