2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file src/filter.cc
23 * @brief A class to describe one of FFmpeg's video or audio filters.
29 DCPOMATIC_DISABLE_WARNINGS
31 #include <libavfilter/avfilter.h>
33 DCPOMATIC_ENABLE_WARNINGS
42 vector<Filter> Filter::_filters;
46 * @param n User-visible name.
47 * @param c User-visible category.
48 * @param f String for a FFmpeg filter descriptor.
50 Filter::Filter (string i, string n, string c, string f)
60 /** @return All available filters */
61 vector<Filter const *>
64 vector<Filter const *> raw;
65 for (auto& filter: _filters) {
66 raw.push_back (&filter);
72 /** Set up the static _filters vector; must be called before from_*
76 Filter::setup_filters ()
78 /* Note: "none" is a magic id name, so don't use it here */
80 maybe_add (N_("vflip"), _("Vertical flip"), _("Orientation"), N_("vflip"));
81 maybe_add (N_("hflip"), _("Horizontal flip"), _("Orientation"), N_("hflip"));
82 maybe_add (N_("90clock"), _("Rotate 90 degrees clockwise"), _("Orientation"), N_("transpose=dir=clock"));
83 maybe_add (N_("90anticlock"), _("Rotate 90 degrees anti-clockwise"), _("Orientation"), N_("transpose=dir=cclock"));
84 maybe_add (N_("mcdeint"), _("Motion compensating deinterlacer"), _("De-interlacing"), N_("mcdeint"));
85 maybe_add (N_("kerndeint"), _("Kernel deinterlacer"), _("De-interlacing"), N_("kerndeint"));
86 maybe_add (N_("yadif"), _("Yet Another Deinterlacing Filter"), _("De-interlacing"), N_("yadif"));
87 maybe_add (N_("bwdif"), _("Bob Weaver Deinterlacing Filter"), _("De-interlacing"), N_("bwdif"));
88 maybe_add (N_("weave"), _("Weave filter"), _("De-interlacing"), N_("weave"));
89 maybe_add (N_("gradfun"), _("Gradient debander"), _("Misc"), N_("gradfun"));
90 maybe_add (N_("unsharp"), _("Unsharp mask and Gaussian blur"), _("Misc"), N_("unsharp"));
91 maybe_add (N_("denoise3d"), _("3D denoiser"), _("Noise reduction"), N_("denoise3d"));
92 maybe_add (N_("hqdn3d"), _("High quality 3D denoiser"), _("Noise reduction"), N_("hqdn3d"));
93 maybe_add (N_("telecine"), _("Telecine filter"), _("Misc"), N_("telecine"));
94 maybe_add (N_("ow"), _("Overcomplete wavelet denoiser"), _("Noise reduction"), N_("mp=ow"));
99 Filter::maybe_add (string i, string n, string c, string f)
101 string check_name = f;
102 size_t end = check_name.find("=");
103 if (end != string::npos) {
104 check_name = check_name.substr (0, end);
107 if (avfilter_get_by_name(check_name.c_str())) {
108 _filters.push_back (Filter(i, n, c, f));
113 /** @param filters Set of filters.
114 * @return String to pass to FFmpeg for the video filters.
117 Filter::ffmpeg_string (vector<Filter const *> const & filters)
121 for (auto const i: filters) {
133 * @return Corresponding Filter, or 0.
136 Filter::from_id (string d)
138 auto i = _filters.begin ();
139 while (i != _filters.end() && i->id() != d) {
143 if (i == _filters.end ()) {