[PATCH] vf_scale: add generic libswscale options support.

Reimar Döffinger <[email protected]>
Newsgroups gmane.comp.video.mplayer.devel
Message-ID <[email protected]>
Allows setting any of the options exposed by libswscale,
in particular for example source and destination colorspace
range.
---
 DOCS/man/en/mplayer.1  |  5 +++++
 av_opts.c              |  6 ++++++
 cfg-common.h           |  1 +
 libmpcodecs/vf_scale.c | 25 ++++++++++++++++++++++++-
 libmpcodecs/vf_scale.h |  1 +
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1
index 7c01ca2c8..8e28024de 100644
--- a/DOCS/man/en/mplayer.1
+++ b/DOCS/man/en/mplayer.1
@@ -5405,6 +5405,11 @@ The description of the scale video filter has further information.
 .RE
 .
 .TP
+.B \-swsopts <software scaler options>
+Specify advanced software scaler options provided by libswscale.
+Set to "help" to get a list of supported options.
+.
+.TP
 .B \-vc <[\-|+]codec1,[\-|+]codec2,...[,]>
 Specify a priority list of video codecs to be used, according to their codec
 name in codecs.conf.
diff --git a/av_opts.c b/av_opts.c
index e10e92e90..30e049db2 100644
--- a/av_opts.c
+++ b/av_opts.c
@@ -30,6 +30,12 @@ int parse_avopts(void *v, char *str){

     if (!v)
         return -1;
+    if (!str)
+        return 0;
+    if (strcmp(str, "help") == 0) {
+        av_opt_show2(v, NULL, -1, 0);
+        return -1;
+    }

     start= str= strdup(str);

diff --git a/cfg-common.h b/cfg-common.h
index ca4e9c9cb..bfb815790 100644
--- a/cfg-common.h
+++ b/cfg-common.h
@@ -521,6 +521,7 @@ const m_option_t common_opts[] = {

     // scaling:
     {"sws", &sws_flags, CONF_TYPE_INT, 0, 0, 2, NULL},
+    {"swsopts", &sws_opts, CONF_TYPE_STRING, 0, 0, 0, NULL},
     {"ssf", scaler_filter_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
     {"zoom", &softzoom, CONF_TYPE_FLAG, 0, 0, 1, NULL},
     {"nozoom", &softzoom, CONF_TYPE_FLAG, 0, 1, 0, NULL},
diff --git a/libmpcodecs/vf_scale.c b/libmpcodecs/vf_scale.c
index ef50261ea..e48a2ad45 100644
--- a/libmpcodecs/vf_scale.c
+++ b/libmpcodecs/vf_scale.c
@@ -32,9 +32,11 @@
 #include "fmt-conversion.h"
 #include "mpbswap.h"

+#include "libavutil/opt.h"
 #include "libswscale/swscale.h"
 #include "vf_scale.h"

+#include "av_opts.h"
 #include "m_option.h"
 #include "m_struct.h"

@@ -588,6 +590,7 @@ static int vf_open(vf_instance_t *vf, char *args){

 //global sws_flags from the command line
 int sws_flags=2;
+char *sws_opts;

 //global srcFilter
 static SwsFilter *src_filter= NULL;
@@ -648,6 +651,7 @@ struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat,
 {
         int flags;
         SwsFilter *dstFilterParam, *srcFilterParam;
+        struct SwsContext *ctx;
         enum AVPixelFormat dfmt, sfmt;

         dfmt = imgfmt2pixfmt(dstFormat);
@@ -655,7 +659,26 @@ struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat,
         if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = AV_PIX_FMT_PAL8;
         sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);

-        return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags, srcFilterParam, dstFilterParam, NULL);
+        ctx = sws_alloc_context();
+        if (!ctx) return NULL;
+        // set it first to allow swsopts to override/add to it
+        av_opt_set_int(ctx, "sws_flags", flags, 0);
+        if (parse_avopts(ctx, sws_opts) < 0) {
+            mp_msg(MSGT_VFILTER, MSGL_ERR, "Your options /%s/ look like gibberish to me pal.\n", sws_opts);
+            return NULL;
+        }
+        // always override these
+        av_opt_set_int(ctx, "srcw", srcW, 0);
+        av_opt_set_int(ctx, "srch", srcH, 0);
+        av_opt_set_int(ctx, "src_format", sfmt, 0);
+        av_opt_set_int(ctx, "dstw", dstW, 0);
+        av_opt_set_int(ctx, "dsth", dstH, 0);
+        av_opt_set_int(ctx, "dst_format", dfmt, 0);
+        if (sws_init_context(ctx, srcFilterParam, dstFilterParam) < 0) {
+            sws_freeContext(ctx);
+            return NULL;
+        }
+        return ctx;
 }

 /// An example of presets usage
diff --git a/libmpcodecs/vf_scale.h b/libmpcodecs/vf_scale.h
index 4de3b48ec..5890b5713 100644
--- a/libmpcodecs/vf_scale.h
+++ b/libmpcodecs/vf_scale.h
@@ -28,6 +28,7 @@ extern float sws_chr_sharpen;
 extern float sws_lum_sharpen;

 extern int sws_flags;
+extern char *sws_opts;

 struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat);

--
2.28.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.