[FFmpeg-devel] [PATCH] lavu/opt: support NULL and special "none" values for size and pixel format options

Stefano Sabatini stefasab at gmail.com
Thu Aug 9 23:01:36 CEST 2012


Allow to specify NULL values explicitly, thus overriding the values set
in the context.
---
 libavutil/opt.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 35a91d7..73540ad 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -235,7 +235,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
     const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
     if (!o || !target_obj)
         return AVERROR_OPTION_NOT_FOUND;
-    if (!val && o->type != AV_OPT_TYPE_STRING)
+    if (!val && (o->type != AV_OPT_TYPE_STRING && o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_IMAGE_SIZE))
         return AVERROR(EINVAL);
 
     dst = ((uint8_t*)target_obj) + o->offset;
@@ -249,11 +249,18 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
     case AV_OPT_TYPE_DOUBLE:
     case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, o, val, dst);
     case AV_OPT_TYPE_IMAGE_SIZE:
+        if (!val || !strcmp(val, "none")) {
+            *(int *)dst = *((int *)dst + 1) = 0;
+            return 0;
+        }
         ret = av_parse_video_size(dst, ((int *)dst) + 1, val);
         if (ret < 0)
             av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val);
         return ret;
     case AV_OPT_TYPE_PIXEL_FMT:
+        if (!val || !strcmp(val, "none"))
+            ret = PIX_FMT_NONE;
+        else {
         ret = av_get_pix_fmt(val);
         if (ret == PIX_FMT_NONE) {
             char *tail;
@@ -263,6 +270,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
                 return AVERROR(EINVAL);
             }
         }
+        }
         *(enum PixelFormat *)dst = ret;
         return 0;
     }
@@ -451,7 +459,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
         ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
         break;
     case AV_OPT_TYPE_PIXEL_FMT:
-        ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum PixelFormat *)dst), "?"));
+        ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum PixelFormat *)dst), "none"));
         break;
     default:
         return AVERROR(EINVAL);
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list