LoginSignup
4
5

More than 3 years have passed since last update.

PythonでflacをaacやALACに変換する。

Posted at

flac形式がiphone対応してないため、変換するツール作りたい。

事前準備

pydubとffmpegをインストールする。

開発環境は以下

  • Windows10 64bit Pro
  • VS Code

実装

from pydub import AudioSegment

sound = AudioSegment.from_file("C:/Project/audio/music.flac", format="flac")
# AAC形式への変換
sound.export("convert320k.m4a", format="ipod", codec="aac", bitrate="320K")
# ALAC(AppleLossless)形式への変換
sound.export("convert.alac", format="ipod", codec="alac")

はまった点

formatにalacを指定するとエラーとなり、ffmpeg側から怒られた。
mp3ならmp3で通るので拡張子と同じ設定だなと思いこみで、半日潰れた。

    sound.export("convert.alac", format="alac", codec="alac") # NG
    sound.export("convert.alac", format="ipod", codec="alac") # OK

参考

4
5
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
4
5