[PATCH] stream_ffmpeg: add -lavfstreamopts option.

Reimar Döffinger <[email protected]>
Newsgroups gmane.comp.video.mplayer.devel
Message-ID <[email protected]>
Allows specifying options to ffmpeg-based streams.
---
 DOCS/man/en/mplayer.1  |  4 ++++
 cfg-common.h           |  1 +
 stream/stream.h        |  1 +
 stream/stream_ffmpeg.c | 19 ++++++++++++++++++-
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1
index 2a143cb..d8e9b3b 100644
--- a/DOCS/man/en/mplayer.1
+++ b/DOCS/man/en/mplayer.1
@@ -1806,6 +1806,10 @@ Skip the proxy for IPv6 addresses.
 It will still be used for IPv4 connections.
 .
 .TP
+.B \-lavfstreamopts <options>
+Specify extra options for libavformat based streams.
+.
+.TP
 .B \-loadidx <index file>
 The file from which to read the video index data saved by \-saveidx.
 This index will be used for seeking, overriding any index data
diff --git a/cfg-common.h b/cfg-common.h
index 3a422cf..ca4e9c9 100644
--- a/cfg-common.h
+++ b/cfg-common.h
@@ -545,6 +545,7 @@ const m_option_t common_opts[] = {
 #ifdef CONFIG_FFMPEG
     {"lavdopts", lavc_decode_opts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
     {"lavfdopts",  lavfdopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
+    {"lavfstreamopts",  &lavfstreamopts, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
 #endif
 #ifdef CONFIG_XVID4
     {"xvidopts", xvid_dec_opts, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
diff --git a/stream/stream.h b/stream/stream.h
index 615f579..388c353 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -392,6 +392,7 @@ extern char *dvd_device;
 extern const m_option_t dvbin_opts_conf[];
 
 extern char *rtsp_destination;
+extern char *lavfstreamopts;
 
 typedef struct {
  int id; // 0 - 31 mpeg; 128 - 159 ac3; 160 - 191 pcm
diff --git a/stream/stream_ffmpeg.c b/stream/stream_ffmpeg.c
index 57d45e4..1883af3 100644
--- a/stream/stream_ffmpeg.c
+++ b/stream/stream_ffmpeg.c
@@ -27,6 +27,8 @@
 #include "av_helpers.h"
 #include "libmpdemux/demuxer.h"
 
+char *lavfstreamopts;
+
 static int fill_buffer(stream_t *s, char *buffer, int max_len)
 {
     int r = avio_read(s->priv, buffer, max_len);
@@ -90,6 +92,7 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
 {
     int flags = 0;
     const char *filename;
+    AVDictionary *avopts = NULL;
     AVIOContext *ctx = NULL;
     int res = STREAM_ERROR;
     int64_t size;
@@ -125,9 +128,23 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
     dummy = !strncmp(filename, "rtsp:", 5) || !strncmp(filename, "dummy:", 6);
     mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename);
 
-    if (!dummy && avio_open(&ctx, filename, flags) < 0)
+    if (lavfstreamopts && av_dict_parse_string(&avopts, lavfstreamopts, "=", ",", 0) < 0) {
+        mp_msg(MSGT_HEADER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", lavfstreamopts);
+        goto out;
+    }
+
+    if (!dummy && avio_open2(&ctx, filename, flags, NULL, &avopts) < 0)
         goto out;
 
+    if (!dummy && av_dict_count(avopts)) {
+        AVDictionaryEntry *e = NULL;
+        while ((e = av_dict_get(avopts, "", e, AV_DICT_IGNORE_SUFFIX))) {
+            mp_msg(MSGT_HEADER,MSGL_ERR,"Unknown option %s\n", e->key);
+        }
+        goto out;
+    }
+    av_dict_free(&avopts);
+
     stream->priv = ctx;
     size = dummy ? 0 : avio_size(ctx);
     if (size >= 0)
-- 
2.7.0

_______________________________________________
MPlayer-dev-eng mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.