[FFmpeg-devel] [PATCH 1/2] lavc: add av_get_profile_name() to get profile names

Anssi Hannula anssi.hannula
Fri Jan 7 18:31:28 CET 2011


Michael wrote:
> Maybe we should add such tables to a new AVCodec.profiles ?

Seems reasonable. Like this?

I'm a bit unsure of the contents of the structure, though. What if an
application wants an "id" style name (i.e. underscores instead of
spaces, all lowercase, like our decoder names) for the profile?
Should we add something like that instead?
(the colorspace and codec as outputted by e.g. avcodec_string() are
already "id"-style instead of being more human-readable)

Adding both would seem a bit overkill, I think.

If we go with the "id" style names ("baseline", "dts_hd_ma" instead of
"Baseline", "DTS-HD MA"), we can add a longer human-readable name later
if the need arises ("Low Complexity" for AAC-LC, "DTS-HD Master Audio",
etc.).

Also, should we already provide AVProfile *av_get_profile() instead of
av_get_profile_name(), or only at a later time if other members are
actually added there?

---
 doc/APIchanges       |    3 +++
 libavcodec/avcodec.h |   22 ++++++++++++++++++++--
 libavcodec/utils.c   |   13 +++++++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index bf9d11d..f1722c7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:   2009-03-08
 
 API changes, most recent first:
 
+2011-01-XX - r26XXX - lavc 52.104.0 - av_get_profile_name()
+  Add av_get_profile_name to libavcodec/avcodec.h.
+
 2010-12-27 - r26108 - lavfi 1.71.0 - AV_PERM_NEG_LINESIZES
   Add AV_PERM_NEG_LINESIZES in avfilter.h.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7850e1d..e723f2d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -32,8 +32,8 @@
 #include "libavutil/cpu.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 103
-#define LIBAVCODEC_VERSION_MICRO  1
+#define LIBAVCODEC_VERSION_MINOR 104
+#define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
@@ -2794,6 +2794,14 @@ typedef struct AVCodecContext {
 } AVCodecContext;
 
 /**
+ * AVProfile.
+ */
+typedef struct AVProfile {
+    int profile;
+    const char *name; ///< short name for the profile
+} AVProfile;
+
+/**
  * AVCodec.
  */
 typedef struct AVCodec {
@@ -2834,6 +2842,7 @@ typedef struct AVCodec {
     const int64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
     uint8_t max_lowres;                     ///< maximum value for lowres supported by the decoder
     AVClass *priv_class;                    ///< AVClass for the private context
+    const AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
 } AVCodec;
 
 /**
@@ -3394,6 +3403,15 @@ AVCodec *avcodec_find_decoder_by_name(const char *name);
 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
 
 /**
+ * Return a name for the specified profile, if available.
+ *
+ * @param codec the codec that is searched for the given profile
+ * @param profile the profile value for which a name is requested
+ * @return A name for the profile if found, NULL otherwise.
+ */
+const char *av_get_profile_name(AVCodec *codec, int profile);
+
+/**
  * Set the fields of the given AVCodecContext to default values.
  *
  * @param s The AVCodecContext of which the fields should be set to default values.
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ce74735..b7e4404 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -966,6 +966,19 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
     }
 }
 
+const char *av_get_profile_name(AVCodec *codec, int profile)
+{
+    const AVProfile *p;
+    if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
+        return NULL;
+
+    for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
+        if (p->profile == profile)
+            return p->name;
+
+    return NULL;
+}
+
 unsigned avcodec_version( void )
 {
   return LIBAVCODEC_VERSION_INT;
-- 
1.7.3




More information about the ffmpeg-devel mailing list