2018-01-31 06:50:21 +01:00
|
|
|
#include <libavutil/avutil.h>
|
|
|
|
|
video: rewrite filtering glue code
Get rid of the old vf.c code. Replace it with a generic filtering
framework, which can potentially handle more than just --vf. At least
reimplementing --af with this code is planned.
This changes some --vf semantics (including runtime behavior and the
"vf" command). The most important ones are listed in interface-changes.
vf_convert.c is renamed to f_swscale.c. It is now an internal filter
that can not be inserted by the user manually.
f_lavfi.c is a refactor of player/lavfi.c. The latter will be removed
once --lavfi-complex is reimplemented on top of f_lavfi.c. (which is
conceptually easy, but a big mess due to the data flow changes).
The existing filters are all changed heavily. The data flow of the new
filter framework is different. Especially EOF handling changes - EOF is
now a "frame" rather than a state, and must be passed through exactly
once.
Another major thing is that all filters must support dynamic format
changes. The filter reconfig() function goes away. (This sounds complex,
but since all filters need to handle EOF draining anyway, they can use
the same code, and it removes the mess with reconfig() having to predict
the output format, which completely breaks with libavfilter anyway.)
In addition, there is no automatic format negotiation or conversion.
libavfilter's primitive and insufficient API simply doesn't allow us to
do this in a reasonable way. Instead, filters can use f_autoconvert as
sub-filter, and tell it which formats they support. This filter will in
turn add actual conversion filters, such as f_swscale, to perform
necessary format changes.
vf_vapoursynth.c uses the same basic principle of operation as before,
but with worryingly different details in data flow. Still appears to
work.
The hardware deint filters (vf_vavpp.c, vf_d3d11vpp.c, vf_vdpaupp.c) are
heavily changed. Fortunately, they all used refqueue.c, which is for
sharing the data flow logic (especially for managing future/past
surfaces and such). It turns out it can be used to factor out most of
the data flow. Some of these filters accepted software input. Instead of
having ad-hoc upload code in each filter, surface upload is now
delegated to f_autoconvert, which can use f_hwupload to perform this.
Exporting VO capabilities is still a big mess (mp_stream_info stuff).
The D3D11 code drops the redundant image formats, and all code uses the
hw_subfmt (sw_format in FFmpeg) instead. Although that too seems to be a
big mess for now.
f_async_queue is unused.
2018-01-16 11:53:44 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "options/m_config.h"
|
|
|
|
|
|
|
|
#include "f_lavfi.h"
|
|
|
|
#include "user_filters.h"
|
|
|
|
|
|
|
|
static bool get_desc_from(const struct mp_user_filter_entry **list, int num,
|
|
|
|
struct m_obj_desc *dst, int index)
|
|
|
|
{
|
|
|
|
if (index >= num)
|
|
|
|
return false;
|
|
|
|
const struct mp_user_filter_entry *entry = list[index];
|
|
|
|
*dst = entry->desc;
|
|
|
|
dst->p = entry;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-18 14:44:20 +01:00
|
|
|
// --af option
|
|
|
|
|
|
|
|
const struct mp_user_filter_entry *af_list[] = {
|
|
|
|
&af_lavfi,
|
|
|
|
&af_lavfi_bridge,
|
|
|
|
&af_scaletempo,
|
|
|
|
&af_format,
|
|
|
|
#if HAVE_RUBBERBAND
|
|
|
|
&af_rubberband,
|
|
|
|
#endif
|
|
|
|
&af_lavcac3enc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool get_af_desc(struct m_obj_desc *dst, int index)
|
|
|
|
{
|
|
|
|
return get_desc_from(af_list, MP_ARRAY_SIZE(af_list), dst, index);
|
|
|
|
}
|
|
|
|
|
2018-01-31 06:50:21 +01:00
|
|
|
static void print_af_help_list(struct mp_log *log)
|
|
|
|
{
|
|
|
|
print_lavfi_help_list(log, AVMEDIA_TYPE_AUDIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_af_lavfi_help(struct mp_log *log, const char *name)
|
|
|
|
{
|
|
|
|
print_lavfi_help(log, name, AVMEDIA_TYPE_AUDIO);
|
|
|
|
}
|
|
|
|
|
2018-01-18 14:44:20 +01:00
|
|
|
const struct m_obj_list af_obj_list = {
|
|
|
|
.get_desc = get_af_desc,
|
|
|
|
.description = "audio filters",
|
|
|
|
.allow_disable_entries = true,
|
|
|
|
.allow_unknown_entries = true,
|
2018-01-31 06:50:21 +01:00
|
|
|
.print_help_list = print_af_help_list,
|
|
|
|
.print_unknown_entry_help = print_af_lavfi_help,
|
2018-01-18 14:44:20 +01:00
|
|
|
};
|
|
|
|
|
video: rewrite filtering glue code
Get rid of the old vf.c code. Replace it with a generic filtering
framework, which can potentially handle more than just --vf. At least
reimplementing --af with this code is planned.
This changes some --vf semantics (including runtime behavior and the
"vf" command). The most important ones are listed in interface-changes.
vf_convert.c is renamed to f_swscale.c. It is now an internal filter
that can not be inserted by the user manually.
f_lavfi.c is a refactor of player/lavfi.c. The latter will be removed
once --lavfi-complex is reimplemented on top of f_lavfi.c. (which is
conceptually easy, but a big mess due to the data flow changes).
The existing filters are all changed heavily. The data flow of the new
filter framework is different. Especially EOF handling changes - EOF is
now a "frame" rather than a state, and must be passed through exactly
once.
Another major thing is that all filters must support dynamic format
changes. The filter reconfig() function goes away. (This sounds complex,
but since all filters need to handle EOF draining anyway, they can use
the same code, and it removes the mess with reconfig() having to predict
the output format, which completely breaks with libavfilter anyway.)
In addition, there is no automatic format negotiation or conversion.
libavfilter's primitive and insufficient API simply doesn't allow us to
do this in a reasonable way. Instead, filters can use f_autoconvert as
sub-filter, and tell it which formats they support. This filter will in
turn add actual conversion filters, such as f_swscale, to perform
necessary format changes.
vf_vapoursynth.c uses the same basic principle of operation as before,
but with worryingly different details in data flow. Still appears to
work.
The hardware deint filters (vf_vavpp.c, vf_d3d11vpp.c, vf_vdpaupp.c) are
heavily changed. Fortunately, they all used refqueue.c, which is for
sharing the data flow logic (especially for managing future/past
surfaces and such). It turns out it can be used to factor out most of
the data flow. Some of these filters accepted software input. Instead of
having ad-hoc upload code in each filter, surface upload is now
delegated to f_autoconvert, which can use f_hwupload to perform this.
Exporting VO capabilities is still a big mess (mp_stream_info stuff).
The D3D11 code drops the redundant image formats, and all code uses the
hw_subfmt (sw_format in FFmpeg) instead. Although that too seems to be a
big mess for now.
f_async_queue is unused.
2018-01-16 11:53:44 +01:00
|
|
|
// --vf option
|
|
|
|
|
|
|
|
const struct mp_user_filter_entry *vf_list[] = {
|
|
|
|
&vf_format,
|
|
|
|
&vf_lavfi,
|
|
|
|
&vf_lavfi_bridge,
|
|
|
|
&vf_sub,
|
video: add vf_fingerprint and a skip-logo script
skip-logo.lua is just what I wanted to have. Explanations are on the top
of that file. As usual, all documentation threatens to remove this stuff
all the time, since this stuff is just for me, and unlike a normal user
I can afford the luxuary of hacking the shit directly into the player.
vf_fingerprint is needed to support this script. It needs to scale down
video frames as part of its operation. For that, it uses zimg. zimg is
much faster than libswscale and generates more correct output. (The
filter includes a runtime fallback, but it doesn't even work because
libswscale fucks up and can't do YUV->Gray with range adjustment.)
Note on the algorithm: seems almost too simple, but was suggested to me.
It seems to be pretty effective, although long time experience with
false positives is missing. At first I wanted to use dHash [1][2], which
is also pretty simple and effective, but might actually be worse than
the implemented mechanism. dHash has the advantage that the fingerprint
is smaller. But exact matching is too unreliable, and you'd still need
to determine the number of different bits for fuzzier comparison. So
there wasn't really a reason to use it.
[1] https://pypi.org/project/dhash/
[2] http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
2019-07-15 03:20:40 +02:00
|
|
|
#if HAVE_ZIMG
|
|
|
|
&vf_fingerprint,
|
|
|
|
#endif
|
2019-06-30 01:20:06 +02:00
|
|
|
#if HAVE_VAPOURSYNTH
|
video: rewrite filtering glue code
Get rid of the old vf.c code. Replace it with a generic filtering
framework, which can potentially handle more than just --vf. At least
reimplementing --af with this code is planned.
This changes some --vf semantics (including runtime behavior and the
"vf" command). The most important ones are listed in interface-changes.
vf_convert.c is renamed to f_swscale.c. It is now an internal filter
that can not be inserted by the user manually.
f_lavfi.c is a refactor of player/lavfi.c. The latter will be removed
once --lavfi-complex is reimplemented on top of f_lavfi.c. (which is
conceptually easy, but a big mess due to the data flow changes).
The existing filters are all changed heavily. The data flow of the new
filter framework is different. Especially EOF handling changes - EOF is
now a "frame" rather than a state, and must be passed through exactly
once.
Another major thing is that all filters must support dynamic format
changes. The filter reconfig() function goes away. (This sounds complex,
but since all filters need to handle EOF draining anyway, they can use
the same code, and it removes the mess with reconfig() having to predict
the output format, which completely breaks with libavfilter anyway.)
In addition, there is no automatic format negotiation or conversion.
libavfilter's primitive and insufficient API simply doesn't allow us to
do this in a reasonable way. Instead, filters can use f_autoconvert as
sub-filter, and tell it which formats they support. This filter will in
turn add actual conversion filters, such as f_swscale, to perform
necessary format changes.
vf_vapoursynth.c uses the same basic principle of operation as before,
but with worryingly different details in data flow. Still appears to
work.
The hardware deint filters (vf_vavpp.c, vf_d3d11vpp.c, vf_vdpaupp.c) are
heavily changed. Fortunately, they all used refqueue.c, which is for
sharing the data flow logic (especially for managing future/past
surfaces and such). It turns out it can be used to factor out most of
the data flow. Some of these filters accepted software input. Instead of
having ad-hoc upload code in each filter, surface upload is now
delegated to f_autoconvert, which can use f_hwupload to perform this.
Exporting VO capabilities is still a big mess (mp_stream_info stuff).
The D3D11 code drops the redundant image formats, and all code uses the
hw_subfmt (sw_format in FFmpeg) instead. Although that too seems to be a
big mess for now.
f_async_queue is unused.
2018-01-16 11:53:44 +01:00
|
|
|
&vf_vapoursynth,
|
|
|
|
#endif
|
|
|
|
#if HAVE_VDPAU
|
|
|
|
&vf_vdpaupp,
|
|
|
|
#endif
|
|
|
|
#if HAVE_VAAPI
|
|
|
|
&vf_vavpp,
|
|
|
|
#endif
|
|
|
|
#if HAVE_D3D_HWACCEL
|
|
|
|
&vf_d3d11vpp,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool get_vf_desc(struct m_obj_desc *dst, int index)
|
|
|
|
{
|
|
|
|
return get_desc_from(vf_list, MP_ARRAY_SIZE(vf_list), dst, index);
|
|
|
|
}
|
|
|
|
|
2018-01-31 06:50:21 +01:00
|
|
|
static void print_vf_help_list(struct mp_log *log)
|
|
|
|
{
|
|
|
|
print_lavfi_help_list(log, AVMEDIA_TYPE_VIDEO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_vf_lavfi_help(struct mp_log *log, const char *name)
|
|
|
|
{
|
|
|
|
print_lavfi_help(log, name, AVMEDIA_TYPE_VIDEO);
|
|
|
|
}
|
|
|
|
|
video: rewrite filtering glue code
Get rid of the old vf.c code. Replace it with a generic filtering
framework, which can potentially handle more than just --vf. At least
reimplementing --af with this code is planned.
This changes some --vf semantics (including runtime behavior and the
"vf" command). The most important ones are listed in interface-changes.
vf_convert.c is renamed to f_swscale.c. It is now an internal filter
that can not be inserted by the user manually.
f_lavfi.c is a refactor of player/lavfi.c. The latter will be removed
once --lavfi-complex is reimplemented on top of f_lavfi.c. (which is
conceptually easy, but a big mess due to the data flow changes).
The existing filters are all changed heavily. The data flow of the new
filter framework is different. Especially EOF handling changes - EOF is
now a "frame" rather than a state, and must be passed through exactly
once.
Another major thing is that all filters must support dynamic format
changes. The filter reconfig() function goes away. (This sounds complex,
but since all filters need to handle EOF draining anyway, they can use
the same code, and it removes the mess with reconfig() having to predict
the output format, which completely breaks with libavfilter anyway.)
In addition, there is no automatic format negotiation or conversion.
libavfilter's primitive and insufficient API simply doesn't allow us to
do this in a reasonable way. Instead, filters can use f_autoconvert as
sub-filter, and tell it which formats they support. This filter will in
turn add actual conversion filters, such as f_swscale, to perform
necessary format changes.
vf_vapoursynth.c uses the same basic principle of operation as before,
but with worryingly different details in data flow. Still appears to
work.
The hardware deint filters (vf_vavpp.c, vf_d3d11vpp.c, vf_vdpaupp.c) are
heavily changed. Fortunately, they all used refqueue.c, which is for
sharing the data flow logic (especially for managing future/past
surfaces and such). It turns out it can be used to factor out most of
the data flow. Some of these filters accepted software input. Instead of
having ad-hoc upload code in each filter, surface upload is now
delegated to f_autoconvert, which can use f_hwupload to perform this.
Exporting VO capabilities is still a big mess (mp_stream_info stuff).
The D3D11 code drops the redundant image formats, and all code uses the
hw_subfmt (sw_format in FFmpeg) instead. Although that too seems to be a
big mess for now.
f_async_queue is unused.
2018-01-16 11:53:44 +01:00
|
|
|
const struct m_obj_list vf_obj_list = {
|
|
|
|
.get_desc = get_vf_desc,
|
|
|
|
.description = "video filters",
|
|
|
|
.allow_disable_entries = true,
|
|
|
|
.allow_unknown_entries = true,
|
2018-01-31 06:50:21 +01:00
|
|
|
.print_help_list = print_vf_help_list,
|
|
|
|
.print_unknown_entry_help = print_vf_lavfi_help,
|
video: rewrite filtering glue code
Get rid of the old vf.c code. Replace it with a generic filtering
framework, which can potentially handle more than just --vf. At least
reimplementing --af with this code is planned.
This changes some --vf semantics (including runtime behavior and the
"vf" command). The most important ones are listed in interface-changes.
vf_convert.c is renamed to f_swscale.c. It is now an internal filter
that can not be inserted by the user manually.
f_lavfi.c is a refactor of player/lavfi.c. The latter will be removed
once --lavfi-complex is reimplemented on top of f_lavfi.c. (which is
conceptually easy, but a big mess due to the data flow changes).
The existing filters are all changed heavily. The data flow of the new
filter framework is different. Especially EOF handling changes - EOF is
now a "frame" rather than a state, and must be passed through exactly
once.
Another major thing is that all filters must support dynamic format
changes. The filter reconfig() function goes away. (This sounds complex,
but since all filters need to handle EOF draining anyway, they can use
the same code, and it removes the mess with reconfig() having to predict
the output format, which completely breaks with libavfilter anyway.)
In addition, there is no automatic format negotiation or conversion.
libavfilter's primitive and insufficient API simply doesn't allow us to
do this in a reasonable way. Instead, filters can use f_autoconvert as
sub-filter, and tell it which formats they support. This filter will in
turn add actual conversion filters, such as f_swscale, to perform
necessary format changes.
vf_vapoursynth.c uses the same basic principle of operation as before,
but with worryingly different details in data flow. Still appears to
work.
The hardware deint filters (vf_vavpp.c, vf_d3d11vpp.c, vf_vdpaupp.c) are
heavily changed. Fortunately, they all used refqueue.c, which is for
sharing the data flow logic (especially for managing future/past
surfaces and such). It turns out it can be used to factor out most of
the data flow. Some of these filters accepted software input. Instead of
having ad-hoc upload code in each filter, surface upload is now
delegated to f_autoconvert, which can use f_hwupload to perform this.
Exporting VO capabilities is still a big mess (mp_stream_info stuff).
The D3D11 code drops the redundant image formats, and all code uses the
hw_subfmt (sw_format in FFmpeg) instead. Although that too seems to be a
big mess for now.
f_async_queue is unused.
2018-01-16 11:53:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create a bidir, single-media filter from command line arguments.
|
|
|
|
struct mp_filter *mp_create_user_filter(struct mp_filter *parent,
|
|
|
|
enum mp_output_chain_type type,
|
|
|
|
const char *name, char **args)
|
|
|
|
{
|
|
|
|
const struct m_obj_list *obj_list = NULL;
|
|
|
|
const char *defs_name = NULL;
|
|
|
|
enum mp_frame_type frame_type = 0;
|
|
|
|
if (type == MP_OUTPUT_CHAIN_VIDEO) {
|
|
|
|
frame_type = MP_FRAME_VIDEO;
|
|
|
|
obj_list = &vf_obj_list;
|
|
|
|
defs_name = "vf-defaults";
|
2018-01-18 14:44:20 +01:00
|
|
|
} else if (type == MP_OUTPUT_CHAIN_AUDIO) {
|
|
|
|
frame_type = MP_FRAME_AUDIO;
|
|
|
|
obj_list = &af_obj_list;
|
|
|
|
defs_name = "af-defaults";
|
video: rewrite filtering glue code
Get rid of the old vf.c code. Replace it with a generic filtering
framework, which can potentially handle more than just --vf. At least
reimplementing --af with this code is planned.
This changes some --vf semantics (including runtime behavior and the
"vf" command). The most important ones are listed in interface-changes.
vf_convert.c is renamed to f_swscale.c. It is now an internal filter
that can not be inserted by the user manually.
f_lavfi.c is a refactor of player/lavfi.c. The latter will be removed
once --lavfi-complex is reimplemented on top of f_lavfi.c. (which is
conceptually easy, but a big mess due to the data flow changes).
The existing filters are all changed heavily. The data flow of the new
filter framework is different. Especially EOF handling changes - EOF is
now a "frame" rather than a state, and must be passed through exactly
once.
Another major thing is that all filters must support dynamic format
changes. The filter reconfig() function goes away. (This sounds complex,
but since all filters need to handle EOF draining anyway, they can use
the same code, and it removes the mess with reconfig() having to predict
the output format, which completely breaks with libavfilter anyway.)
In addition, there is no automatic format negotiation or conversion.
libavfilter's primitive and insufficient API simply doesn't allow us to
do this in a reasonable way. Instead, filters can use f_autoconvert as
sub-filter, and tell it which formats they support. This filter will in
turn add actual conversion filters, such as f_swscale, to perform
necessary format changes.
vf_vapoursynth.c uses the same basic principle of operation as before,
but with worryingly different details in data flow. Still appears to
work.
The hardware deint filters (vf_vavpp.c, vf_d3d11vpp.c, vf_vdpaupp.c) are
heavily changed. Fortunately, they all used refqueue.c, which is for
sharing the data flow logic (especially for managing future/past
surfaces and such). It turns out it can be used to factor out most of
the data flow. Some of these filters accepted software input. Instead of
having ad-hoc upload code in each filter, surface upload is now
delegated to f_autoconvert, which can use f_hwupload to perform this.
Exporting VO capabilities is still a big mess (mp_stream_info stuff).
The D3D11 code drops the redundant image formats, and all code uses the
hw_subfmt (sw_format in FFmpeg) instead. Although that too seems to be a
big mess for now.
f_async_queue is unused.
2018-01-16 11:53:44 +01:00
|
|
|
}
|
|
|
|
assert(frame_type && obj_list);
|
|
|
|
|
|
|
|
struct mp_filter *f = NULL;
|
|
|
|
|
|
|
|
struct m_obj_desc desc;
|
|
|
|
if (!m_obj_list_find(&desc, obj_list, bstr0(name))) {
|
|
|
|
// Generic lavfi bridge.
|
|
|
|
if (strncmp(name, "lavfi-", 6) == 0)
|
|
|
|
name += 6;
|
|
|
|
struct mp_lavfi *l =
|
|
|
|
mp_lavfi_create_filter(parent, frame_type, true, NULL, name, args);
|
|
|
|
if (l)
|
|
|
|
f = l->f;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *options = NULL;
|
|
|
|
if (desc.options) {
|
|
|
|
struct m_obj_settings *defs = NULL;
|
|
|
|
if (defs_name) {
|
|
|
|
mp_read_option_raw(parent->global, defs_name,
|
|
|
|
&m_option_type_obj_settings_list, &defs);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct m_config *config =
|
|
|
|
m_config_from_obj_desc_and_args(NULL, parent->log, parent->global,
|
|
|
|
&desc, name, defs, args);
|
|
|
|
|
|
|
|
struct m_option dummy = {.type = &m_option_type_obj_settings_list};
|
|
|
|
m_option_free(&dummy, &defs);
|
|
|
|
|
|
|
|
if (!config)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
options = config->optstruct;
|
|
|
|
// Free config when options is freed.
|
|
|
|
ta_set_parent(options, NULL);
|
|
|
|
ta_set_parent(config, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct mp_user_filter_entry *entry = desc.p;
|
|
|
|
f = entry->create(parent, options);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!f) {
|
|
|
|
MP_ERR(parent, "Creating filter '%s' failed.\n", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|