[FFmpeg-devel] [PATCH]Accept 0 as codec_tag in ffmpeg.c if it matches the codec_id, v2

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Jan 17 20:06:51 CET 2013


Hi!

Two patches are attached: The first adds a new function av_codec_get_tag2() 
that does not fail for codecs that have codec_tag == 0, the second fixes 
ticket #1953.

Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index c907d4e..8330c6b 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1930,6 +1930,18 @@ enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned i
  */
 unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
 
+/**
+ * Get the codec tag for the given codec id.
+ *
+ * @param tags list of supported codec_id - codec_tag pairs, as stored
+ * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
+ * @param id codec id that should be searched for in the list
+ * @param tag A pointer to the found tag
+ * @return 0 if id was not found in tags, > 0 if it was found
+ */
+int av_codec_get_tag2(const struct AVCodecTag * const *tags, enum AVCodecID id,
+                      unsigned int *tag);
+
 int av_find_default_stream_index(AVFormatContext *s);
 
 /**
diff --git a/libavformat/utils.c b/libavformat/utils.c
index d43e1c0..576713a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2584,10 +2584,25 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
 
 unsigned int av_codec_get_tag(const AVCodecTag * const *tags, enum AVCodecID id)
 {
+    unsigned int tag;
+    if (!av_codec_get_tag2(tags, id, &tag))
+        return 0;
+    return tag;
+}
+
+int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id,
+                      unsigned int *tag)
+{
     int i;
     for(i=0; tags && tags[i]; i++){
-        int tag= ff_codec_get_tag(tags[i], id);
-        if(tag) return tag;
+        const AVCodecTag *codec_tags = tags[i];
+        while (codec_tags->id != AV_CODEC_ID_NONE) {
+            if (codec_tags->id == id) {
+                *tag = codec_tags->tag;
+                return 1;
+            }
+            codec_tags++;
+        }
     }
     return 0;
 }
diff --git a/libavformat/version.h b/libavformat/version.h
index cffc4bf..5262948 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,8 +30,8 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 60
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR 61
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
-------------- next part --------------
diff --git a/ffmpeg.c b/ffmpeg.c
index acaa523..abfe439 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2046,9 +2046,10 @@ static int transcode_init(void)
             codec->codec_type = icodec->codec_type;
 
             if (!codec->codec_tag) {
+                unsigned int codec_tag;
                 if (!oc->oformat->codec_tag ||
                      av_codec_get_id (oc->oformat->codec_tag, icodec->codec_tag) == codec->codec_id ||
-                     av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0)
+                     !av_codec_get_tag2(oc->oformat->codec_tag, icodec->codec_id, &codec_tag))
                     codec->codec_tag = icodec->codec_tag;
             }
 


More information about the ffmpeg-devel mailing list