summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2019-09-30 12:13:46 +0200
committerPaul B Mahol <onemda@gmail.com>2019-09-30 12:14:34 +0200
commit9c9d5bf257df6bbdf50da469706e326a79de2ae8 (patch)
tree2d8ab5ff4acccad3d242c96baa78b5041bc40241
parent6ca3d34ff8490fb1efa0cc3dc06b6bbb58151c53 (diff)
avfilter/f_metadata: add ends_with() function for comparing ends of strings
-rw-r--r--doc/filters.texi4
-rw-r--r--libavfilter/f_metadata.c13
2 files changed, 17 insertions, 0 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index 333f502083..e7927f07c0 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -21856,6 +21856,10 @@ Values are interpreted as floats, returns true if metadata value is greater than
@item expr
Values are interpreted as floats, returns true if expression from option @code{expr}
evaluates to true.
+
+@item ends_with
+Values are interpreted as strings, returns true if metadata value ends with
+the @code{value} option string.
@end table
@item expr
diff --git a/libavfilter/f_metadata.c b/libavfilter/f_metadata.c
index 523a94d38c..97e5c669fe 100644
--- a/libavfilter/f_metadata.c
+++ b/libavfilter/f_metadata.c
@@ -54,6 +54,7 @@ enum MetadataFunction {
METADATAF_EQUAL,
METADATAF_GREATER,
METADATAF_EXPR,
+ METADATAF_ENDS_WITH,
METADATAF_NB
};
@@ -107,6 +108,7 @@ static const AVOption filt_name##_options[] = { \
{ "equal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EQUAL }, 0, 3, FLAGS, "function" }, \
{ "greater", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_GREATER }, 0, 3, FLAGS, "function" }, \
{ "expr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EXPR }, 0, 3, FLAGS, "function" }, \
+ { "ends_with", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_ENDS_WITH }, 0, 0, FLAGS, "function" }, \
{ "expr", "set expression for expr function", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \
{ "file", "set file where to print metadata information", OFFSET(file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, \
{ NULL } \
@@ -122,6 +124,14 @@ static int starts_with(MetadataContext *s, const char *value1, const char *value
return !strncmp(value1, value2, strlen(value2));
}
+static int ends_with(MetadataContext *s, const char *value1, const char *value2)
+{
+ const int len1 = strlen(value1);
+ const int len2 = strlen(value2);
+
+ return !strncmp(value1 + FFMAX(len1 - len2, 0), value2, len2);
+}
+
static int equal(MetadataContext *s, const char *value1, const char *value2)
{
float f1, f2;
@@ -212,6 +222,9 @@ static av_cold int init(AVFilterContext *ctx)
case METADATAF_STARTS_WITH:
s->compare = starts_with;
break;
+ case METADATAF_ENDS_WITH:
+ s->compare = ends_with;
+ break;
case METADATAF_LESS:
s->compare = less;
break;