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

j at svn.xiph.org j at svn.xiph.org
Sun Aug 23 03:47:17 PDT 2009


Author: j
Date: 2009-08-23 03:47:16 -0700 (Sun, 23 Aug 2009)
New Revision: 16510

Modified:
   trunk/ffmpeg2theora/src/ffmpeg2theora.c
   trunk/ffmpeg2theora/src/theorautils.c
Log:
fix metadata handling, patch by Anton Novikov



Modified: trunk/ffmpeg2theora/src/ffmpeg2theora.c
===================================================================
--- trunk/ffmpeg2theora/src/ffmpeg2theora.c	2009-08-23 02:25:50 UTC (rev 16509)
+++ trunk/ffmpeg2theora/src/ffmpeg2theora.c	2009-08-23 10:47:16 UTC (rev 16510)
@@ -1914,7 +1914,7 @@
     int output_json = 0;
 
     static int flag = -1;
-    static int metadata_flag = 0;
+    static int metadata_flag = -1;
 
     AVInputFormat *input_fmt = NULL;
     AVFormatParameters params, *formatParams = NULL;
@@ -1980,15 +1980,15 @@
         {"frontend",0,&flag,FRONTEND_FLAG},
         {"frontendfile",required_argument,&flag,FRONTENDFILE_FLAG},
         {"info",no_argument,&flag,INFO_FLAG},
-        {"artist",required_argument,&metadata_flag,10},
-        {"title",required_argument,&metadata_flag,11},
-        {"date",required_argument,&metadata_flag,12},
-        {"location",required_argument,&metadata_flag,13},
-        {"organization",required_argument,&metadata_flag,14},
-        {"copyright",required_argument,&metadata_flag,15},
-        {"license",required_argument,&metadata_flag,16},
-        {"contact",required_argument,&metadata_flag,17},
-        {"source-hash",required_argument,&metadata_flag,18},
+        {"artist",required_argument,&metadata_flag,0},
+        {"title",required_argument,&metadata_flag,1},
+        {"date",required_argument,&metadata_flag,2},
+        {"location",required_argument,&metadata_flag,3},
+        {"organization",required_argument,&metadata_flag,4},
+        {"copyright",required_argument,&metadata_flag,5},
+        {"license",required_argument,&metadata_flag,6},
+        {"contact",required_argument,&metadata_flag,7},
+        {"source-hash",required_argument,&metadata_flag,8},
 
         {"help",0,NULL,'h'},
         {NULL,0,NULL,0}
@@ -2193,37 +2193,21 @@
                 }
 
                 /* metadata */
-                if (metadata_flag) {
-                    switch(metadata_flag) {
-                        case 10:
-                            theora_comment_add_tag(&info.tc, "ARTIST", optarg);
-                            break;
-                        case 11:
-                            theora_comment_add_tag(&info.tc, "TITLE", optarg);
-                            break;
-                        case 12:
-                            theora_comment_add_tag(&info.tc, "DATE", optarg);
-                            break;
-                        case 13:
-                            theora_comment_add_tag(&info.tc, "LOCATION", optarg);
-                            break;
-                        case 14:
-                            theora_comment_add_tag(&info.tc, "ORGANIZATION", optarg);
-                            break;
-                        case 15:
-                            theora_comment_add_tag(&info.tc, "COPYRIGHT", optarg);
-                            break;
-                        case 16:
-                            theora_comment_add_tag(&info.tc, "LICENSE", optarg);
-                            break;
-                        case 17:
-                            theora_comment_add_tag(&info.tc, "CONTACT", optarg);
-                            break;
-                        case 18:
-                            theora_comment_add_tag(&info.tc, "SOURCE HASH", optarg);
-                            break;
-                    }
-                    metadata_flag=0;
+                if (metadata_flag >= 0) {
+                    static char *metadata_keys[] = {
+                        "ARTIST",
+                        "TITLE",
+                        "DATE",
+                        "LOCATION",
+                        "ORGANIZATION",
+                        "COPYRIGHT",
+                        "LICENSE",
+                        "CONTACT",
+                        "SOURCE HASH"
+                    };
+                    th_comment_add_tag(&info.tc, metadata_keys[metadata_flag], optarg);
+                    vorbis_comment_add_tag(&info.vc, metadata_keys[metadata_flag], optarg);
+                    metadata_flag = -1;
                 }
                 break;
             case 'e':

Modified: trunk/ffmpeg2theora/src/theorautils.c
===================================================================
--- trunk/ffmpeg2theora/src/theorautils.c	2009-08-23 02:25:50 UTC (rev 16509)
+++ trunk/ffmpeg2theora/src/theorautils.c	2009-08-23 10:47:16 UTC (rev 16510)
@@ -254,6 +254,13 @@
     srand (time (NULL));
     ogg_stream_init (&info->vo, rand ());
 
+    th_comment_add_tag(&info->tc, "ENCODER", PACKAGE_STRING);
+    vorbis_comment_add_tag(&info->vc, "ENCODER", PACKAGE_STRING);
+    if (strcmp(info->oshash, "0") > 0) {
+        th_comment_add_tag(&info->tc, "SOURCE_OSHASH", info->oshash);
+        vorbis_comment_add_tag(&info->vc, "SOURCE_OSHASH", info->oshash);
+    }
+
     if (!info->audio_only) {
         ogg_stream_init (&info->to, rand ());    /* oops, add one ot the above */
     }
@@ -275,11 +282,6 @@
             exit (1);
         }
 
-        vorbis_comment_init (&info->vc);
-        vorbis_comment_add_tag (&info->vc, "ENCODER",PACKAGE_STRING);
-        if (strcmp(info->oshash,"0000000000000000") > 0) {
-            vorbis_comment_add_tag (&info->vc, "SOURCE_OSHASH", info->oshash);
-        }
         /* set up the analysis state and auxiliary encoding storage */
         vorbis_analysis_init (&info->vd, &info->vi);
         vorbis_block_init (&info->vd, &info->vb);
@@ -328,13 +330,6 @@
     /* first packet will get its own page automatically */
     if (!info->audio_only) {
         /* write the bitstream header packets with proper page interleave */
-        th_comment_init(&info->tc);
-        th_comment_add_tag(&info->tc, "ENCODER",PACKAGE_STRING);
-        if (strcmp(info->oshash,"0") > 0) {
-            th_comment_add_tag(&info->tc, "SOURCE_OSHASH", info->oshash);
-        }
-
-        /* write the bitstream header packets with proper page interleave */
         /* first packet will get its own page automatically */
         if(th_encode_flushheader(info->td, &info->tc, &op) <= 0) {
           fprintf(stderr, "Internal Theora library error.\n");



More information about the commits mailing list