diff options
author | wm4 <wm4@nowhere> | 2014-07-30 01:15:42 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-07-30 01:15:42 +0200 |
commit | 26d973ce827555619405bf62db24bf4ae12a4a90 (patch) | |
tree | 1b5f97301adca8ac102d6b530ebbc04d604dd47b | |
parent | da780309d707ac995941c14d1f5bbc8f1a7239b8 (diff) | |
download | mpv-26d973ce827555619405bf62db24bf4ae12a4a90.tar.bz2 mpv-26d973ce827555619405bf62db24bf4ae12a4a90.tar.xz |
stream_lavf: allow setting AVOptions with --stream-lavf-o
This commit also creates a private option struct for stream_lavf.c, but
since I'm lazy, I'm not moving any existing options to it.
-rw-r--r-- | DOCS/man/options.rst | 7 | ||||
-rw-r--r-- | common/av_common.c | 9 | ||||
-rw-r--r-- | common/av_common.h | 2 | ||||
-rw-r--r-- | options/options.c | 2 | ||||
-rw-r--r-- | options/options.h | 1 | ||||
-rw-r--r-- | stream/stream_lavf.c | 17 |
6 files changed, 38 insertions, 0 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 1e02d0f2b5..9f67523f66 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -1706,6 +1706,13 @@ OPTIONS Same as ``--stream-capture``, but do not start playback. Instead, the entire file is dumped. +``--stream-lavf-o=opt1=value1,opt2=value2,...`` + Set AVOptions on streams opened with libavformat. Unknown or misspelled + options are silently ignored. (They are mentioned in the terminal output + in verbose mode, i.e. ``--v``. In general we can't print errors, because + other options such as e.g. user agent are not available with all protocols, + and printing errors for unknown options would end up being too noisy.) + ``--playlist=<filename>`` Play files according to a playlist file (Supports some common formats.If no format is detected, t will be treated as list of files, separated by diff --git a/common/av_common.c b/common/av_common.c index d8d5c7e09d..d090ccfc50 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -19,6 +19,7 @@ #include <libavutil/common.h> #include <libavutil/log.h> +#include <libavutil/dict.h> #include <libavcodec/avcodec.h> #include "common/common.h" @@ -180,3 +181,11 @@ const char *mp_codec_from_av_codec_id(int codec_id) } return name; } + +// kv is in the format as by OPT_KEYVALUELIST(): kv[0]=key0, kv[1]=val0, ... +// Copy them to the dict. +void mp_set_avdict(AVDictionary **dict, char **kv) +{ + for (int n = 0; kv && kv[n * 2]; n++) + av_dict_set(dict, kv[n * 2 + 0], kv[n * 2 + 1], 0); +} diff --git a/common/av_common.h b/common/av_common.h index 2e55fe17a0..4afebe6662 100644 --- a/common/av_common.h +++ b/common/av_common.h @@ -26,6 +26,7 @@ struct mp_decoder_list; struct demux_packet; +struct AVDictionary; int mp_lavc_set_extradata(AVCodecContext *avctx, void *ptr, int size); void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st); @@ -36,5 +37,6 @@ void mp_set_avcodec_threads(AVCodecContext *avctx, int threads); void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type); int mp_codec_to_av_codec_id(const char *codec); const char *mp_codec_from_av_codec_id(int codec_id); +void mp_set_avdict(struct AVDictionary **dict, char **kv); #endif diff --git a/options/options.c b/options/options.c index 955526f740..0d7f426606 100644 --- a/options/options.c +++ b/options/options.c @@ -63,6 +63,7 @@ extern const struct m_sub_options tv_params_conf; extern const struct m_sub_options stream_pvr_conf; extern const struct m_sub_options stream_cdda_conf; extern const struct m_sub_options stream_dvb_conf; +extern const struct m_sub_options stream_lavf_conf; extern const struct m_sub_options sws_conf; extern const struct m_sub_options demux_rawaudio_conf; extern const struct m_sub_options demux_rawvideo_conf; @@ -229,6 +230,7 @@ const m_option_t mp_opts[] = { #if HAVE_DVBIN OPT_SUBSTRUCT("dvbin", stream_dvb_opts, stream_dvb_conf, 0), #endif + OPT_SUBSTRUCT("", stream_lavf_opts, stream_lavf_conf, 0), // ------------------------- a-v sync options -------------------- diff --git a/options/options.h b/options/options.h index 51867b9cc9..b7db8b08ce 100644 --- a/options/options.h +++ b/options/options.h @@ -250,6 +250,7 @@ typedef struct MPOpts { struct pvr_params *stream_pvr_opts; struct cdda_params *stream_cdda_opts; struct dvb_params *stream_dvb_opts; + struct stream_lavf_params *stream_lavf_opts; char *cdrom_device; int dvd_title; diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c index 925be8acd1..c736ade45f 100644 --- a/stream/stream_lavf.c +++ b/stream/stream_lavf.c @@ -25,6 +25,7 @@ #include "options/path.h" #include "common/msg.h" #include "common/tags.h" +#include "common/av_common.h" #include "stream.h" #include "options/m_option.h" @@ -33,6 +34,21 @@ #include "bstr/bstr.h" #include "talloc.h" +struct stream_lavf_params *stream_lavf_opts; + +#define OPT_BASE_STRUCT struct stream_lavf_params +struct stream_lavf_params { + char **avopts; +}; + +const struct m_sub_options stream_lavf_conf = { + .opts = (const m_option_t[]) { + OPT_KEYVALUELIST("stream-lavf-o", avopts, 0), + {0} + }, + .size = sizeof(struct stream_lavf_params), +}; + static int open_f(stream_t *stream); static struct mp_tags *read_icy(stream_t *stream); @@ -199,6 +215,7 @@ static int open_f(stream_t *stream) if (strlen(cust_headers)) av_dict_set(&dict, "headers", cust_headers, 0); av_dict_set(&dict, "icy", "1", 0); + mp_set_avdict(&dict, opts->stream_lavf_opts->avopts); AVIOInterruptCB cb = { .callback = interrupt_cb, |