mp3をoggに変換

html5でaudioタグを使って簡単に音楽ファイルを再生できるようにできますが、mp3で音楽ファイルを用意すると、Firefoxでは再生できません(コントロールが表示されません)。Firefoxではogg形式でファイルを用意する必要があるようなので、mp3からoggへ変換する方法を調べました。

コマンドラインツールのffmpegというツールでoggへ変換できるらしいとわかり、やってみたのですが変換はできたもののFirefoxでは再生できませんでした。

ちなみにffmpegをMacにインストールするには、MacPortsを使うと簡単にできます。

sudo port install ffmpeg
Password:******

■MacPotsのコマンド

  • port search <パッケージ名>: パッケージの検索
  • port info <パッケージ名>: パッケージの情報を表示(ホームページのアドレスなど)
  • port list : パッケージの一覧を表示
  • port install <パッケージ名>: パッケージのインストール
  • port installed : インストールされているパッケージの一覧を表示
  • port uninstall <パッケージ名>: パッケージのアンインストール
  • port upgrade : MacPortsのアップグレード

ネットでさらに調べてみると、解決されている方がいました。(スコトプリゴニエフスク通信 – [Ogg]MP3をOgg Vorbisに変換する

MacPortsでもインストール可能です。

sudo install mpg321
sudo install vorbis-tools

変換コマンド

$ mpg321 audio.mp3 -w - | oggenc -o audio.ogg -

変換してみたところ、mp3のサイズの2倍近くのサイズになってしまいました。

oggencコマンドのオプションで品質を下げるとサイズが小さくなります。

■oggencコマンドのオプション($ oggenc -h )

oggenc from vorbis-tools 1.4.0 by the Xiph.Org Foundation (http://www.xiph.org/)

Usage: oggenc [options] inputfile […]

OPTIONS:
General:
-Q, –quiet Produce no output to stderr
-h, –help Print this help text
-V, –version Print the version number
-k, –skeleton Adds an Ogg Skeleton bitstream
-r, –raw Raw mode. Input files are read directly as PCM data
-B, –raw-bits=n Set bits/sample for raw input; default is 16
-C, –raw-chan=n Set number of channels for raw input; default is 2
-R, –raw-rate=n Set samples/sec for raw input; default is 44100
–raw-endianness 1 for bigendian, 0 for little (defaults to 0)
-b, –bitrate Choose a nominal bitrate to encode at. Attempt to encode at a bitrate averaging this. Takes an argument in kbps. By default, this produces a VBR encoding, equivalent to using -q or –quality. See the –managed option to use a managed bitrate targetting the selected bitrate.
–managed Enable the bitrate management engine. This will allow much greater control over the precise bitrate(s) used, but encoding will be much slower. Don’t use it unless you have a strong need for detailed control over bitrate, such as for streaming.
-m, –min-bitrate Specify a minimum bitrate (in kbps). Useful for encoding for a fixed-size channel. Using this will automatically enable managed bitrate mode (see –managed).
-M, –max-bitrate Specify a maximum bitrate in kbps. Useful for streaming applications. Using this will automatically enable managed bitrate mode (see –managed).
–advanced-encode-option option=value
Sets an advanced encoder option to the given value.
The valid options (and their values) are documented in the man page supplied with this program. They are for advanced users only, and should be used with caution.
-q, –quality Specify quality, between -1 (very low) and 10 (very  high), instead of specifying a particular bitrate.
This is the normal mode of operation. 
Fractional qualities (e.g. 2.75) are permitted
The default quality level is 3.
–resample n Resample input data to sampling rate n (Hz)
–downmix Downmix stereo to mono. Only allowed on stereo
input.
-s, –serial Specify a serial number for the stream. If encoding
multiple files, this will be incremented for each
stream after the first.
–discard-comments Prevents comments in FLAC and Ogg FLAC files from
being copied to the output Ogg Vorbis file.
–ignorelength Ignore the datalength in Wave headers. This allows
support for files > 4GB and STDIN data streams.

Naming:
-o, –output=fn Write file to fn (only valid in single-file mode)
-n, –names=string Produce filenames as this string, with %a, %t, %l,
%n, %d replaced by artist, title, album, track number,
and date, respectively (see below for specifying these).
%% gives a literal %.
-X, –name-remove=s Remove the specified characters from parameters to the
-n format string. Useful to ensure legal filenames.
-P, –name-replace=s Replace characters removed by –name-remove with the
characters specified. If this string is shorter than the
–name-remove list or is not specified, the extra
characters are just removed.
Default settings for the above two arguments are platform
specific.
–utf8 Tells oggenc that the command line parameters date, title,
album, artist, genre, and comment are already in UTF-8.
On Windows, this switch applies to file names too.
-c, –comment=c Add the given string as an extra comment. This may be
used multiple times. The argument should be in the
format “tag=value”.
-d, –date Date for track (usually date of performance)
-N, –tracknum Track number for this track
-t, –title Title for this track
-l, –album Name of album
-a, –artist Name of artist
-G, –genre Genre of track
-L, –lyrics Include lyrics from given file (.srt or .lrc format)
-Y, –lyrics-language Sets the language for the lyrics
If multiple input files are given, then multiple
instances of the previous eight arguments will be used,
in the order they are given. If fewer titles are
specified than files, OggEnc will print a warning, and
reuse the final one for the remaining files. If fewer
track numbers are given, the remaining files will be
unnumbered. If fewer lyrics are given, the remaining
files will not have lyrics added. For the others, the
final tag will be reused for all others without warning
(so you can specify a date once, for example, and have
it used for all the files)

INPUT FILES:
OggEnc input files must currently be 24, 16, or 8 bit PCM Wave, AIFF, or AIFF/C
files, 32 bit IEEE floating point Wave, and optionally FLAC or Ogg FLAC. Files
may be mono or stereo (or more channels) and any sample rate.
Alternatively, the –raw option may be used to use a raw PCM data file, which
must be 16 bit stereo little-endian PCM (‘headerless Wave’), unless additional
parameters for raw mode are specified.
You can specify taking the file from stdin by using – as the input filename.
In this mode, output is to stdout unless an output filename is specified
with -o
Lyrics files may be in SubRip (.srt) or LRC (.lrc) format

 オプションは -q で−1〜10の間で指定するようです。

私のmp3ファイルは品質レベルを1にすると同じ程度のサイズになりました。

$ mpg321 audio.mp3 -w - | oggenc -q 1 -o audio.ogg -

vorbis-toolsをインストールしたら、ffmpegでもoggに変換できました。

ffmpeg -i audio.mp3 -acodec libvorbis audio.ogg