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>
34 vector<Filter const *> Filter::_filters;
37 * @param n User-visible name.
38 * @param c User-visible category.
39 * @param v String for a FFmpeg video filter descriptor, or "".
40 * @param p String for a FFmpeg post-processing descriptor, or "".
42 Filter::Filter (string i, string n, string c, string v, string p)
52 /** @return All available filters */
53 vector<Filter const *>
60 /** Set up the static _filters vector; must be called before from_*
64 Filter::setup_filters ()
66 /* Note: "none" is a magic id name, so don't use it here */
68 maybe_add (N_("pphb"), _("Horizontal deblocking filter"), _("De-blocking"), N_(""), N_("hb"));
69 maybe_add (N_("ppvb"), _("Vertical deblocking filter"), _("De-blocking"), N_(""), N_("vb"));
70 maybe_add (N_("ppha"), _("Horizontal deblocking filter A"), _("De-blocking"), N_(""), N_("ha"));
71 maybe_add (N_("ppva"), _("Vertical deblocking filter A"), _("De-blocking"), N_(""), N_("va"));
72 maybe_add (N_("pph1"), _("Experimental horizontal deblocking filter 1"), _("De-blocking"), N_(""), N_("h1"));
73 maybe_add (N_("pphv"), _("Experimental vertical deblocking filter 1"), _("De-blocking"), N_(""), N_("v1"));
74 maybe_add (N_("ppdr"), _("Deringing filter"), _("Misc"), N_(""), N_("dr"));
75 maybe_add (N_("pplb"), _("Linear blend deinterlacer"), _("De-interlacing"), N_(""), N_("lb"));
76 maybe_add (N_("ppli"), _("Linear interpolating deinterlacer"), _("De-interlacing"), N_(""), N_("li"));
77 maybe_add (N_("ppci"), _("Cubic interpolating deinterlacer"), _("De-interlacing"), N_(""), N_("ci"));
78 maybe_add (N_("ppmd"), _("Median deinterlacer"), _("De-interlacing"), N_(""), N_("md"));
79 maybe_add (N_("ppfd"), _("FFMPEG deinterlacer"), _("De-interlacing"), N_(""), N_("fd"));
80 maybe_add (N_("ppl5"), _("FIR low-pass deinterlacer"), _("De-interlacing"), N_(""), N_("l5"));
81 maybe_add (N_("mcdeint"), _("Motion compensating deinterlacer"), _("De-interlacing"), N_("mcdeint"), N_(""));
82 maybe_add (N_("kerndeint"), _("Kernel deinterlacer"), _("De-interlacing"), N_("kerndeint"), N_(""));
83 maybe_add (N_("yadif"), _("Yet Another Deinterlacing Filter"), _("De-interlacing"), N_("yadif"), N_(""));
84 maybe_add (N_("pptn"), _("Temporal noise reducer"), _("Noise reduction"), N_(""), N_("tn"));
85 maybe_add (N_("ppfq"), _("Force quantizer"), _("Misc"), N_(""), N_("fq"));
86 maybe_add (N_("gradfun"), _("Gradient debander"), _("Misc"), N_("gradfun"), N_(""));
87 maybe_add (N_("unsharp"), _("Unsharp mask and Gaussian blur"), _("Misc"), N_("unsharp"), N_(""));
88 maybe_add (N_("denoise3d"), _("3D denoiser"), _("Noise reduction"), N_("denoise3d"), N_(""));
89 maybe_add (N_("hqdn3d"), _("High quality 3D denoiser"), _("Noise reduction"), N_("hqdn3d"), N_(""));
90 maybe_add (N_("telecine"), _("Telecine filter"), _("Misc"), N_("telecine"), N_(""));
91 maybe_add (N_("ow"), _("Overcomplete wavelet denoiser"), _("Noise reduction"), N_("mp=ow"), N_(""));
95 Filter::maybe_add (string i, string n, string c, string v, string p)
98 if (avfilter_get_by_name (i.c_str())) {
99 _filters.push_back (new Filter (i, n, c, v, p));
101 } else if (!p.empty ()) {
102 pp_mode* m = pp_get_mode_by_name_and_quality (p.c_str(), PP_QUALITY_MAX);
104 _filters.push_back (new Filter (i, n, c, v, p));
110 /** @param filters Set of filters.
111 * @return A pair; .first is a string to pass to FFmpeg for the video filters,
112 * .second is a string to pass for the post-processors.
115 Filter::ffmpeg_strings (vector<Filter const *> const & filters)
120 for (vector<Filter const *>::const_iterator i = filters.begin(); i != filters.end(); ++i) {
121 if (!(*i)->vf().empty ()) {
128 if (!(*i)->pp().empty ()) {
136 return make_pair (vf, pp);
140 * @return Corresponding Filter, or 0.
143 Filter::from_id (string d)
145 vector<Filter const *>::iterator i = _filters.begin ();
146 while (i != _filters.end() && (*i)->id() != d) {
150 if (i == _filters.end ()) {