shithub: aacenc

Download patch

ref: 3ba2093c9e8dedeed94155a98e343781d2f85816
parent: 17a2abfb64d5da78999672a9ba9b9e08e19f978e
author: knik <knik@users.sourceforge.net>
date: Mon Jul 24 10:35:38 EDT 2017

--genre --track --disc options fix

--- a/frontend/main.c
+++ b/frontend/main.c
@@ -111,11 +111,11 @@
     "  --artist X\tSet artist to X\n"
     "  --composer X\tSet composer to X\n"
     "  --title X\tSet title to X\n"
-    "  --genre X\tSet genre to X\n"
+    "  --genre X\tSet genre number to X\n"
     "  --album X\tSet album to X\n"
     "  --compilation\tSet compilation\n"
-    "  --track X\tSet track number to X\n"
-    "  --disc X\tSet disc number to X\n"
+    "  --track X\tSet track to X (number/total)\n"
+    "  --disc X\tSet disc to X (number/total)\n"
     "  --year X\tSet year to X\n"
     "  --cover-art X\tRead cover art from file X\n"
     "  --comment X\tSet comment to X\n"
@@ -174,11 +174,11 @@
     "  --artist X\tSet artist to X\n"
     "  --composer X\tSet composer to X\n"
     "  --title X\tSet title/track name to X\n"
-    "  --genre X\tSet genre to X\n"
+    "  --genre X\tSet genre number to X\n"
     "  --album X\tSet album/performer to X\n"
     "  --compilation\tMark as compilation\n"
-    "  --track X\tSet track number to X\n"
-    "  --disc X\tSet disc number to X\n"
+    "  --track X\tSet track to X (number/total)\n"
+    "  --disc X\tSet disc to X (number/total)\n"
     "  --year X\tSet year to X\n"
     "  --cover-art X\tRead cover art from file X\n"
     "\t\tSupported image formats are GIF, JPEG, and PNG.\n"
@@ -423,11 +423,12 @@
 
     FILE *outfile = NULL;
 
-    unsigned int trackno = 0;
-    unsigned int discno = 0;
+    unsigned int ntracks = 0, trackno = 0;
+    unsigned int ndiscs = 0, discno = 0;
     uint8_t compilation = 0;
     const char *artist = NULL, *title = NULL, *album = NULL, *year = NULL,
-        *genre = NULL, *comment = NULL, *composer = NULL;
+        *comment = NULL, *composer = NULL;
+    int genre = 0;
     uint8_t *artData = NULL;
     uint64_t artSize = 0;
     uint64_t encoded_samples = 0;
@@ -599,16 +600,16 @@
             album = optarg;
             break;
         case TRACK_FLAG:
-            trackno = atoi(optarg);
+            sscanf(optarg, "%d/%d", &trackno, &ntracks);
             break;
         case DISC_FLAG:
-            discno = atoi(optarg);
+            sscanf(optarg, "%d/%d", &discno, &ndiscs);
             break;
         case COMPILATION_FLAG:
             compilation = 0x1;
             break;
         case GENRE_FLAG:
-            genre = optarg;
+            genre = atoi(optarg) + 1;
             break;
         case YEAR_FLAG:
             year = optarg;
@@ -810,9 +811,9 @@
         return 1;
     }
 
-    if (container != MP4_CONTAINER && (trackno || artist ||
+    if (container != MP4_CONTAINER && (ntracks || trackno || artist ||
                                        title || album || year || artData ||
-                                       genre || comment || discno ||
+                                       genre || comment || discno || ndiscs ||
                                        composer || compilation))
     {
         fprintf(stderr, "Metadata requires MP4 output!\n");
@@ -1130,7 +1131,9 @@
         SETTAG(title);
         SETTAG(album);
         SETTAG(trackno);
+        SETTAG(ntracks);
         SETTAG(discno);
+        SETTAG(ndiscs);
         SETTAG(compilation);
         SETTAG(year);
         SETTAG(genre);
--- a/frontend/mp4write.c
+++ b/frontend/mp4write.c
@@ -527,9 +527,9 @@
     return size;
 }
 
-static int tagu32(char *tagname, int n /*number of stored fields*/)
+static int tagu16(char *tagname, int n /*number of stored fields*/)
 {
-    int numsize = n * 4;
+    int numsize = n * 2;
     int size = 0;
     int datasize = numsize + 16;
 
@@ -537,7 +537,7 @@
     size += dataout(tagname, 4);
     size += u32out(datasize);
     size += dataout("data", 4);
-    size += u32out(0); // data type uint32
+    size += u32out(0); // data type uint16
     size += u32out(0);
 
     return size;
@@ -601,25 +601,32 @@
     if (mp4config.tag.title)
         size += tagtxt("\xa9" "nam", mp4config.tag.title);
     if (mp4config.tag.genre)
-        size += tagtxt("gnre", mp4config.tag.genre);
+    {
+        size += tagu16("gnre", 1);
+        size += u16out(mp4config.tag.genre);
+    }
     if (mp4config.tag.album)
         size += tagtxt("\xa9" "alb", mp4config.tag.album);
     if (mp4config.tag.compilation)
     {
-        size += tagu32("cpil", 1);
-        size += u32out(mp4config.tag.compilation);
+        size += tagu16("cpil", 1);
+        size += u16out(mp4config.tag.compilation);
     }
     if (mp4config.tag.trackno)
     {
-        size += tagu32("trkn", 2);
-        size += u32out(mp4config.tag.trackno);
-        size += u32out(0);
+        size += tagu16("trkn", 4);
+        size += u16out(0);
+        size += u16out(mp4config.tag.trackno);
+        size += u16out(mp4config.tag.ntracks);
+        size += u16out(0);
     }
     if (mp4config.tag.discno)
     {
-        size += tagu32("disk", 2);
-        size += u32out(mp4config.tag.discno);
-        size += u32out(0);
+        size += tagu16("disk", 4);
+        size += u16out(0);
+        size += u16out(mp4config.tag.discno);
+        size += u16out(mp4config.tag.ndiscs);
+        size += u16out(0);
     }
     if (mp4config.tag.year)
         size += tagtxt("\xa9" "day", mp4config.tag.year);
--- a/frontend/mp4write.h
+++ b/frontend/mp4write.h
@@ -54,11 +54,13 @@
         const char *artist;
         const char *composer;
         const char *title;
-        const char *genre;
         const char *album;
         uint8_t compilation;
         uint32_t trackno;
+        uint32_t ntracks;
         uint32_t discno;
+        uint32_t ndiscs;
+        int genre;
         const char *year;
         struct {
             uint8_t *data;