]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/f_metadata.c
avformat: Remove getters and setters
[ffmpeg] / libavfilter / f_metadata.c
index 97e5c669fee46e8db19441056156d310c68309f9..598257b15b8714c999c992ae4f2216010457c129 100644 (file)
@@ -88,6 +88,8 @@ typedef struct MetadataContext {
     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)
@@ -111,6 +113,7 @@ static const AVOption filt_name##_options[] = { \
     {   "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 } \
 }
 
@@ -274,6 +277,9 @@ static av_cold int init(AVFilterContext *ctx)
                    s->file_str, buf);
             return ret;
         }
+
+        if (s->direct)
+            s->avio_context->direct = AVIO_FLAG_DIRECT;
     }
 
     return 0;
@@ -283,6 +289,8 @@ static av_cold void uninit(AVFilterContext *ctx)
 {
     MetadataContext *s = ctx->priv;
 
+    av_expr_free(s->expr);
+    s->expr = NULL;
     if (s->avio_context) {
         avio_closep(&s->avio_context);
     }
@@ -296,7 +304,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     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,
@@ -318,13 +326,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             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",
@@ -339,7 +345,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             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);
@@ -347,7 +352,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             av_dict_set(metadata, s->key, NULL, 0);
         }
         return ff_filter_frame(outlink, frame);
-        break;
     default:
         av_assert0(0);
     };