HydrogenAudio

Lossy Audio Compression => AAC => AAC - General => Topic started by: Marsu42 on 2023-10-25 00:41:57

Title: Command line tool to duplicate tags for mp4 (m4b, m4a)?
Post by: Marsu42 on 2023-10-25 00:41:57
I'm trying to copy all tags from a mp4 file to another, but haven't found a command line tool (Windows) to do it.

For mp3 and ogg there are options, like id3.exe --duplicate or tools that dump tags to stdout and read them from stdin to tag another file. I haven't found such a tool for mp4 yet, and am struggling to manually catch all possible tags with mediainfo or exiftool.

I know mp4box, or other tools like kid3-cli, tone, ... but didn't see how to do it in one batch, maybe some wizardry with json files or the like.
Title: Re: Command line tool to duplicate tags for mp4 (m4b, m4a)?
Post by: jprjr on 2023-10-26 14:42:19
ffmpeg can do it, I think you'll have to make a copy of your destination file rather than just update the existing file.

Assuming you have "source.mp4" with your tags, "untagged.mp4" is your audio without tags, and "destination.mp4" as the audio from untagged.mp4 + the tags from source.mp4:

Code: [Select]
ffmpeg -i source.mp4 -i untagged.mp4 -map_metadata 0 -map 1 -c:a copy -movflags faststart destination.mp4

Here's the breakdown of the command:


What it probably won't copy very well is embedded pictures, I always have a hard time getting that handled correctly.

It might not copy each and every tag but I think the only missing tags would be particularly esoteric ones. All your standard stuff like artist, title, album, albumartist, musicbrainz IDs, etc should copy fine.
Title: Re: Command line tool to duplicate tags for mp4 (m4b, m4a)?
Post by: jprjr on 2023-10-26 14:52:58
It looks like exiftool should be able to do this as well:

Code: [Select]
exiftool -TagsFromFile source.mp4 -overwrite_original -all:all untagged.mp4

This will copy the tags from source.mp4 and write them into untagged.mp4 - updating it in-place.
Title: Re: Command line tool to duplicate tags for mp4 (m4b, m4a)?
Post by: nu774 on 2023-10-26 15:58:50
Code: [Select]
ffmpeg -i source.mp4 -i untagged.mp4 -map_metadata 0 -map 1 -c:a copy -movflags faststart destination.mp4
What it probably won't copy very well is embedded pictures, I always have a hard time getting that handled correctly.
This may sound strange, but ffmpeg treats cover arts as video streams. So I think you can do it like this:
Code: [Select]
ffmpeg -i source.mp4 -i untagged.mp4 -map_metadata 0 -map 1 -c:a copy -map 0 -c:v copy -movflags faststart destination.mp4