encode: don't apply default config options

Often, user configs set options that are not suitable for encoding.
Usually, playback and encoding are pretty different things, so it makes
sense to keep them strictly separate. There are several possible
solutions. The approach taken by this commit is to basically ignore the
default config settings, and switch to an [encoding] config profile
section instead. This also makes it impossible to have --o in a config
file, because --o enables encode mode.

See github issue #727 for discussion.
This commit is contained in:
wm4 2014-04-19 22:05:17 +02:00
parent 85998f6121
commit b85983a4a6
8 changed files with 36 additions and 20 deletions

View File

@ -38,6 +38,11 @@ section::
oac = aac
oacopts-add = b=96k
It's also possible to define default encoding options by putting them into
the section named ``[encoding]``. (This behavior changed after mpv 0.3.x. In
mpv 0.3.x, config options in the default section / no section were applied
to encoding. This is not the case anymore.)
One can then encode using this profile using the command::
mpv infile -o outfile.mp4 -profile myencprofile

View File

@ -3,7 +3,7 @@ ENCODING
You can encode files from one format/codec to another using this facility.
``-o <filename>``
``--o=<filename>``
Enables encoding mode and specifies the output file name.
``--of=<format>``

View File

@ -758,6 +758,8 @@ struct m_profile *m_config_get_profile0(const struct m_config *config,
struct m_profile *m_config_add_profile(struct m_config *config, char *name)
{
if (!name || !name[0] || strcmp(name, "default") == 0)
return NULL; // never a real profile
struct m_profile *p = m_config_get_profile0(config, name);
if (p)
return p;

View File

@ -619,7 +619,7 @@ const m_option_t mp_opts[] = {
OPT_PRINT("V", print_version),
#if HAVE_ENCODING
OPT_STRING("o", encode_output.file, CONF_GLOBAL),
OPT_STRING("o", encode_output.file, CONF_GLOBAL | CONF_NOCFG | CONF_PRE_PARSE),
OPT_STRING("of", encode_output.format, CONF_GLOBAL),
OPT_STRINGLIST("ofopts*", encode_output.fopts, CONF_GLOBAL),
OPT_FLOATRANGE("ofps", encode_output.fps, CONF_GLOBAL, 0.0, 1000000.0),

View File

@ -38,14 +38,13 @@
/// Current include depth.
static int recursion_depth = 0;
/// Setup the \ref Config from a config file.
/** \param config The config object.
* \param conffile Path to the config file.
* \param flags M_SETOPT_* bits
* \return 1 on sucess, -1 on error, 0 if file not accessible.
*/
// Load options and profiles from from a config file.
// conffile: path to the config file
// initial_section: default section where to add normal options
// flags: M_SETOPT_* bits
// returns: 1 on sucess, -1 on error, 0 if file not accessible.
int m_config_parse_config_file(m_config_t *config, const char *conffile,
int flags)
char *initial_section, int flags)
{
#define PRINT_LINENUM MP_ERR(config, "%s:%d: ", conffile, line_num)
#define MAX_LINE_LEN 10000
@ -63,7 +62,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
int param_pos; /* param pos */
int ret = 1;
int errors = 0;
m_profile_t *profile = NULL;
m_profile_t *profile = m_config_add_profile(config, initial_section);
flags = flags | M_SETOPT_FROM_CONFIG_FILE;
@ -132,10 +131,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
/* Profile declaration */
if (opt_pos > 2 && opt[0] == '[' && opt[opt_pos - 1] == ']') {
opt[opt_pos - 1] = '\0';
if (strcmp(opt + 1, "default"))
profile = m_config_add_profile(config, opt + 1);
else
profile = NULL;
profile = m_config_add_profile(config, opt + 1);
continue;
}

View File

@ -22,6 +22,6 @@
#include "m_config.h"
int m_config_parse_config_file(m_config_t* config, const char *conffile,
int flags);
char *initial_section, int flags);
#endif /* MPLAYER_PARSER_CFG_H */

View File

@ -44,6 +44,8 @@
#include "core.h"
#include "command.h"
#define SECT_ENCODE "encoding"
bool mp_parse_cfgfiles(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
@ -54,27 +56,38 @@ bool mp_parse_cfgfiles(struct MPContext *mpctx)
void *tmp = talloc_new(NULL);
bool r = true;
char *conffile;
char *section = NULL;
bool encoding = opts->encode_output.file && *opts->encode_output.file;
// In encoding mode, we don't want to apply normal config options.
// So we "divert" normal options into a separate section, and the diverted
// section is never used - unless maybe it's explicitly referenced from an
// encoding profile.
if (encoding)
section = "playback-default";
// The #if is a stupid hack to avoid errors if libavfilter is not available.
#if HAVE_LIBAVFILTER && HAVE_ENCODING
conffile = mp_find_config_file(tmp, mpctx->global, "encoding-profiles.conf");
if (conffile && mp_path_exists(conffile))
m_config_parse_config_file(mpctx->mconfig, conffile, 0);
m_config_parse_config_file(mpctx->mconfig, conffile, SECT_ENCODE, 0);
#endif
conffile = mp_find_global_config_file(tmp, mpctx->global, "mpv.conf");
if (conffile && m_config_parse_config_file(conf, conffile, 0) < 0) {
if (conffile && m_config_parse_config_file(conf, conffile, section, 0) < 0) {
r = false;
goto done;
}
mp_mk_config_dir(mpctx->global, NULL);
if (!(conffile = mp_find_user_config_file(tmp, mpctx->global, "config")))
MP_ERR(mpctx, "mp_find_user_config_file(\"config\") problem\n");
else if (m_config_parse_config_file(conf, conffile, 0) < 0) {
else if (m_config_parse_config_file(conf, conffile, section, 0) < 0) {
r = false;
goto done;
}
if (encoding)
m_config_set_profile(conf, m_config_add_profile(conf, SECT_ENCODE), 0);
done:
talloc_free(tmp);
return r;
@ -85,7 +98,7 @@ static int try_load_config(struct MPContext *mpctx, const char *file, int flags)
if (!mp_path_exists(file))
return 0;
MP_INFO(mpctx, "Loading config '%s'\n", file);
m_config_parse_config_file(mpctx->mconfig, file, flags);
m_config_parse_config_file(mpctx->mconfig, file, NULL, flags);
return 1;
}

View File

@ -300,7 +300,7 @@ static void osdep_preinit(int *p_argc, char ***p_argv)
static int cfg_include(void *ctx, char *filename, int flags)
{
struct MPContext *mpctx = ctx;
return m_config_parse_config_file(mpctx->mconfig, filename, flags);
return m_config_parse_config_file(mpctx->mconfig, filename, NULL, flags);
}
struct MPContext *mp_create(void)