encode: make option struct local

Similar to previous commits.
This commit is contained in:
wm4 2014-06-11 02:04:02 +02:00
parent be5725ebc4
commit 8f60de98be
7 changed files with 70 additions and 56 deletions

View File

@ -8,15 +8,36 @@
struct mpv_global;
struct mp_log;
struct encode_lavc_context;
struct encode_output_conf;
struct encode_opts {
char *file;
char *format;
char **fopts;
float fps;
float maxfps;
char *vcodec;
char **vopts;
char *acodec;
char **aopts;
int harddup;
float voffset;
float aoffset;
int copyts;
int rawts;
int autofps;
int neverdrop;
int video_first;
int audio_first;
int metadata;
};
// interface for mplayer.c
struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options,
struct encode_lavc_context *encode_lavc_init(struct encode_opts *options,
struct mpv_global *global);
void encode_lavc_finish(struct encode_lavc_context *ctx);
void encode_lavc_free(struct encode_lavc_context *ctx);
void encode_lavc_discontinuity(struct encode_lavc_context *ctx);
bool encode_lavc_showhelp(struct mp_log *log, struct encode_output_conf *options);
bool encode_lavc_showhelp(struct mp_log *log, struct encode_opts *options);
int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, float relative_position);
void encode_lavc_expect_stream(struct encode_lavc_context *ctx, int mt);
void encode_lavc_set_metadata(struct encode_lavc_context *ctx,

View File

@ -27,12 +27,43 @@
#include "common/msg.h"
#include "common/msg_control.h"
#include "video/vfcap.h"
#include "options/m_option.h"
#include "options/options.h"
#include "osdep/timer.h"
#include "video/out/vo.h"
#include "talloc.h"
#include "stream/stream.h"
#define OPT_BASE_STRUCT struct encode_opts
const struct m_sub_options encode_config = {
.opts = (const m_option_t[]) {
OPT_STRING("o", file, CONF_GLOBAL | CONF_NOCFG | CONF_PRE_PARSE),
OPT_STRING("of", format, CONF_GLOBAL),
OPT_STRINGLIST("ofopts*", fopts, CONF_GLOBAL),
OPT_FLOATRANGE("ofps", fps, CONF_GLOBAL, 0.0, 1000000.0),
OPT_FLOATRANGE("omaxfps", maxfps, CONF_GLOBAL, 0.0, 1000000.0),
OPT_STRING("ovc", vcodec, CONF_GLOBAL),
OPT_STRINGLIST("ovcopts*", vopts, CONF_GLOBAL),
OPT_STRING("oac", acodec, CONF_GLOBAL),
OPT_STRINGLIST("oacopts*", aopts, CONF_GLOBAL),
OPT_FLAG("oharddup", harddup, CONF_GLOBAL),
OPT_FLOATRANGE("ovoffset", voffset, CONF_GLOBAL, -1000000.0, 1000000.0),
OPT_FLOATRANGE("oaoffset", aoffset, CONF_GLOBAL, -1000000.0, 1000000.0),
OPT_FLAG("ocopyts", copyts, CONF_GLOBAL),
OPT_FLAG("orawts", rawts, CONF_GLOBAL),
OPT_FLAG("oautofps", autofps, CONF_GLOBAL),
OPT_FLAG("oneverdrop", neverdrop, CONF_GLOBAL),
OPT_FLAG("ovfirst", video_first, CONF_GLOBAL),
OPT_FLAG("oafirst", audio_first, CONF_GLOBAL),
OPT_FLAG("ometadata", metadata, CONF_GLOBAL),
{0}
},
.size = sizeof(struct encode_opts),
.defaults = &(const struct encode_opts){
.metadata = 1,
},
};
static int set_to_avdictionary(struct encode_lavc_context *ctx,
AVDictionary **dictp,
const char *key,
@ -124,7 +155,7 @@ int encode_lavc_oformat_flags(struct encode_lavc_context *ctx)
return ctx->avc ? ctx->avc->oformat->flags : 0;
}
struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options,
struct encode_lavc_context *encode_lavc_init(struct encode_opts *options,
struct mpv_global *global)
{
struct encode_lavc_context *ctx;
@ -905,7 +936,7 @@ static void encode_lavc_printoptions(struct mp_log *log, void *obj,
}
}
bool encode_lavc_showhelp(struct mp_log *log, struct encode_output_conf *opts)
bool encode_lavc_showhelp(struct mp_log *log, struct encode_opts *opts)
{
bool help_output = false;
if (av_codec_next(NULL) == NULL)

View File

@ -36,7 +36,7 @@
struct encode_lavc_context {
struct mpv_global *global;
struct encode_output_conf *options;
struct encode_opts *options;
struct mp_log *log;
struct mp_tags *metadata;

View File

@ -66,6 +66,7 @@ extern const struct m_sub_options demux_lavf_conf;
extern const struct m_sub_options vd_lavc_conf;
extern const struct m_sub_options ad_lavc_conf;
extern const struct m_sub_options input_config;
extern const struct m_sub_options encode_config;
extern const struct m_obj_list vf_obj_list;
extern const struct m_obj_list af_obj_list;
@ -505,29 +506,11 @@ const m_option_t mp_opts[] = {
OPT_PRINT("version", print_version),
OPT_PRINT("V", print_version),
#if HAVE_ENCODING
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),
OPT_FLOATRANGE("omaxfps", encode_output.maxfps, CONF_GLOBAL, 0.0, 1000000.0),
OPT_STRING("ovc", encode_output.vcodec, CONF_GLOBAL),
OPT_STRINGLIST("ovcopts*", encode_output.vopts, CONF_GLOBAL),
OPT_STRING("oac", encode_output.acodec, CONF_GLOBAL),
OPT_STRINGLIST("oacopts*", encode_output.aopts, CONF_GLOBAL),
OPT_FLAG("oharddup", encode_output.harddup, CONF_GLOBAL),
OPT_FLOATRANGE("ovoffset", encode_output.voffset, CONF_GLOBAL, -1000000.0, 1000000.0),
OPT_FLOATRANGE("oaoffset", encode_output.aoffset, CONF_GLOBAL, -1000000.0, 1000000.0),
OPT_FLAG("ocopyts", encode_output.copyts, CONF_GLOBAL),
OPT_FLAG("orawts", encode_output.rawts, CONF_GLOBAL),
OPT_FLAG("oautofps", encode_output.autofps, CONF_GLOBAL),
OPT_FLAG("oneverdrop", encode_output.neverdrop, CONF_GLOBAL),
OPT_FLAG("ovfirst", encode_output.video_first, CONF_GLOBAL),
OPT_FLAG("oafirst", encode_output.audio_first, CONF_GLOBAL),
OPT_FLAG("ometadata", encode_output.metadata, CONF_GLOBAL),
#ifdef HAVE_ENCODING
OPT_SUBSTRUCT("", encode_opts, encode_config, 0),
#endif
{NULL, NULL, 0, 0, 0, 0, NULL}
{0}
};
const struct MPOpts mp_default_opts = {
@ -643,10 +626,6 @@ const struct MPOpts mp_default_opts = {
.dvd_angle = 1,
.mf_fps = 1.0,
.encode_output = {
.metadata = 1,
},
};
#endif /* MPLAYER_CFG_MPLAYER_H */

View File

@ -265,27 +265,8 @@ typedef struct MPOpts {
struct input_opts *input_opts;
struct encode_output_conf {
char *file;
char *format;
char **fopts;
float fps;
float maxfps;
char *vcodec;
char **vopts;
char *acodec;
char **aopts;
int harddup;
float voffset;
float aoffset;
int copyts;
int rawts;
int autofps;
int neverdrop;
int video_first;
int audio_first;
int metadata;
} encode_output;
// may be NULL if encoding is not compiled-in
struct encode_opts *encode_opts;
} MPOpts;
extern const m_option_t mp_opts[];

View File

@ -32,6 +32,7 @@
#include "osdep/io.h"
#include "common/global.h"
#include "common/encode.h"
#include "common/msg.h"
#include "options/path.h"
#include "options/m_config.h"
@ -58,7 +59,8 @@ bool mp_parse_cfgfiles(struct MPContext *mpctx)
bool r = true;
char *conffile;
char *section = NULL;
bool encoding = opts->encode_output.file && *opts->encode_output.file;
bool encoding = opts->encode_opts &&
opts->encode_opts->file && opts->encode_opts->file[0];
// 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

View File

@ -236,7 +236,7 @@ static bool handle_help_options(struct MPContext *mpctx)
opt_exit = 1;
}
#if HAVE_ENCODING
if (encode_lavc_showhelp(log, &opts->encode_output))
if (encode_lavc_showhelp(log, opts->encode_opts))
opt_exit = 1;
#endif
return opt_exit;
@ -383,8 +383,8 @@ int mp_initialize(struct MPContext *mpctx)
mp_dispatch_set_wakeup_fn(mpctx->dispatch, wakeup_playloop, mpctx);
#if HAVE_ENCODING
if (opts->encode_output.file && *opts->encode_output.file) {
mpctx->encode_lavc_ctx = encode_lavc_init(&opts->encode_output,
if (opts->encode_opts->file && opts->encode_opts->file[0]) {
mpctx->encode_lavc_ctx = encode_lavc_init(opts->encode_opts,
mpctx->global);
if(!mpctx->encode_lavc_ctx) {
MP_INFO(mpctx, "Encoding initialization failed.");