METADATAF_EQUAL,
METADATAF_GREATER,
METADATAF_EXPR,
+ METADATAF_ENDS_WITH,
METADATAF_NB
};
int (*compare)(struct MetadataContext *s,
const char *value1, const char *value2);
void (*print)(AVFilterContext *ctx, const char *msg, ...) av_printf_format(2, 3);
+
+ int direct; // reduces buffering when printing to user-supplied URL
} MetadataContext;
#define OFFSET(x) offsetof(MetadataContext, x)
{ "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 }, \
+ { "direct", "reduce buffering when printing to user-set file or pipe", OFFSET(direct), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, \
{ NULL } \
}
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;
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;
s->file_str, buf);
return ret;
}
+
+ if (s->direct)
+ s->avio_context->direct = AVIO_FLAG_DIRECT;
}
return 0;
{
MetadataContext *s = ctx->priv;
+ av_expr_free(s->expr);
+ s->expr = NULL;
if (s->avio_context) {
avio_closep(&s->avio_context);
}
AVDictionary **metadata = &frame->metadata;
AVDictionaryEntry *e;
- if (!*metadata)
+ if (!*metadata && s->mode != METADATA_ADD)
return ff_filter_frame(outlink, frame);
e = av_dict_get(*metadata, !s->key ? "" : s->key, NULL,
av_dict_set(metadata, s->key, s->value, 0);
}
return ff_filter_frame(outlink, frame);
- break;
case METADATA_MODIFY:
if (e && e->value) {
av_dict_set(metadata, s->key, s->value, 0);
}
return ff_filter_frame(outlink, frame);
- break;
case METADATA_PRINT:
if (!s->key && e) {
s->print(ctx, "frame:%-4"PRId64" pts:%-7s pts_time:%s\n",
s->print(ctx, "%s=%s\n", s->key, e->value);
}
return ff_filter_frame(outlink, frame);
- break;
case METADATA_DELETE:
if (!s->key) {
av_dict_free(metadata);
av_dict_set(metadata, s->key, NULL, 0);
}
return ff_filter_frame(outlink, frame);
- break;
default:
av_assert0(0);
};
{ NULL }
};
-AVFilter ff_af_ametadata = {
+const AVFilter ff_af_ametadata = {
.name = "ametadata",
.description = NULL_IF_CONFIG_SMALL("Manipulate audio frame metadata."),
.priv_size = sizeof(MetadataContext),
{ NULL }
};
-AVFilter ff_vf_metadata = {
+const AVFilter ff_vf_metadata = {
.name = "metadata",
.description = NULL_IF_CONFIG_SMALL("Manipulate video frame metadata."),
.priv_size = sizeof(MetadataContext),