如果我从一个 .mp3 文件开始,我该如何向其中添加元数据?我知道格式-metadata title="Some Title" -metadata artist="Someone"
,但不确定如何将其应用于 .mp3 文件,尤其是当文件已经是 .mp3 时。
我在想更多这样的事情:ffmpeg -i input.mp3 -metadata artist="Someone" -f mp3 output.mp3
唯一的问题是,当我在 Kubuntu 18.04 上使用所有库编译的 ffmpeg 4 执行此操作时,出现以下错误消息:
输出流 #0:0 的自动编码器选择失败。mp3 格式(编解码器 mp3)的默认编码器可能已禁用。请手动选择编码器。
为流 0:0 选择编码器时出错
编辑:
当我尝试添加时也会发生这种情况-acodec libmp3lame
,尽管错误似乎表明我没有 .mp3 编解码器
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'
答案1
您的 ffmpeg 版本没有任何 MP3 编码器。但是,对于您的用例来说,这无关紧要。
使用
ffmpeg -i input.mp3 -c copy -metadata artist="Someone" output.mp3
输出必须是单独的文件。FFmpeg 无法更新输入本身。
答案2
我有数百个文件,我使用这个脚本。我希望对某些人有帮助。
#!/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