[xiph-commits] r16511 - trunk/ffmpeg2theora/src

j at svn.xiph.org j at svn.xiph.org
Sun Aug 23 03:55:51 PDT 2009


Author: j
Date: 2009-08-23 03:55:51 -0700 (Sun, 23 Aug 2009)
New Revision: 16511

Modified:
   trunk/ffmpeg2theora/src/ffmpeg2theora.c
   trunk/ffmpeg2theora/src/ffmpeg2theora.h
Log:
read metadata from the input file.
metadata specified with --artist etc overrides it.
also added --nometadata to not read metadata from input file
patch by Anton Novikov


Modified: trunk/ffmpeg2theora/src/ffmpeg2theora.c
===================================================================
--- trunk/ffmpeg2theora/src/ffmpeg2theora.c	2009-08-23 10:47:16 UTC (rev 16510)
+++ trunk/ffmpeg2theora/src/ffmpeg2theora.c	2009-08-23 10:55:51 UTC (rev 16511)
@@ -49,6 +49,8 @@
 #include "ffmpeg2theora.h"
 #include "avinfo.h"
 
+#define LENGTH(x) (sizeof(x) / sizeof(*x))
+
 enum {
     NULL_FLAG,
     DEINTERLACE_FLAG,
@@ -61,6 +63,7 @@
     NOAUDIO_FLAG,
     NOVIDEO_FLAG,
     NOSUBTITLES_FLAG,
+    NOMETADATA_FLAG,
     NOUPSCALING_FLAG,
     CROPTOP_FLAG,
     CROPBOTTOM_FLAG,
@@ -162,6 +165,7 @@
         this->disable_audio=0;
         this->disable_video=0;
         this->disable_subtitles=0;
+        this->disable_metadata=0;
         this->no_upscaling=0;
         this->video_index = -1;
         this->audio_index = -1;
@@ -1713,8 +1717,50 @@
     return crop_value;
 }
 
+void copy_metadata(const AVFormatContext *av)
+{
+    static const char *allowed[] = {
+        "TITLE",
+        "VERSION",
+        "ALBUM",
+        "TRACKNUMBER",
+        "ARTIST",
+        "PERFORMER",
+        "COPYRIGHT",
+        "LICENSE",
+        "ORGANIZATION",
+        "DESCRIPTION",
+        "GENRE",
+        "DATE",
+        "LOCATION",
+        "CONTACT",
+        "ISRC",
 
+        "AUTHOR"
+    };
+    AVMetadataTag *tag = NULL;
+    while ((tag = av_metadata_get(av->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) {
+        char uc_key[16];
+        int i;
+        for (i = 0; tag->key[i] != '\0' && i < LENGTH(uc_key) - 1; i++)
+            uc_key[i] = toupper(tag->key[i]);
+        uc_key[i] = '\0';
 
+        for (i = 0; i < LENGTH(allowed); i++)
+            if (!strcmp(uc_key, allowed[i]))
+                break;
+        if (i != LENGTH(allowed)) {
+            if (!strcmp(uc_key, "AUTHOR"))
+                strcpy(uc_key, "ARTIST");
+            if (th_comment_query(&info.tc, uc_key, 0) == NULL) {
+                th_comment_add_tag(&info.tc, uc_key, tag->value);
+                vorbis_comment_add_tag(&info.vc, uc_key, tag->value);
+            }
+        }
+    }
+}
+
+
 void print_presets_info() {
     fprintf(stdout,
         //  "v2v presets - more info at http://wiki.v2v.cc/presets"
@@ -1786,7 +1832,7 @@
         "                         the cost is quality and bandwidth\n"
         "                         - 0: Slowest (best)\n"
         "                         - 1: Enable early skip (default)\n"
-	"                         - 2: Disable motion compensation\n"
+    "                         - 2: Disable motion compensation\n"
 
         "  -x, --width            scale to given width (in pixels)\n"
         "  -y, --height           scale to given height (in pixels)\n"
@@ -1869,6 +1915,7 @@
         "      --copyright        Copyright\n"
         "      --license          License\n"
         "      --contact          Contact link\n"
+        "      --nometadata       disables metadata from input\n"
         "\n"
         "Other options:\n"
 #ifndef _WIN32
@@ -1952,6 +1999,7 @@
         {"noaudio",0,&flag,NOAUDIO_FLAG},
         {"novideo",0,&flag,NOVIDEO_FLAG},
         {"nosubtitles",0,&flag,NOSUBTITLES_FLAG},
+        {"nometadata",0,&flag,NOMETADATA_FLAG},
         {"no-upscaling",0,&flag,NOUPSCALING_FLAG},
 #ifdef HAVE_FRAMEHOOK
         {"vhook",required_argument,&flag,VHOOK_FLAG},
@@ -2081,6 +2129,10 @@
                             convert->disable_subtitles = 1;
                             flag = -1;
                             break;
+                        case NOMETADATA_FLAG:
+                            convert->disable_metadata = 1;
+                            flag = -1;
+                            break;
                         case NOUPSCALING_FLAG:
                             convert->no_upscaling = 1;
                             flag = -1;
@@ -2513,6 +2565,12 @@
                 if (convert->disable_subtitles) {
                     fprintf(stderr, "  [subtitles disabled].\n");
                 }
+                if (convert->disable_metadata) {
+                    fprintf(stderr, "  [metadata disabled].\n");
+                } else {
+                    copy_metadata(convert->context);
+                }
+
                 if (convert->sync) {
                     fprintf(stderr, "  Use A/V Sync from input container.\n");
                 }

Modified: trunk/ffmpeg2theora/src/ffmpeg2theora.h
===================================================================
--- trunk/ffmpeg2theora/src/ffmpeg2theora.h	2009-08-23 10:47:16 UTC (rev 16510)
+++ trunk/ffmpeg2theora/src/ffmpeg2theora.h	2009-08-23 10:55:51 UTC (rev 16511)
@@ -47,6 +47,7 @@
     int preset;
 
     int disable_subtitles;
+    int disable_metadata;
 
     int videostream;
     int picture_width;



More information about the commits mailing list