0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

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.
This commit is contained in:
wm4 2014-07-30 01:15:42 +02:00
parent da780309d7
commit 26d973ce82
6 changed files with 38 additions and 0 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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 --------------------

View File

@ -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;

View File

@ -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,