[FFmpeg-devel] [PATCH 1/6] avformat/format: add av_demuxer_find_by_ext

Gyan Doshi ffmpeg at gyani.pro
Fri Jan 31 16:26:03 EET 2020


Allows selecting demuxer by extension which are more widely recognized
by users.

Conditional cast added since this function will usually be called after
av_find_input_format, and so matches its return type.
---
 libavformat/avformat.h |  5 +++++
 libavformat/format.c   | 15 +++++++++++++++
 libavformat/version.h  |  2 +-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 9b9b634ec3..9172ddbc8a 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2237,6 +2237,11 @@ int avformat_alloc_output_context2(AVFormatContext **ctx, ff_const59 AVOutputFor
  */
 ff_const59 AVInputFormat *av_find_input_format(const char *short_name);
 
+/**
+ * Find AVInputFormat based on an extension.
+ */
+const AVInputFormat *av_demuxer_find_by_ext(const char *extension);
+
 /**
  * Guess the file format.
  *
diff --git a/libavformat/format.c b/libavformat/format.c
index c47490c8eb..9dda6df676 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -125,6 +125,21 @@ ff_const59 AVInputFormat *av_find_input_format(const char *short_name)
     return NULL;
 }
 
+const AVInputFormat *av_demuxer_find_by_ext(const char *extension)
+{
+    const AVInputFormat *fmt = NULL;
+    void *i = 0;
+    while ((fmt = av_demuxer_iterate(&i)))
+        if (fmt->extensions && av_match_name(extension, fmt->extensions))
+#if FF_API_AVIOFORMAT
+            return (AVInputFormat*)fmt;
+#else
+            return fmt;
+#endif
+
+    return NULL;
+}
+
 ff_const59 AVInputFormat *av_probe_input_format3(ff_const59 AVProbeData *pd, int is_opened,
                                       int *score_ret)
 {
diff --git a/libavformat/version.h b/libavformat/version.h
index 15fdb73e3e..be22abc010 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR  37
+#define LIBAVFORMAT_VERSION_MINOR  38
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.24.1



More information about the ffmpeg-devel mailing list