mirror of
https://github.com/mpv-player/mpv
synced 2025-02-20 23:07:02 +00:00
options: add options that set defaults for af/vf/ao/vo
There are some use cases for this. For example, you can use it to set defaults of automatically inserted filters (like af_lavrresample). It's also useful if you have a non-trivial VO configuration, and want to use --vo to quickly change between the drivers without repeating the whole configuration in the --vo argument.
This commit is contained in:
parent
aaddcb702e
commit
b18f02d1ad
@ -11,6 +11,12 @@ syntax is:
|
||||
|
||||
To get a full list of available audio filters, see ``--af=help``.
|
||||
|
||||
You can also set defaults for each filter. The defaults are applied before the
|
||||
normal filter parameters.
|
||||
|
||||
``--af-defaults=<filter1[=parameter1:parameter2:...],filter2,...>``
|
||||
Set defaults for each filter.
|
||||
|
||||
Audio filters are managed in lists. There are a few commands to manage the
|
||||
filter list:
|
||||
|
||||
@ -50,9 +56,9 @@ Available filters are:
|
||||
entries. (default: no)
|
||||
``no-detach``
|
||||
Do not detach if input and output audio format/rate/channels match.
|
||||
You should add this option if you specify additional parameters, as
|
||||
automatically inserted lavrresample instances will use the default
|
||||
settings.
|
||||
(If you just want to set defaults for this filter that will be used
|
||||
even by automatically inserted lavrresample instances, you should
|
||||
prefer setting them with ``--af-defaults=lavrresample:...``.)
|
||||
``o=<string>``
|
||||
Set AVOptions on the SwrContext or AVAudioResampleContext. These should
|
||||
be documented by FFmpeg or Libav.
|
||||
|
@ -10,6 +10,12 @@ syntax is:
|
||||
If the list has a trailing ',', mpv will fall back on drivers not contained
|
||||
in the list. Suboptions are optional and can mostly be omitted.
|
||||
|
||||
You can also set defaults for each driver. The defaults are applied before the
|
||||
normal driver parameters.
|
||||
|
||||
``--ao-defaults=<driver1[:parameter1:parameter2:...],driver2,...>``
|
||||
Set defaults for each driver.
|
||||
|
||||
.. note::
|
||||
|
||||
See ``--ao=help`` for a list of compiled-in audio output drivers.
|
||||
|
@ -7,6 +7,12 @@ syntax is:
|
||||
``--vf=<filter1[=parameter1:parameter2:...],filter2,...>``
|
||||
Setup a chain of video filters.
|
||||
|
||||
You can also set defaults for each filter. The defaults are applied before the
|
||||
normal filter parameters.
|
||||
|
||||
``--vf-defaults=<filter1[=parameter1:parameter2:...],filter2,...>``
|
||||
Set defaults for each filter.
|
||||
|
||||
Many parameters are optional and set to default values if omitted. To
|
||||
explicitly use a default value, set a parameter to '-1'. Parameters ``w:h``
|
||||
means width x height in pixels, ``x:y`` means x;y position counted from the
|
||||
|
@ -10,6 +10,12 @@ syntax is:
|
||||
If the list has a trailing ',', mpv will fall back on drivers not contained
|
||||
in the list. Suboptions are optional and can mostly be omitted.
|
||||
|
||||
You can also set defaults for each driver. The defaults are applied before the
|
||||
normal driver parameters.
|
||||
|
||||
``--vo-defaults=<driver1[:parameter1:parameter2:...],driver2,...>``
|
||||
Set defaults for each driver.
|
||||
|
||||
.. note::
|
||||
|
||||
See ``--vo=help`` for a list of compiled-in video output drivers.
|
||||
|
@ -204,6 +204,8 @@ static struct af_instance *af_create(struct af_stream *s, char *name,
|
||||
.data = talloc_zero(af, struct mp_audio),
|
||||
};
|
||||
struct m_config *config = m_config_from_obj_desc(af, &desc);
|
||||
if (m_config_apply_defaults(config, name, s->opts->af_defs) < 0)
|
||||
goto error;
|
||||
if (m_config_initialize_obj(config, &desc, &af->priv, &args) < 0)
|
||||
goto error;
|
||||
|
||||
|
@ -79,7 +79,6 @@ struct af_stream {
|
||||
struct af_instance *last;
|
||||
// The user sets the input format (what the decoder outputs), and sets some
|
||||
// or all fields in output to the output format the AO accepts.
|
||||
// See fixup_output_format().
|
||||
struct mp_audio input;
|
||||
struct mp_audio output;
|
||||
struct mp_audio filter_output;
|
||||
|
@ -150,6 +150,8 @@ static struct ao *ao_create(bool probing, struct mpv_global *global,
|
||||
if (ao->driver->encode != !!ao->encode_lavc_ctx)
|
||||
goto error;
|
||||
struct m_config *config = m_config_from_obj_desc(ao, &desc);
|
||||
if (m_config_apply_defaults(config, name, global->opts->ao_defs) < 0)
|
||||
goto error;
|
||||
if (m_config_set_obj_params(config, args) < 0)
|
||||
goto error;
|
||||
ao->priv = config->optstruct;
|
||||
|
@ -230,6 +230,26 @@ int m_config_set_obj_params(struct m_config *conf, char **args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int m_config_apply_defaults(struct m_config *config, const char *name,
|
||||
struct m_obj_settings *defaults)
|
||||
{
|
||||
int r = 0;
|
||||
for (int n = 0; defaults && defaults[n].name; n++) {
|
||||
struct m_obj_settings *entry = &defaults[n];
|
||||
if (name && strcmp(entry->name, name) == 0) {
|
||||
if (entry->attribs && strcmp(entry->attribs[0], "_oldargs_") == 0) {
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Filter '%s' can't take defaults, because it uses "
|
||||
"custom option parsing.\n", name);
|
||||
return -1;
|
||||
}
|
||||
r = m_config_set_obj_params(config, entry->attribs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int m_config_initialize_obj(struct m_config *config, struct m_obj_desc *desc,
|
||||
void **ppriv, char ***pargs)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ struct m_option;
|
||||
struct m_option_type;
|
||||
struct m_sub_options;
|
||||
struct m_obj_desc;
|
||||
struct m_obj_settings;
|
||||
|
||||
// Config option
|
||||
struct m_config_option {
|
||||
@ -87,6 +88,11 @@ struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx,
|
||||
|
||||
int m_config_set_obj_params(struct m_config *conf, char **args);
|
||||
|
||||
// Search for the object with the given name in the defaults list, and apply
|
||||
// its parameters.
|
||||
int m_config_apply_defaults(struct m_config *config, const char *name,
|
||||
struct m_obj_settings *defaults);
|
||||
|
||||
// Initialize an object (VO/VF/...) in one go, including legacy handling.
|
||||
// This is pretty specialized, and is just for convenience.
|
||||
int m_config_initialize_obj(struct m_config *config, struct m_obj_desc *desc,
|
||||
|
@ -466,7 +466,9 @@ const m_option_t mp_opts[] = {
|
||||
|
||||
// ------------------------- codec/vfilter options --------------------
|
||||
|
||||
OPT_SETTINGSLIST("af-defaults", af_defs, 0, &af_obj_list),
|
||||
OPT_SETTINGSLIST("af*", af_settings, 0, &af_obj_list),
|
||||
OPT_SETTINGSLIST("vf-defaults", vf_defs, 0, &vf_obj_list),
|
||||
OPT_SETTINGSLIST("vf*", vf_settings, 0, &vf_obj_list),
|
||||
|
||||
OPT_CHOICE("deinterlace", deinterlace, M_OPT_OPTIONAL_PARAM,
|
||||
@ -557,7 +559,9 @@ const m_option_t mp_opts[] = {
|
||||
|
||||
//---------------------- libao/libvo options ------------------------
|
||||
OPT_SETTINGSLIST("vo", vo.video_driver_list, 0, &vo_obj_list),
|
||||
OPT_SETTINGSLIST("vo-defaults", vo.vo_defs, 0, &vo_obj_list),
|
||||
OPT_SETTINGSLIST("ao", audio_driver_list, 0, &ao_obj_list),
|
||||
OPT_SETTINGSLIST("ao-defaults", ao_defs, 0, &ao_obj_list),
|
||||
OPT_FLAG("fixed-vo", fixed_vo, CONF_GLOBAL),
|
||||
OPT_FLAG("force-window", force_vo, CONF_GLOBAL),
|
||||
OPT_FLAG("ontop", vo.ontop, 0),
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "mpvcore/m_option.h"
|
||||
|
||||
typedef struct mp_vo_opts {
|
||||
struct m_obj_settings *video_driver_list;
|
||||
struct m_obj_settings *video_driver_list, *vo_defs;
|
||||
|
||||
int screenwidth;
|
||||
int screenheight;
|
||||
@ -48,7 +48,7 @@ typedef struct MPOpts {
|
||||
char **lua_files;
|
||||
int lua_load_osc;
|
||||
|
||||
struct m_obj_settings *audio_driver_list;
|
||||
struct m_obj_settings *audio_driver_list, *ao_defs;
|
||||
int fixed_vo;
|
||||
int force_vo;
|
||||
int softvol;
|
||||
@ -174,8 +174,8 @@ typedef struct MPOpts {
|
||||
int force_srate;
|
||||
int dtshd;
|
||||
double playback_speed;
|
||||
struct m_obj_settings *vf_settings;
|
||||
struct m_obj_settings *af_settings;
|
||||
struct m_obj_settings *vf_settings, *vf_defs;
|
||||
struct m_obj_settings *af_settings, *af_defs;
|
||||
int deinterlace;
|
||||
float movie_aspect;
|
||||
int flip;
|
||||
|
@ -251,6 +251,8 @@ static struct vf_instance *vf_open(struct MPOpts *opts, vf_instance_t *next,
|
||||
.out_pool = talloc_steal(vf, mp_image_pool_new(16)),
|
||||
};
|
||||
struct m_config *config = m_config_from_obj_desc(vf, &desc);
|
||||
if (m_config_apply_defaults(config, name, opts->vf_defs) < 0)
|
||||
goto error;
|
||||
void *priv = NULL;
|
||||
if (m_config_initialize_obj(config, &desc, &priv, &args) < 0)
|
||||
goto error;
|
||||
|
@ -169,6 +169,8 @@ static struct vo *vo_create(struct mpv_global *global,
|
||||
if (vo->driver->encode != !!vo->encode_lavc_ctx)
|
||||
goto error;
|
||||
struct m_config *config = m_config_from_obj_desc(vo, &desc);
|
||||
if (m_config_apply_defaults(config, name, vo->opts->vo_defs) < 0)
|
||||
goto error;
|
||||
if (m_config_set_obj_params(config, args) < 0)
|
||||
goto error;
|
||||
vo->priv = config->optstruct;
|
||||
|
Loading…
Reference in New Issue
Block a user