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: using ffmpeg to rebuild mp3s (Read 3166 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

using ffmpeg to rebuild mp3s

i'm using ffmpeg to 'rebuild' mp3s by copying the audio stream to a new file while discarding most of the metadata - the problem i'm having is that the LAME tag is also discarded and i want to keep that

basically i want to remove all of the 'fluff', such as artist, title, comments. cover art, etc., but keep everything that an mp3 requires and that is useful to the decoder

i've been playing with combinations of the following and the LAME tag is always trash-canned, but if i adjust to keep the tag, then other stuff i don't want (artist, etc.) is also retained...

Code: [Select]
-hide_banner -loglevel warning -i 'in.mp3' -ignore_unknown -map 0:a -map_metadata -1 -codec:a copy -bitexact 'out.mp3'

i'm rebuilding the mp3s because i'm not intimately familiar with the format, so i'm guessing that using ffmpeg to copy to a new file is the way to go, however that's just a guess - if anyone has a better idea i'm all ears (just keep in mind i'm working from a terminal and don't want GUIs)


Re: using ffmpeg to rebuild mp3s

Reply #2
i'm on Linux, so no foobar2k (i don't use wine either)

plus i'm using console tools because rebuilding mp3s is part of a larger shell script project

Re: using ffmpeg to rebuild mp3s

Reply #3
What exactly do you mean by "LAME tag"?  Artist, etc. is all IDv3.  Do you mean the vendor string?

Re: using ffmpeg to rebuild mp3s

Reply #4
LAME tag is identical to the Xing VBR header, except with a different signature which is used for CBR files.

Re: using ffmpeg to rebuild mp3s

Reply #5
yes, i think @kode54 explained what i meant

when LAME encodes, it "extends", if that's the right word, the Xing header - in it is some info about the mp3, particularly a CRC checksum of the audio stream and it is this i am most interested in keeping when rebuilding the file with ffmpeg

Re: using ffmpeg to rebuild mp3s

Reply #6
You could try and add
Code: [Select]
-codec:d copy
to your command line

Code: [Select]
-dcodec copy
should also work

Re: using ffmpeg to rebuild mp3s

Reply #7
hi @Maggi - thanks for the reply

that didn't work for me ...

Code: [Select]
Unable to find a suitable output format for 'dcodec' dcodec: Invalid argument
Unable to find a suitable output format for 'codec:d' codec:d: Invalid argument

regardless, i suspect that what i'm trying to do may simply not be possible

the LAME tag is part of (or is, or replaces) the Xing header and so i suspect that it cannot be separated from Xing which means i'd have to map/copy the whole header, which i don't want to do because i want ffmpeg to write a fresh one

so unless there's an ffmpeg stream specifier for only the LAME tag (i couldn't find it), i think i'm up the creek and i think what @kode54 said confirms that it's either all (Xing/Lame) or nothing

as much as i'd like to keep the LAME CRC checksum, i don't think it's possible

Re: using ffmpeg to rebuild mp3s

Reply #8
That error message looks like you forgot to put a - before those options

dcodec copy vs. -dcodec copy
codec:d copy vs. -codec:d copy

:)

Re: using ffmpeg to rebuild mp3s

Reply #9
I just made a few tests and if you use
Code: [Select]
ffmpeg -i "%~1" -map 0:a -acodec copy -dcodec copy -bitexact "%~dpn1_out.mp3"
-map 0:a will only map the audio stream, so the album art will not get transfered to the output file.

The rest of the metadata seems to be unaffected and passed (copied) to the output file.

You could extend that command line to explicitly strip certain tags using this table
https://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata#MP3

eg. -metadata album="" will delete the album tag -metadata artist="" will delete the artist tag and so on

Code: [Select]
ffmpeg -i "%~1" -map 0:a -acodec copy -dcodec copy -metadata album="" -metadata artist="" -bitexact "%~dpn1_out.mp3"

 8)

Re: using ffmpeg to rebuild mp3s

Reply #10
Try this:
Code: [Select]
ffmpeg -i /path/to/input.mp3 -c:a copy -id3v2_version 0 /path/to/output.mp3

 

Re: using ffmpeg to rebuild mp3s

Reply #11
@nu774 - that sort of works in that there is a LAME tag copied to the new file and the metadata i don;t want is discarded, but some of the LAME data is altered - here i'm looking at the files with mp3guessenc...

Code: [Select]
original
  Bitrate strategy      : CBR, 255 kbps or higher
  Lowpass value         : 20500
  nspsytune             : yes
  nssafejoint           : yes
  nogap continued       : no
  nogap continuation    : no
  ATH type              : 4
  Encoding mode         : joint stereo
  Source frequency      : 44.1 kHz
  Preset                : 320 kbps
Code: [Select]
copy
  Bitrate strategy      : unknown
  Lowpass value         : unknown
  nspsytune             : no
  nssafejoint           : no
  nogap continued       : no
  nogap continuation    : no
  ATH type              : 0
  Encoding mode         : mono
  Source frequency      : 32 kHz or below
  Preset                : No preset.
but then when i look at the MPEG stream details, the info is correct...

Code: [Select]
  Data rate               : 320.0 kbps
  Audio frequency         : 44100 Hz
  Encoding mode           : joint stereo

so i ended up with conflicting info and i'm not sure how different decoders would handle that

That error message looks like you forgot to put a - before those options

i messed up when i made that post - indeed i did forget the '-' at first, but i then corrected my mistake, then forgot i corrected it and posted the erroneous errors

both of your suggestions provide a very similar result regarding the LAME tag - the above is using @nu774 code

i really appreciate the help but i don't want to keep beating a potentially dead horse either - perhaps i should discard the LAME tag as i was originally doing and not worry about it, or dump the specific metadata i want to remove

from a decoder perspective, are there any consequences to discarding the LAME info?