[FFmpeg-cvslog] lavc: add a table of all codecs names.

Nicolas George git at videolan.org
Mon Aug 22 12:21:01 CEST 2011


ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Wed Aug 17 13:54:49 2011 +0200| [b3be9f4a88787d2d6692ffced187db677afdc726] | committer: Nicolas George

lavc: add a table of all codecs names.

The table is automatically generated from the definition of enum CodecID in
avcodec.h and contains the name of all known codecs, even those for which no
encoder nor decoder exists or is enabled.

The table is queried using the avcodec_get_name function.

If CONFIG_SMALL is true, the table is not compiled in; the avcodec_get_name
looks for names in the list of available decoders and encoders.

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

 .gitignore                |    1 +
 libavcodec/Makefile       |    6 +++
 libavcodec/avcodec.h      |    6 +++
 libavcodec/codec_names.sh |   85 +++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/utils.c        |   19 ++++++++++
 5 files changed, 117 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index 958dd71..e7585e3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ avconv
 libavcodec/*_tablegen
 libavcodec/*_tables.c
 libavcodec/*_tables.h
+libavcodec/codec_names.h
 libavcodec/libavcodec*
 libavcore/libavcore*
 libavdevice/libavdevice*
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 147c1b3..ac47c99 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -735,3 +735,9 @@ $(SUBDIR)motionpixels.o: $(SUBDIR)motionpixels_tables.h
 $(SUBDIR)pcm.o: $(SUBDIR)pcm_tables.h
 $(SUBDIR)qdm2.o: $(SUBDIR)qdm2_tables.h
 endif
+
+CODEC_NAMES_SH := $(SRC_PATH)/$(SUBDIR)codec_names.sh
+AVCODEC_H      := $(SRC_PATH)/$(SUBDIR)avcodec.h
+$(SUBDIR)codec_names.h: $(CODEC_NAMES_SH) config.h $(AVCODEC_H)
+	$(M)$(CODEC_NAMES_SH) config.h $(AVCODEC_H) $@
+$(SUBDIR)utils.o: $(SUBDIR)codec_names.h
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2617f65..2c5e70b 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3433,6 +3433,12 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width,
 int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height);
 void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift);
 
+/**
+ * Get the name of a codec.
+ * @return  a static string identifying the codec; never NULL
+ */
+const char *avcodec_get_name(enum CodecID id);
+
 #if FF_API_GET_PIX_FMT_NAME
 /**
  * Return the short name for a pixel format.
diff --git a/libavcodec/codec_names.sh b/libavcodec/codec_names.sh
new file mode 100755
index 0000000..4d86c19
--- /dev/null
+++ b/libavcodec/codec_names.sh
@@ -0,0 +1,85 @@
+#!/bin/sh
+
+# Copyright (c) 2011 Nicolas George
+#
+# This file is part of FFmpeg.
+#
+# FFmpeg is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# FFmpeg is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with FFmpeg; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+set -e
+
+config="$1"
+codecs="$2"
+out="$3"
+test -n "$out"
+
+outval=""
+
+add_line () {
+  outval="$outval$*
+"
+}
+
+parse_config_h () {
+  while read define var value; do
+    case "$define $var $value" in
+      "#define CONFIG_"*_*" 1") eval "$var=1";;
+    esac
+  done
+}
+
+define_codecid () {
+  id="$1"
+  n=${1#CODEC_ID_}
+  add_line "case ${id}:"
+  eval "c=\${CONFIG_${n}_DECODER}:\${CONFIG_${n}_ENCODER}"
+  case "$c" in
+    1:*) s="decoder";;
+    *:1) s="encoder";;
+    *) s="";;
+  esac
+  case "$s" in
+    "") add_line "    return \"$n\";" ;;
+    *)
+      add_line "    { extern AVCodec ff_${n}_${s};"
+      add_line "      return ff_${n}_${s}.name; }"
+      ;;
+  esac
+}
+
+parse_enum_codecid () {
+  while read line; do
+    case "$line" in
+      "};") break;;
+      *CODEC_ID_FIRST*///*dummy*) ;;
+      CODEC_ID_*) define_codecid ${line%%[=,]*};;
+    esac
+  done
+}
+
+parse_avcodec_h () {
+  while read line; do
+    case "$line" in
+      "enum CodecID {") parse_enum_codecid; break;;
+    esac
+  done
+}
+
+parse_config_h  < "$config"
+parse_avcodec_h < "$codecs"
+sed -e '/case.*:/ ! y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \
+    -e 's/extern avcodec /extern AVCodec /' > "$out" <<EOF
+$outval
+EOF
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ce8c099..1d5ec44 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -984,6 +984,25 @@ static int get_bit_rate(AVCodecContext *ctx)
     return bit_rate;
 }
 
+const char *avcodec_get_name(enum CodecID id)
+{
+    AVCodec *codec;
+
+#if !CONFIG_SMALL
+    switch (id) {
+#include "libavcodec/codec_names.h"
+    }
+    av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
+#endif
+    codec = avcodec_find_decoder(id);
+    if (codec)
+        return codec->name;
+    codec = avcodec_find_encoder(id);
+    if (codec)
+        return codec->name;
+    return "unknown_codec";
+}
+
 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
 {
     int i, len, ret = 0;



More information about the ffmpeg-cvslog mailing list