2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/filter.cc
21 * @brief A class to describe one of FFmpeg's video or post-processing filters.
26 #include <libavfilter/avfilter.h>
27 #include <libpostproc/postprocess.h>
32 vector<Filter const *> Filter::_filters;
35 * @param n User-visible name.
36 * @param v String for a FFmpeg video filter descriptor, or "".
37 * @param p String for a FFmpeg post-processing descriptor, or "".
39 Filter::Filter (string i, string n, string v, string p)
48 /** @return All available filters */
49 vector<Filter const *>
56 /** Set up the static _filters vector; must be called before from_*
60 Filter::setup_filters ()
62 /* Note: "none" is a magic id name, so don't use it here */
64 maybe_add ("pphb", "Horizontal deblocking filter", "", "hb");
65 maybe_add ("ppvb", "Vertical deblocking filter", "", "vb");
66 maybe_add ("ppha", "Horizontal deblocking filter A", "", "ha");
67 maybe_add ("ppva", "Vertical deblocking filter A", "", "va");
68 maybe_add ("pph1", "Experimental horizontal deblocking filter 1", "", "h1");
69 maybe_add ("pphv", "Experimental vertical deblocking filter 1", "", "v1");
70 maybe_add ("ppdr", "Deringing filter", "", "dr");
71 maybe_add ("pplb", "Linear blend deinterlacer", "", "lb");
72 maybe_add ("ppli", "Linear interpolating deinterlacer", "", "li");
73 maybe_add ("ppci", "Cubic interpolating deinterlacer", "", "ci");
74 maybe_add ("ppmd", "Median deinterlacer", "", "md");
75 maybe_add ("ppfd", "FFMPEG deinterlacer", "", "fd");
76 maybe_add ("ppl5", "FIR low-pass deinterlacer", "", "l5");
77 maybe_add ("mcdeint", "Motion compensating deinterlacer", "mcdeint", "");
78 maybe_add ("kerndeint", "Kernel deinterlacer", "kerndeint", "");
79 maybe_add ("yadif", "Yet Another Deinterlacing Filter", "yadif", "");
80 maybe_add ("pptn", "Temporal noise reducer", "", "tn");
81 maybe_add ("ppfq", "Force quantizer", "", "fq");
82 maybe_add ("gradfun", "Gradient debander", "gradfun", "");
83 maybe_add ("unsharp", "Unsharp mask and Gaussian blur", "unsharp", "");
84 maybe_add ("denoise3d", "3D denoiser", "denoise3d", "");
85 maybe_add ("hqdn3d", "High quality 3D denoiser", "hqdn3d", "");
86 maybe_add ("telecine", "Telecine filter", "telecine", "");
87 maybe_add ("ow", "Overcomplete wavelet denoiser", "mp=ow", "");
91 Filter::maybe_add (string i, string n, string v, string p)
94 if (avfilter_get_by_name (i.c_str())) {
95 _filters.push_back (new Filter (i, n, v, p));
97 } else if (!p.empty ()) {
98 pp_mode* m = pp_get_mode_by_name_and_quality (p.c_str(), PP_QUALITY_MAX);
100 _filters.push_back (new Filter (i, n, v, p));
106 /** @param filters Set of filters.
107 * @return A pair; .first is a string to pass to FFmpeg for the video filters,
108 * .second is a string to pass for the post-processors.
111 Filter::ffmpeg_strings (vector<Filter const *> const & filters)
116 for (vector<Filter const *>::const_iterator i = filters.begin(); i != filters.end(); ++i) {
117 if (!(*i)->vf().empty ()) {
124 if (!(*i)->pp().empty ()) {
132 return make_pair (vf, pp);
136 * @return Corresponding Filter, or 0.
139 Filter::from_id (string d)
141 vector<Filter const *>::iterator i = _filters.begin ();
142 while (i != _filters.end() && (*i)->id() != d) {
146 if (i == _filters.end ()) {