2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

flac音楽ファイルのメタデータをmp3に付ける

Posted at

やりたいこと

  • flacからmp3に変換するときにメタデータが消えるのを何とかしたい
  • よくよくググったら出てきた。

という話です。
ID3タグとflacファイルメタデータとRustでRustでやることも考えましたが、今回の発見でこの計画は凍結です。

解決法

ここにありました。
https://wiki.archlinux.jp/index.php/Flac_%E3%82%92_Mp3_%E3%81%AB%E5%A4%89%E6%8F%9B
flacのツールとlameを使います。lameでmp3に変換するときにタグのデータを入力できたのです。
ただ、上記のサイトだと私の欲しい次のフレームが欠落していたので、それぞれ追加対応しました。

  • アルバムアーティスト
    • アルバムアーティストはID3の規格ではTPE2 [#TPE2 Band/orchestra/accompaniment]でした。
    • なので --tv "TPE2=${ALBUMARTIST}"のオプションを付けます。
  • 作曲者。これはそのままComposerだったので、
    • --tv "TCOM=${COMPOSER}"

というわけでシェルスクリプトの改訂版は下記です。

meta_flac2mp3.sh
# !/bin/bash

for a in *.flac; do
  # give output correct extension
  OUTF="${a[@]/%flac/mp3}"

  # get the tags
  ARTIST=$(metaflac "$a" --show-tag=ARTIST | sed s/.*=//g)
  TITLE=$(metaflac "$a" --show-tag=TITLE | sed s/.*=//g)
  ALBUM=$(metaflac "$a" --show-tag=ALBUM | sed s/.*=//g)
  GENRE=$(metaflac "$a" --show-tag=GENRE | sed s/.*=//g)
  TRACKNUMBER=$(metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g)
  DATE=$(metaflac "$a" --show-tag=DATE | sed s/.*=//g)
  ALBUMARTIST=$(metaflac "$a" --show-tag=ALBUMARTIST | sed s/.*=//g)
  COMPOSER=$(metaflac "$a" --show-tag=COMPOSER | sed s/.*=//g)

  # stream flac into the lame encoder
  flac -c -d "$a" | lame -V0 --add-id3v2 --pad-id3v2 --ignore-tag-errors \
    --ta "$ARTIST" --tt "$TITLE" --tl "$ALBUM"  --tg "${GENRE:-12}" \
    --tn "${TRACKNUMBER:-0}" --ty "$DATE" \
    --tv "TPE2=${ALBUMARTIST}" --tv "TCOM=${COMPOSER}" \
    - "$OUTF"
done
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?