Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: mp4 command line tagger (Read 78906 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

mp4 command line tagger

Reply #1
Good work!

Now it remains to do the tagging just after the encoding through QuickTime by modifying the VBS script for EAC.

Adding of course the right parameters to pass by EAC like name, title, track, etc...

Encoding and tagging in one pass, who'll need Nero, Sveta or Foobar...

Oooopsssss, don't hit me! I'm joking! 

mp4 command line tagger

Reply #2
I modified the script for EAC & QuickTime.

Now I can do encoding and tagging in one pass, but there is apparently a problem with your program.

I cannot tag the year, be it by the script of manually.  :'(

But at least that doesn't pertub the tagging process


mp4 command line tagger

Reply #4
Thanks!

Now it works fine (but EphPod doesn't)

A singer labeled "Pop" was converted to "Jazz" by EphPod. 

The tagged songs transferred on my Mac renamed to .m4a were imported perfectly in iTunes.

As for the losing of focus, well I added some AppActivate to the script to help.

So where should I put the new script, here or the old forum in which it evolved?

mp4 command line tagger

Reply #5
>A singer labeled "Pop" was converted to "Jazz" by EphPod

Just to be clear, iTunes reads correctly?  foobar also reads what seems to be correctly.  I've had the same problem with EphPod.

Which version of EphPod are you using?  I'd like to be able to tell the author he's inconsistent with iTunes.

>So where should I put the new script, here or the old forum in which it evolved?

Either way.  There should be a way to send keys using windows api rather than vbs 'sendkeys',  but I don't know how.

mp4 command line tagger

Reply #6
>Which version of EphPod are you using?  I'd like to be able to
>tell the author he's inconsistent with iTunes.

The download link I got said 2.71, but when I launch EphPod is say 2.70b.
Maybe he's not inconsistent, he simply doesn't put the tag as it is written originally?

And yes iTunes gets it right.

>Either way.  There should be a way to send keys using
>windows api rather than vbs 'sendkeys',  but I don't know how.

Me neither.

Anyway here is the new script.

Following the configuration procedure of EAC as described here : http://www.hydrogenaudio.org/forums/index....showtopic=10874

This option "Additional command line options" was set to C:\SAVE\EAC.vbs %s %d

Now it MUST be set like this C:\SAVE\EAC.vbs %s %d "%a" "%g" "%t" %n "%m" %y

Note : The quotes are important to encompass names with spaces

Also, the EAC.vbs script and the TG.exe program are in the C:\SAVE directory, so modify to your liking to accomodate your needs.

mp4 command line tagger

Reply #7
Code: [Select]
Function CallQuickTime(Path)
  Dim fso, mp4, mp5, c, Car, QT, Str
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set WshShell = WScript.CreateObject("WScript.Shell")

  Str = ""
  For c = 1 To Len(Path) 'Convert 1 \ in 2 \
    If Mid(Path, c, 1) = "\" Then
        Str = Str & "\\"
      Else
        Str = Str & Mid(Path, c, 1)
    End If
  Next

  mp4 = Left(Path, Len(Path)-3) & "mp4"
 
  ' get filename.wav by Zeer
  For c = 1 To Len(Path)
    If Mid(Path, c, 1) = "\" Then
      wavx=c
    Else
    End If
  Next

  wav=Right(Path,Len(Path)-wavx)
  wav=Left(wav,Len(Path)-3)

  Path = Chr(34) & Str & Chr(34)

  QT = Chr(34) & "C:\\Program Files\\QuickTime\\QuickTimePlayer.exe " & Chr (34)
 
  WshShell.Run(QT & Path)
 
  WScript.Sleep 3000

Do 'Loop until the mp4 file really exists

  WshShell.AppActivate(wav)
  WScript.Sleep 1500
  WshShell.SendKeys "%FE" 'File Export, could be "^E"
  WScript.Sleep 500
  WshShell.SendKeys ("C:\Temp.mp4") 'Temporary mp4 filename
  WScript.Sleep 500
  WshShell.SendKeys "{ENTER}"
  WScript.Sleep 8000

'Check to see if the temp file is still here
  While fso.FileExists ("C:\Temp.mp5")
    WScript.Sleep 2000 'With CScript.exe instead of WScript.exe I could put 500
   'IMPORTANT : Increase the value under slower systems (.wav already exists bug)
  Wend
 
'The Enter was added in case QuickTime says .wav file already exists, to clear the error.
'It launches playing if all goes well.
  WScript.Sleep 500
  WshShell.AppActivate(wav)
  WshShell.SendKeys "{ENTER}"
  WScript.Sleep 500
  WshShell.SendKeys "{ESC}"
  WScript.Sleep 500

Loop Until fso.FileExists("C:\Temp.mp4")

'Close QuickTime
  WshShell.AppActivate(wav)
  WScript.Sleep 500
  WshShell.SendKeys "{ESC}"
  WScript.Sleep 500
  WshShell.SendKeys "%FX"

  WScript.Sleep 2000 'A little wait to let QuickTime exit before returning to EAC
  ' If not EAC could not be able to rename the wav file to original, then delete it.
  'IMPORTANT : Increase the value under slower systems (files do not regain their original names bug)


  'Added part here for tagging the mp4.
  Tagger = Chr(34) & "C:\\SAVE\\tg.exe " & Chr (34)
  TagParams = "C:\Temp.mp4" & " --artist " & Artist & " --album " & Album & " --title " & Title & " --track " & Track & " --genre " & Genre & " --year " & CDYear
 
  WshShell.Run(Tagger & TagParams)

  'Wait some seconds for tagging to occur.
  WScript.Sleep 3000


  'Move the Temp.mp4 to the right place while renaming it
  fso.MoveFile "C:\Temp.mp4" , mp4
  Set fso = Nothing
 
End Function


'Get the 8 first arguments and assumes they are %s %d "%a" "%g" "%t" %n "%m" %y
'(source, destination, Artist, Album, Title, Track number, Genre, Year In EAC)

Dim wav

Set objArgs = WScript.Arguments

  wav = objArgs(0)
  mp4 = objArgs(1)
  Artist = Chr(34) & objArgs(2) & Chr(34)
  Album = Chr(34) & objArgs(3) & Chr(34)
  Title = Chr(34) & objArgs(4) & Chr(34)
  Track = objArgs(5)
  Genre = Chr(34) & objArgs(6) & Chr(34)
  CDYear = objArgs(7)
 
CallQuickTime(wav)
Wscript.Quit

mp4 command line tagger

Reply #8
Don't you know that there is a bug with long post on this board ?
seems like it worked this time though, just letting you know .... 

mp4 command line tagger

Reply #9
Quote
Don't you know that there is a bug with long post on this board ?
seems like it worked this time though, just letting you know .... 

Yeah! I noticed 

That's why I splitted on two posts, the code was all fouled up.

The ruse worked  (w00t)

mp4 command line tagger

Reply #10
EhpPod & tags

>Maybe he's not inconsistent, he simply doesn't put the tag as it is written

It's not clear what he's doing.  He says he prefers id3v2 string genre tags to id3v1 numeric genre tags.  But if EphPod is not reading the tags created by iTunes, then he's doing something wrong.  As far as I can tell from files people have sent to me, iTunes creates numeric rather string genre tags.  Could you look at a few iTunes created mp4's and confirm that iTunes is creating numeric genre tags?

Given that you're saying he's not reading iTunes tags, it appears he's doing something wrong.

mp4 command line tagger

Reply #11
You were right.

I Hex Edited some iTunes created .m4a and the "gnre" tag is numeric I wrongly thought it was alpha. But the year is alpha.

$0E for Pop.
$1D for Vocal if that helps.

iTunes is using CDDB, I don't know if it differs from freedb but that seems not to be the problem.

Or maybe you and him don't use the same genre tables?

Edit:
I found a table for genre here : http://www.id3.org/id3v2-00.txt

Apparently the tags are the same except the iTunes tags are plus 1.

iTunes -> ID Tags
$0E -> $0D = Pop
$1D -> $1C = Vocal

So you see he read the tags correctly but since they are out of sync the result is wrong. Maybe he sould add a preference in EphPod for people wanting to use iTunes rules or ID3 rules, or simply go for iTunes rules for mp4.
End edit:

Meanwhile I correct the tags manually in EphPod after transfer.

mp4 command line tagger

Reply #12
I've just edited the Script Code message.

In fact it was wrong and I haven't noticed it till now.

mp4 command line tagger

Reply #13
EphPod should really read iTunes tags.  iTunes and every other mp4 tag writer or reader I know of uses id3v1 + 1.

I could add a parameter to do id3v1 (or any other tagging scheme EphPod uses), if I had the patience to figure out exactly what EphPod is doing.

mp4 command line tagger

Reply #14
It's not to you to adapt to the wrong doing of EphPod.

If you allowed a tagging "out of sync" with iTunes you wouldn't be able to trust any mp4 file you could encounter.

iTunes is quite a reference for mp4 tagging, EphPod must follow it's steps, we're not talking about mp3's.

mp4 command line tagger

Reply #15
Yesterday I encoded and tagged some tracks which contain accented caracters, it became a great problem.

Your tagging Richard isn't accepted by EphPod (I don't know why it crashes  ) and by iTunes when it comes to accented caracters.

Strangely EphPod refused also one music in the rip which hadn't any accented caracter in it??? (other freshly encoded CDs imported perfectly also)

For iTunes, if you try to import songs tagged by TG.EXE with accented caracters in them the name becames truncaded at the first special char. "Générique" became "G".    (G for Gasp, Gulp?)

In fact iTunes uses a marker to identify accented chars. It's "$C3"

é = C3,A9
è = C3,A8
ê = C3,AA

Well you need to do a correlating table if you want to tag in the iTunes way.

:'(  It was all working so well...

I re encoded the same tracks without tagging and this time EphPod accepted them 

mp4 command line tagger

Reply #16
Alas, I never use accented characters and therefore never test with them.  I'll poke around a bit and see if there are any easy fixes.

Does --remove clear the bad tags?

mp4 command line tagger

Reply #17
I believe iTunes uses UTF-8 for the tags. Your OS should be able to aid you in converting it to something else.

mp4 command line tagger

Reply #18
I haven't tried the --remove tag Richard, but I'll do a check.

Danchr, you sent me in the right direction, it is UTF-8 as I could find here : http://www1.tip.nl/~t876506/utf8tbl.html

Some UTF-8 explanation : http://www.joconner.com/javai18n/articles/UTF8.html

So in fact there would have to be a table that will convert from Unicode to UTF-8 as far as I understood.

Maybe you have UTF tools available in your developing environment Richard?

Meanwhile, it seems the characters above $80 must be replaced by a standard char if you want iTunes to be able to read the tags and not lose what's after the special char.

i.e : Say there is "Générique" changed to "G_n_rique" at least iTunes will read this.

Well you won't be alone in that task, EphPod too must be modified to understand UTF-8    (and so do the others)

Good luck.

mp4 command line tagger

Reply #19
Quote
So in fact there would have to be a table that will convert from Unicode to UTF-8 as far as I understood.

Maybe you have UTF tools available in your developing environment Richard?

You should consider scouring the Windows SDK for information on UTF-8. I find it very hard to believe that there isn't a routine for converting to and from UTF-8. UTF-8 is an 8 bit representation of all Unicode characters, btw.

mp4 command line tagger

Reply #20
I'm using a windows port of gcc, so I should have standard libraries, etc.

It should be trivial to change any char above 0x7f to a space, but there must be a routine which will map anything above 0x7f to something more sensible.  Although there may be a number of different char sets, which would complicate the problem.

Will EphPod transfer a song tagged by iTunes with accented chars?

The database on the ipod (iTunesDB) uses 2 bytes to store each char.  This seems different than the way tags are stored within a song.

How is iTunes storing the accented chars in a song?  Please post a sample hex sequence or two of the tag as stored by iTunes.

Here's some more info: http://www.cl.cam.ac.uk/~mgk25/unicode.html (I did not read the whole thing).

mp4 command line tagger

Reply #21
Yes coding in iTunesDB and in a song are different.

iTunesDB is in Unicode 16 bits or UCS (Universal Character Set) and you can verify the coding with the accessory Chartable provided with Windows.  U+xxxx for the caracter code.

Coding in a song is done in UTF-8 apparently. and EphPod doesn't know how to handle it. (But song encoded with iTunes seems not to make it crash)

I have an artist : Déanta

In iTunes m4a it gives (I space them to explain)

D | Ã | © | a | n | t | a  -  Shown like that (without the bars) in EphPod

Hex
44|C3|A9|61|6E|74|61

If you look at the UTF-8 code of C3;A9 it's "é".

I have a song titled : Générique

G | Ã | © | n | Ã | © | r | i | q | u | e

47|C3|A9|6E|C3|A9|72|69|71|75|65

Look about the code ranges in UTF-8 on table B-2.
http://www.csis.gvsu.edu/GeneralInfo/Oracl...a96529/appb.htm

Here is some code in C you may understand it, I don't  My C is very far....
http://www-124.ibm.com/pipermail/jikes-dev...uly/003495.html

Very interesting about Unicode and UTF-8 and others.
http://czyborra.com/utf/

Happy coding.

PS : Using the --remove option allowed a buggy mp4 to be imported by EphPod afterwards.

Addendum : I found a Microsoft page about Unicode and UTF including Windows API : http://msdn.microsoft.com/library/en-us/in...nicode_6bqr.asp


mp4 command line tagger

Reply #23
You should consider using libmp4v2 for reading the tags. It's a part of the mpeg4ip project, but I find that the easiest way to get it is as part of faad2 from the FAAC project. I successfully used it to add MP4 metadata support to the giFT file sharing daemon (the patch hasn't been applied yet). The API is remarkable simple

 

mp4 command line tagger

Reply #24
Quote
You should consider using libmp4v2 for reading the tags. It's a part of the mpeg4ip project, but I find that the easiest way to get it is as part of faad2 from the FAAC project. I successfully used it to add MP4 metadata support to the giFT file sharing daemon (the patch hasn't been applied yet). The API is remarkable simple

I've browsed the lib and am not sure it does anything I'm not doing in terms of tagging.  I seem to be missing something about using it though.

Can you post a few lines of code showing how to, for example,  read an album name and then write a song title.  I'm clearly misunderstanding its syntax, as it crashes when I call MP4GetMetadataAlbum.

EDIT:

Code: [Select]
#include <stdio.h>

#include <mp4.h>

int main(int argc, char *argv[])
{
    char song[] = "song.mp4";
    char **album;
    MP4FileHandle f;
    
    f = MP4Read(song);
    album = (char **)malloc(256);
    MP4GetMetadataAlbum(f, album);

    printf("album: %s\n", *album);  // so far, so good - reports album name
    
    MP4SetMetadataAlbum(f, "new title");  // why doesn't this work?
    MP4Close(f);
   return 0;
}