[MPlayer-cvslog] r38201 - in trunk: DOCS/man/en/mplayer.1 av_opts.c cfg-common.h libmpcodecs/vf_scale.c libmpcodecs/vf_scale.h

reimar subversion at mplayerhq.hu
Sun Nov 1 17:07:47 EET 2020


Author: reimar
Date: Sun Nov  1 17:07:47 2020
New Revision: 38201

Log:
vf_scale: add generic libswscale options support.

Allows setting any of the options exposed by libswscale,
in particular for example source and destination colorspace
range.

Modified:
   trunk/av_opts.c
   trunk/cfg-common.h
   trunk/libmpcodecs/vf_scale.c
   trunk/libmpcodecs/vf_scale.h

Changes in other areas also in this revision:
Modified:
   trunk/DOCS/man/en/mplayer.1

Modified: trunk/av_opts.c
==============================================================================
--- trunk/av_opts.c	Sun Nov  1 17:07:45 2020	(r38200)
+++ trunk/av_opts.c	Sun Nov  1 17:07:47 2020	(r38201)
@@ -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);
 

Modified: trunk/cfg-common.h
==============================================================================
--- trunk/cfg-common.h	Sun Nov  1 17:07:45 2020	(r38200)
+++ trunk/cfg-common.h	Sun Nov  1 17:07:47 2020	(r38201)
@@ -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},

Modified: trunk/libmpcodecs/vf_scale.c
==============================================================================
--- trunk/libmpcodecs/vf_scale.c	Sun Nov  1 17:07:45 2020	(r38200)
+++ trunk/libmpcodecs/vf_scale.c	Sun Nov  1 17:07:47 2020	(r38201)
@@ -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, ch
 
 //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_getContextFromCmd
 {
         int flags;
         SwsFilter *dstFilterParam, *srcFilterParam;
+        struct SwsContext *ctx;
         enum AVPixelFormat dfmt, sfmt;
 
         dfmt = imgfmt2pixfmt(dstFormat);
@@ -655,7 +659,26 @@ struct SwsContext *sws_getContextFromCmd
         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

Modified: trunk/libmpcodecs/vf_scale.h
==============================================================================
--- trunk/libmpcodecs/vf_scale.h	Sun Nov  1 17:07:45 2020	(r38200)
+++ trunk/libmpcodecs/vf_scale.h	Sun Nov  1 17:07:47 2020	(r38201)
@@ -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);
 


More information about the MPlayer-cvslog mailing list