[FFmpeg-cvslog] avformat: Do not search through the AVOption table for a option not in it repeatedly on each packet

Michael Niedermayer git at videolan.org
Sun Mar 27 17:13:49 EEST 2022


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Fri Mar 25 23:51:29 2022 +0100| [6265f0b4e1978485b8147ce7dbd5bc7533e7a298] | committer: Michael Niedermayer

avformat: Do not search through the AVOption table for a option not in it repeatedly on each packet

This search takes alot of time especially when compared with small packets

46631 decicycles -> 15719 decicycles in read_frame_internal() for amr-nb in 3gp

Reviewed-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6265f0b4e1978485b8147ce7dbd5bc7533e7a298
---

 libavformat/demux.c    | 15 +++++++++------
 libavformat/internal.h |  5 +++++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index ac1f16edcd..ef189d9d8e 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1407,12 +1407,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 
-    av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata);
-    if (metadata) {
-        s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
-        av_dict_copy(&s->metadata, metadata, 0);
-        av_dict_free(&metadata);
-        av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN);
+    if (!si->metafree) {
+        int metaret = av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata);
+        if (metadata) {
+            s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
+            av_dict_copy(&s->metadata, metadata, 0);
+            av_dict_free(&metadata);
+            av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN);
+        }
+        si->metafree = metaret == AVERROR_OPTION_NOT_FOUND;
     }
 
     if (s->debug & FF_FDEBUG_TS)
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 342e6f7327..3ad76d992c 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -183,6 +183,11 @@ typedef struct FFFormatContext {
      * Set if chapter ids are strictly monotonic.
      */
     int chapter_ids_monotonic;
+
+    /**
+     * Contexts and child contexts do not contain a metadata option
+     */
+    int metafree;
 } FFFormatContext;
 
 static av_always_inline FFFormatContext *ffformatcontext(AVFormatContext *s)



More information about the ffmpeg-cvslog mailing list