[FFmpeg-devel] [PATCH 6/6] MOV: iTunes media type

David Conrad lessen42
Mon Nov 23 05:14:45 CET 2009


---
 libavformat/isom.c   |   34 ++++++++++++++++++++++++++++++++++
 libavformat/isom.h   |    2 ++
 libavformat/mov.c    |   10 ++++++++++
 libavformat/movenc.c |   24 ++++++++++++++++++++++++
 4 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index ae16532..69f9dae 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <strings.h>
 #include "avformat.h"
 #include "riff.h"
 #include "isom.h"
@@ -309,3 +310,36 @@ int ff_mov_lang_to_iso639(unsigned code, char *to)
     strncpy(to, mov_mdhd_language_map[code], 4);
     return 1;
 }
+
+static const struct {
+    int stik;
+    const char *name;
+} mov_stik_names[] = {
+    { 0, "Movie" },
+    { 1, "Normal" },
+    { 2, "Audiobook" },
+    { 5, "Whacked Bookmark" },
+    { 6, "Music Video" },
+    { 9, "Short Film" },
+    { 10, "TV Show" },
+    { 11, "Booklet" },
+    { 14, "Ringtone" },
+};
+
+int ff_mov_stik_name_to_num(char *name)
+{
+    int i;
+    for (i = 0; i < FF_ARRAY_ELEMS(mov_stik_names); i++)
+        if (!strcasecmp(name, mov_stik_names[i].name))
+            return mov_stik_names[i].stik;
+    return -1;
+}
+
+const char* ff_mov_stik_num_to_name(int code)
+{
+    int i;
+    for (i = 0; i < FF_ARRAY_ELEMS(mov_stik_names); i++)
+        if (mov_stik_names[i].stik == code)
+            return mov_stik_names[i].name;
+    return NULL;
+}
diff --git a/libavformat/isom.h b/libavformat/isom.h
index abd5f97..63b8f4e 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -36,6 +36,8 @@ extern const AVCodecTag ff_codec_movsubtitle_tags[];
 
 int ff_mov_iso639_to_lang(const char *lang, int mp4);
 int ff_mov_lang_to_iso639(unsigned code, char *to);
+int ff_mov_stik_name_to_num(char *name);
+const char* ff_mov_stik_num_to_name(int code);
 
 /* the QuickTime file format is quite convoluted...
  * it has lots of index tables, each indexing something in another one...
diff --git a/libavformat/mov.c b/libavformat/mov.c
index dee251d..fe2c444 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -103,6 +103,14 @@ static int mov_metadata_be32(MOVContext *c, ByteIOContext *pb, unsigned len, con
     return 0;
 }
 
+static int mov_metadata_stik(MOVContext *c, ByteIOContext *pb, unsigned len, const char *key)
+{
+    const char *name = ff_mov_stik_num_to_name(get_byte(pb));
+    if (name)
+        av_metadata_set(&c->fc->metadata, key, name);
+    return 0;
+}
+
 static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
 {
 #ifdef MOV_EXPORT_ALL_METADATA
@@ -138,6 +146,8 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
         parse = mov_metadata_be32; break;
     case MKTAG( 't','r','k','n'): key = "track";
         parse = mov_metadata_trkn; break;
+    case MKTAG( 's','t','i','k'): key = "itunes_type";
+        parse = mov_metadata_stik; break;
     }
 
     if (c->itunes_metadata && atom.size > 8) {
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index c2b2154..911b18d 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1384,6 +1384,29 @@ static int mov_write_be32_metadata(AVFormatContext *s, ByteIOContext *pb,
     return size;
 }
 
+static int mov_write_stik_tag(ByteIOContext *pb, MOVMuxContext *mov,
+                              AVFormatContext *s)
+{
+    AVMetadataTag *t = av_metadata_get(s->metadata, "itunes_type", NULL, 0);
+    int size = 0, stik = t ? ff_mov_stik_name_to_num(t->value) : -1;
+    if (stik >= 0) {
+        int64_t pos = url_ftell(pb);
+        put_be32(pb, 0); /* size */
+        put_tag(pb, "stik");
+        {
+            int64_t pos = url_ftell(pb);
+            put_be32(pb, 0); /* size */
+            put_tag(pb, "data");
+            put_be32(pb, 0);        // 8 bytes empty
+            put_be32(pb, 0);
+            put_byte(pb, stik);
+            updateSize(pb, pos);
+        }
+        size = updateSize(pb, pos);
+    }
+    return size;
+}
+
 /* iTunes meta data list */
 static int mov_write_ilst_tag(ByteIOContext *pb, MOVMuxContext *mov,
                               AVFormatContext *s)
@@ -1408,6 +1431,7 @@ static int mov_write_ilst_tag(ByteIOContext *pb, MOVMuxContext *mov,
     mov_write_be32_metadata  (s, pb, "tvsn",    "season");
     mov_write_be32_metadata  (s, pb, "tves",    "episode");
     mov_write_trkn_tag(pb, mov, s);
+    mov_write_stik_tag(pb, mov, s);
     return updateSize(pb, pos);
 }
 
-- 
1.6.4.4




More information about the ffmpeg-devel mailing list