FFMPEG从.mp3输入添加元数​​据到.mp3?


1

如果我从.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执行此操作时,我收到以下错误消息:

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

编辑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'

Answers:


3

您的ffmpeg版本没有任何MP3编码器。但是,对于您的用例,这是无关紧要的。

使用

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

输出必须是单独的文件。FFmpeg无法更新输入本身。


0

我有数百个文件,我使用这个脚本。我希望对某人有所帮助。

Github上

Github有一些音频脚本

YouTube播放列表

#!/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

1
谢谢(我猜?)完整的,有效的脚本,但是(1)ffmpeg在脚本的核心呈现和解释命令,以及(2)解释脚本正在做的其余部分可能更有帮助  。另外,(3)当你有一个长度为352个字符的命令时,最好把它分成更短的行。(4)我注意到,您的ffmpeg命令报价"$z"(和"$metadataTPE2",  "$metadataComposer",  "$metadataGenre" 和  "$metadataYear"),但不  $z.mp3。......(续)
Scott

(续)...(5)最后,最重要的是,看起来你的ffmpeg命令将.wav文件作为输入并生成.mp3文件作为输出。但问题是如何  .mp3文件作为输入并生成.mp3文件作为输出。(6)PS  算术展开是由POSIX指定,但let并  ++不是。(7)PPS当脚本说出counterTotalFiles = 0(带空格)之类的东西时,它怎么能工作?
Scott
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.