将 (ID3) 标签从 FLAC 传输到 MP3 的 Linux 脚本

发布于 2024-12-26 19:59:55 字数 298 浏览 1 评论 0原文

对于我的媒体服务器,我正在寻找将标签从 FLAC 文件传输到 MP3 的方法。

在 bash 脚本中,我可以使用 metaflac 将标签提取到本地变量,但是当使用id3v2,我似乎丢失了国家字符(猜猜它一定是unicode?)

此外,我需要能够设置重播增益标签和专辑封面(全部存在于FLAC)。

我正在寻找一种无人值守运行的脚本化解决方案。

For my media server, I am looking for ways to transfer tags from my FLAC files to MP3.

In a bash script, I can extract tags using metaflac to local vars, but when tagging mp3 with id3v2, I seem to lose national characters (guess it must be unicode?)

Also I need to be able to set replay gain tags, and album art (all present in the FLAC's).

I am looking for a scripted solution to run unattended.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

唱一曲作罢 2025-01-02 19:59:55

如果您对 Python 解决方案感兴趣,诱变库看起来非常不错。

它可能很简单:

from mutagen.flac import FLAC
from mutagen.easyid3 import EasyID3

flacfile = FLAC("flacfile.flac")
mp3file = EasyID3("mp3file.mp3")

for tag in flacfile:
    if tag in EasyID3.valid_keys.keys():
        mp3file[tag] = flacfile[tag]

mp3file.save()

我找到了将 mp3 id3 标签复制到 FLAC 文件中的解决方案。

If you are interested in a Python solution, the mutagen library looks really good.

It could be as easy as:

from mutagen.flac import FLAC
from mutagen.easyid3 import EasyID3

flacfile = FLAC("flacfile.flac")
mp3file = EasyID3("mp3file.mp3")

for tag in flacfile:
    if tag in EasyID3.valid_keys.keys():
        mp3file[tag] = flacfile[tag]

mp3file.save()

I found this solution for copying mp3 id3 tags into FLAC files.

醉南桥 2025-01-02 19:59:55

试试这个工具eyed3。它支持专辑封面嵌入、latin1、utf8、utf16-BE 和 utf16-LE 文本编码。但是不支持重放增益。据我了解,它没有得到广泛支持。

Try this tool eyed3. It supports album art embedding, text encoding in latin1, utf8, utf16-BE and utf16-LE. However the replay gain is not supported. As far as I understand it is not widely supported.

止于盛夏 2025-01-02 19:59:55

维克多的解决方案为我指明了道路。但是,如果将标签复制到刚刚转换的文件(例如从 flac 到 mp3),则可能会失败。也就是说,如果您将标签复制到的文件尚不具有任何标签,则该操作将会失败。

因此,您可能需要首先准备目标文件,为其提供标记的方法。

from mutagen import File
from mutagen.flac import FLAC
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, ID3NoHeaderError

def convert_tags(f1,f2):
    # f1: full path to file copying tags from
    # f2: full path to file copying tags to
    # http://stackoverflow.com/questions/8873364/linux-script-to-transfer-id3-tags-from-flac-to-mp3
    # http://stackoverflow.com/a/18369606/2455413
    try:
        meta = EasyID3(f2)
    except ID3NoHeaderError:
        meta = File(f2, easy=True)
        meta.add_tags()
        meta.save()
    from_f = FLAC(f1)
    to_f = EasyID3(f2)
    for tag in from_f:
        if tag in EasyID3.valid_keys.keys(): to_f[tag] = from_f[tag]
    to_f.save()
    return

Victor's solution showed me the way. It may fail, however, if copying tags to a file you've just converted, for example, from flac to mp3. That is, it will fail if the file you are copying tags to doesn't already have any tags.

So you may need to prime the destination file first, giving it the means to have tags.

from mutagen import File
from mutagen.flac import FLAC
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, ID3NoHeaderError

def convert_tags(f1,f2):
    # f1: full path to file copying tags from
    # f2: full path to file copying tags to
    # http://stackoverflow.com/questions/8873364/linux-script-to-transfer-id3-tags-from-flac-to-mp3
    # http://stackoverflow.com/a/18369606/2455413
    try:
        meta = EasyID3(f2)
    except ID3NoHeaderError:
        meta = File(f2, easy=True)
        meta.add_tags()
        meta.save()
    from_f = FLAC(f1)
    to_f = EasyID3(f2)
    for tag in from_f:
        if tag in EasyID3.valid_keys.keys(): to_f[tag] = from_f[tag]
    to_f.save()
    return
眼藏柔 2025-01-02 19:59:55

这是使用 ffmpeg 的另一种解决方案。
例如。只需在 $HOME/.bashrc 中定义一个 bash 函数:

flac2mp3() 
{ 
  ffmpeg -i "$1" -ab 320k -map_metadata 0 -id3v2_version 3 "$(basename "$1" flac)mp3"
}

Here is another solution using ffmpeg.
Eg. just define a bash function in $HOME/.bashrc:

flac2mp3() 
{ 
  ffmpeg -i "$1" -ab 320k -map_metadata 0 -id3v2_version 3 "$(basename "$1" flac)mp3"
}
猥琐帝 2025-01-02 19:59:55

Quod Libet 附带一个名为 operon 可以执行此操作以及更多操作:

operon copy song.flac song.mp3

由于 Quod Libet 是基于 Mutagen 构建的,因此它知道一堆晦涩的标签以及如何在各种标签格式之间翻译它们,这对于某些工作流程很重要。我注意到的唯一怪癖是它不会复制具有空值的标签,但这并不困扰我。

Quod Libet comes with a command line tool called operon that does this and more:

operon copy song.flac song.mp3

Since Quod Libet is built on Mutagen, it knows about a bunch of obscure tags and how to translate them among the various tagging formats, which is important for some workflows. The only quirk I noticed is that it doesn't copy tags with empty values, but that doesn't bother me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文