FFMPEG Adding Metadata to an .mp3 From .mp3 Input?

1

If I start off with a .mp3 file, how can I add metadata to it? I'm aware of the -metadata title="Some Title" -metadata artist="Someone" formatting, but not sure how this can be applied to a .mp3 file, especially if the file is already a .mp3.

I'm thinking something more like this: ffmpeg -i input.mp3 -metadata artist="Someone" -f mp3 output.mp3

The only thing is that when I execute this with ffmpeg 4 compiled with all libraries on Kubuntu 18.04, I get this error message:

Automatic encoder selection failed for output stream #0:0. Default encoder for format mp3 (codec mp3) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:0

Edit 0:

This also happens when I try to add -acodec libmp3lame although the error seems to indicate that I don't have the .mp3 codec

sarah@ConvergentRefuge:~/Desktop/Indexing/Test Folder$ ffmpeg -i DANCE\ WITH\ THE\ DEAD\ -\ BATTLE.mp3 -acodec libmp3lame -f mp3 file.mp3 ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7 (Ubuntu 7.3.0-16ubuntu3) configuration: libavutil 56. 14.100 / 56. 14.100 libavcodec 58. 18.100 / 58. 18.100 libavformat 58. 12.100 / 58. 12.100 libavdevice 58. 3.100 / 58. 3.100 libavfilter 7. 16.100 / 7. 16.100 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 Input #0, mp3, from 'DANCE WITH THE DEAD - BATTLE.mp3': Duration: 00:04:15.92, start: 0.025057, bitrate: 128 kb/s Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s Metadata: encoder : LAME3.99r Side data: replaygain: track gain - -9.200000, track peak - unknown, album gain - unknown, album peak - unknown, Unknown encoder 'libmp3lame'

Sarah Szabo

Posted 2018-06-16T05:03:52.640

Reputation: 187

Answers

3

Your ffmpeg build does not have any MP3 encoder. However, for your use case, that's irrelevant.

Use

ffmpeg -i input.mp3 -c copy -metadata artist="Someone" output.mp3

Output has to be a separate file. FFmpeg can't update the input itself.

Gyan

Posted 2018-06-16T05:03:52.640

Reputation: 21 016

0

I have hundreds of files, and I use this script.  I hope will be helpful for someone.

Github

Github with some audio scripts

YouTube Playlist

#!/bin/sh

#____________ 1. CONVERT ALL WAV FILES TO 44100hz and 16bits _______________________________
# Rename all audio wav files in folder, with the format 001.wav, 002.wav, 003.wav, etc...
a=1
for i in *.wav; do
  new=$(printf "%03d.wav" "$a") #03 pad to length of 3
  mv -i -- "$i" "$new"
  let a=a+1
done

rm *.mp3    # remove old mp3 files

declare -a arr=("" # always keep empty the first array index, because have index zero.
                "Track Title 1 (allow with special characters + $ ñ ò)"
                "Track Title 2 (allow with special characters + $ ñ ò)"
                "Track Title 3 (allow with special characters + $ ñ ò)"
                "Track Title 4 (allow with special characters + $ ñ ò)"
                "Track Title 5 (allow with special characters + $ ñ ò)"
                "Track Title 6 (allow with special characters + $ ñ ò)"
                "Track Title 7 (allow with special characters + $ ñ ò)"
                "Track Title 8 (allow with special characters + $ ñ ò)"
                "Track Title 9 (allow with special characters + $ ñ ò)"
                "Track Title 10 (allow with special characters + $ ñ ò)"
                "Track Title 11 (allow with special characters + $ ñ ò)"
                "Track Title 12 (allow with special characters + $ ñ ò)"
                )

counterTotalFiles = 0;    # count the total audio wav files there are in the folder
counterTrackNumber = 0;   # sequence of the track number
metadataArtist = "My Artist Name"
metadataTPE2="My Artist Album"
metadataComposer="My Composer"
metadataGenre="Spoken & Audio" 
metadataYear=`date +%Y`   # setup automatic the current year


# count the total audio wav files there are in the folder
for x in *.wav; do      
  let counterTotalFiles++
done

  for z in *.wav; do      
    let counterTrackNumber++
    ffmpeg -y -i "$z" -vn -ar 44100 -b:a 128k -metadata title="${arr[$counterTrackNumber]}" -metadata album="My Album Name" -metadata track="$counterTrackNumber/$counterTotalFiles" -metadata artist="$metadataArtist" -metadata TPE2="$metadataTPE2" -metadata composer="$metadataComposer" -metadata genre="$metadataGenre" -metadata year="$metadataYear" $z.mp3
  done

# remove temporary files
rm "temp-"*.wav    
rm *.pkf    

# rename the wrong extension *.wav.mp3 to the right extension *.mp3
for f in *.mp3; do
    mv -- "$f" "$(basename -- "$f" .wav.mp3).mp3"
done


# show info about your media files generated
mediainfo *.mp3
ls -lah

fireDevelop.com

Posted 2018-06-16T05:03:52.640

Reputation: 1

2Thanks (I guess?) for the complete, working script, but it might be more helpful to (1) present and explain the ffmpeg command at the core of the script, and (2) explain the rest of what the script is doing.  Also, (3) when you have a command that’s 352 characters long, it’s nice to break it up into shorter lines.  And (4) I noticed that your ffmpeg command quotes "$z" (and "$metadataTPE2", "$metadataComposer", "$metadataGenre" and "$metadataYear") but not $z.mp3.  … (Cont’d) – Scott – 2019-07-13T18:04:37.803

1

(Cont’d) … (5) Finally, most importantly, it looks like your ffmpeg command takes .wav files as input and produces .mp3 files as output.  But the question asks how to *take .mp3 files as input* and produce .mp3 files as output.  (6) P.S. Arithmetic Expansion is specified by POSIX, but let and ++ are not.  (7) P.P.S. How can that script even work when it says things like counterTotalFiles = 0 (with spaces)?

– Scott – 2019-07-13T18:04:40.313